If you look at the way we define the routes in MaterialApp, the home route is required. You can achieve this with the "/" symbol. Then, you can set up the other routes for your app:
routes: {
'/': (context) => LoginScreen(),
LoginScreen.route: (context) => LoginScreen(),
StopWatch.route: (context) => StopWatch(),
},
We have a bit of redundancy here because there are only two screens in this app. Once the routes have been declared, MaterialApp needs to know which route to start with. This is just inputted as a string:
initialRoute: '/',
It is recommended that you define constants for your routes and use those instead of string literals. In this recipe, we put the constants as static elements for each screen. There is no real requirement to organize your code like that; you could also keep your constants in a single file if you prefer.