Mariam Albarghouti
Mariam Albarghouti

Reputation: 487

home of materialApp in dart language

my question is about the structure of the widgets.

this line of code:

return new MaterialApp(
      title: "question",
      home: MyApp(),
);

if there is a navigator on MyApp() class to navigat to another Screen (LoginScreen()), the MyApp() class will be as its parent or will be destried and the other Screen (LoginScreen()) will be as

this line of code:

return new MaterialApp(
          title: "question",
          home: LoginScreen(),
    );

Upvotes: 1

Views: 194

Answers (1)

kuhnroyal
kuhnroyal

Reputation: 7553

The MaterialApp already provides a Navigator. You should only have one MaterialApp in your app and all your screens should be children of the one app.

MyApp -> MaterialApp
                    -> HomeScreen
                    -> LoginScreen

You can follow this basic example on flutter.io: https://flutter.dev/docs/cookbook/navigation/navigation-basics

Also you don't need the new keyword anymore. Any IDE (VSCode/IntelliJ) should give you a hint there if it is correctly configured.

Upvotes: 1

Related Questions