We will begin by creating the first screen, which is a stateful widget containing a Scaffold with a centered ElevatedButton. Follow these steps:
- Create a new file, called navigation_first.dart.
- Add the following code to the navigation_first.dart file (note that in the onPressed of the button, we are calling a method that does not exist yet, called _navigateAndGetColor()):
import 'package:flutter/material.dart';
class NavigationFirst extends StatefulWidget {
@override
_NavigationFirstState createState() => _NavigationFirstState();
}
class _NavigationFirstState extends State<NavigationFirst> {
Color color = Colors.blue[700];
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: color,
appBar: AppBar(
title: Text('Navigation First Screen'),
),
body: Center(
child: ElevatedButton(
child: Text('Change Color'),
onPressed: () ...