Mobile 我可以用MyApp类以外的类启动我的应用程序吗?

Mobile 我可以用MyApp类以外的类启动我的应用程序吗?,mobile,flutter,dart,Mobile,Flutter,Dart,我正在开发一个需要登录页面的移动应用程序。我已经把主页编好了。我希望应用程序以登录页面开始,而不是我编码的页面。有没有办法用myapp类以外的其他类启动应用程序 我试图启动runApp(ClassThatIWant())但这似乎不起作用 void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { re

我正在开发一个需要登录页面的移动应用程序。我已经把主页编好了。我希望应用程序以登录页面开始,而不是我编码的页面。有没有办法用myapp类以外的其他类启动应用程序

我试图启动
runApp(ClassThatIWant())但这似乎不起作用

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: VoiceHome(),
    );
  }
}
您始终运行MyApp()。您可以通过以下操作访问您的登录:

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: YourLoginPage(),
    );
  }
}

使用路由也是很常见的,例如:


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
       title: "My app name",
       routes: {
        '/': (BuildContext context) => YourLoginPage(),
        '/home': (BuildContext context) => VoiceHome(),
        '/otherscreen': (BuildContext context) => OtherScreen(),
        '/etc': (BuildContext context) => EtcScreen(),

      },
    );
  }
}

并通过执行以下操作来引用它:

Navigator.pushNamed(context, '/home');
您始终运行MyApp()。您可以通过以下操作访问您的登录:

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: YourLoginPage(),
    );
  }
}

使用路由也是很常见的,例如:


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
       title: "My app name",
       routes: {
        '/': (BuildContext context) => YourLoginPage(),
        '/home': (BuildContext context) => VoiceHome(),
        '/otherscreen': (BuildContext context) => OtherScreen(),
        '/etc': (BuildContext context) => EtcScreen(),

      },
    );
  }
}

并通过执行以下操作来引用它:

Navigator.pushNamed(context, '/home');

你能分享你得到的例外情况吗?只要它是一个小部件,你就可以在runApp方法中传递它。你能分享你得到的异常吗?只要它是一个小部件,你就可以在runApp方法中传递它。只要它是一个小部件,你就可以在runApp方法中传递它。它不一定是MyApp。只要它是一个小部件,你就可以在runApp方法中传递它。它不一定是MyApp。