Open the existing stopwatch project to get started:
- Named routes are referenced as strings. To reduce the potential for error, add some constants to the top of both stopwatch.dart and login_screen.dart:
class LoginScreen extends StatefulWidget {
static const route = '/login';
class StopWatch extends StatefulWidget {
static const route = '/stopwatch';
- These routes need to be wired up in MaterialApp so that they can be fed to the app's Navigator.
- Open main.dart and update the MaterialApp's constructor so that it includes these pages:
return MaterialApp(
routes: {
'/': (context) => LoginScreen(),
LoginScreen.route: (context) => LoginScreen(),
StopWatch.route: (context) => StopWatch(),
},
initialRoute: '/',
);
- Now, we can invoke this route. Open login_screen.dart and scroll to the _validate method. Replace the existing navigator code...