简体   繁体   English

Flutter:如何将 main.dart(入口点)更改为 Flutter 中的其他页面?

[英]Flutter: How do I change main.dart(entry point) to some other page in Flutter?

  • I started working on the "home page" of the application in main.dart.我开始在 main.dart 中处理应用程序的“主页”。
  • Then I created "Login.dart" page, and now I want my application to start with "Login.dart" page.然后我创建了“Login.dart”页面,现在我希望我的应用程序以“Login.dart”页面开始。

I am newbie in Flutter.我是 Flutter 的新手。

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

flutter run -t lib/my_other_main.dart

You can change your Dart entry point from edit configurations.您可以通过编辑配置更改 Dart 入口点。 在此处输入图片说明

Change your main.dart file to some other file.将 main.dart 文件更改为其他文件。

在此处输入图片说明

Follow these pictures:按照这些图片:

点击运行按钮

创建一个lonch json文件

点击 Dart&Flutter

be sure you write the right path:确保你写的是正确的路径:

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

更改入口点

image(5) to test your new entrypoint: image(5) 来测试你的新入口点:

测试您的新入口点

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

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

In your main.dart you can specify the first screen that your app opens to: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
  },
));

I'm not sure if this is any better than Günter's answer, but mine will mean you don't have to always specify the file name when building or running.我不确定这是否比 Günter 的答案更好,但我的意思是您不必在构建或运行时始终指定文件名。

flutter run -t lib/main_admin.dart the t stands for target, the default of which is lib/main.dart. flutter run -t lib/main_admin.dart t代表target,默认为lib/main.dart。 If you don't specify the -t you will go to lib/main.dart如果你不指定 -t 你会去 lib/main.dart

you can also pass in --flavor to the flutter run command if you would like to load a different flavour for your same entry point - ie production, dev & test如果您想为相同的入口点加载不同的风格,您也可以将--flavor传递给 flutter run 命令 - 即生产、开发和测试

We have a separate file for this.我们有一个单独的文件。 Please follow below steps:请按照以下步骤操作:

1.Go to test> widget.test.dart 1.转到测试>小部件.test.dart
2.Change import package:flutter_async/main.dart to package:flutter_async/your_file_name.dart 2.将导入package:flutter_async/main.dart改为package:flutter_async/your_file_name.dart

and in the class which you have defined you can use your MyApp ( which runapp function will take as a input ) class or you can rename Myapp class also to some other class from widget.testfile as a first screen for your app.在您定义的类中,您可以使用MyApprunapp 函数将作为输入)类,或者您也可以将 Myapp 类重命名为 widget.testfile 中的其他类,作为您的应用程序的第一个屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM