【问题标题】:Flutter: How do I change main.dart(entry point) to some other page in Flutter?Flutter:如何将 main.dart(entry point) 更改为 Flutter 中的其他页面?
【发布时间】:2019-08-25 20:57:32
【问题描述】:
  • 我开始在 main.dart 中处理应用程序的“主页”。
  • 然后我创建了“Login.dart”页面,现在我希望我的应用程序从“Login.dart”页面开始。

我是 Flutter 的新手。

【问题讨论】:

    标签: flutter


    【解决方案1】:

    flutter run -t lib/main_admin.dartt代表target,默认是lib/main.dart。如果你不指定 -t 你会去 lib/main.dart

    如果您想为同一个入口点加载不同的风格 - 即生产、开发和测试,也可以将 --flavor 传递给颤振运行命令

    【讨论】:

      【解决方案2】:

      按照这些图片:

      确保你写的是正确的路径:

      提示:("lib/start.dart") 只是示例。

      image(5) 来测试你的新入口点:

      【讨论】:

        【解决方案3】:

        为此我们有一个单独的文件。请按照以下步骤操作:

        1.去测试> widget.test.dart
        2.更改导入package:flutter_async/main.dartpackage:flutter_async/your_file_name.dart

        在您定义的类中,您可以使用您的 MyApp哪个 runapp 函数将作为输入)类,或者您也可以将 Myapp 类重命名为 some widget.testfile 中的其他类作为您应用的第一个屏幕。

        【讨论】:

          【解决方案4】:

          如果您想使用 lib/config/main_production.dart 以外的文件中的主入口点构建发布应用程序,则必须这样做:

          flutter build apk -t lib/config/main_production.dart
          

          【讨论】:

          • 正是我想要的——如何为在设备上运行的构建应用程序更改它。
          【解决方案5】:

          您可以从编辑配置中更改您的 Dart 入口点。

          将您的 main.dart 文件更改为其他文件。

          【讨论】:

          • 我可以进入“编辑配置...”的唯一方法是先单击“运行”。
          • 你必须添加 void main() => runApp(MyApp());修改配置后在类名的顶部
          【解决方案6】:

          在您的main.dart 中,您可以指定您的应用打开的第一个屏幕:

          runApp(new MaterialApp(
            debugShowCheckedModeBanner: false,
            theme: //theme
            title: "Title",
            home: new Login(), //Here you can specify the screen the app starts on.
            routes: <String, WidgetBuilder>{
              //routes
            },
          ));
          

          我不确定这是否比 Günter 的答案更好,但我的意思是您在构建或运行时不必总是指定文件名。

          【讨论】:

            【解决方案7】:

            -t 参数执行各种命令(运行、构建等)支持的操作

            flutter run -t lib/my_other_main.dart
            

            【讨论】:

            • 感谢您的回复,这很有帮助。但它只在我再次调试我的应用程序之前工作。在我调试时,它以“main.dart”而不是“Login.dart”开头。
            • 如果您使用Android Studio/IntellyJ,则需要将参数添加到运行配置中。我不知道VSCode。
            • @GünterZöchbauer,我发现这篇很棒的文章帮助了我使用 VSCode -> medium.com/flutter-community/…
            猜你喜欢
            • 1970-01-01
            • 2021-09-30
            • 2018-08-09
            • 1970-01-01
            • 2021-09-13
            • 2022-01-06
            • 2020-07-29
            • 2021-08-29
            • 2019-07-02
            相关资源
            最近更新 更多