Navigate to a new screen in Flutter

后端 未结 7 1422
日久生厌
日久生厌 2020-12-11 18:34

How do you navigate to a new screen in Flutter?

These questions are similar, but are asking more than I am.

  • Flutter - Navigate to a new screen, and cle
7条回答
  •  爱一瞬间的悲伤
    2020-12-11 19:02

    If you are familiar with web development this approach is similar to routing.

    main.dart

    void main() {
      setupLocator();
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          routes: {
            '/' : (BuildContext context)=>HomePage(),
            '/register' : (BuildContext context)=>RegisterPage(),
          },
        );
      }
    }
    

    You can add button onPressed event from the homepage.dart to navigate register.dart as follows.

    onPressed: (){
        Navigator.pushReplacementNamed(context, '/register');
     },
    

提交回复
热议问题