Step By Step Tutorial In Learning Flutter: Lesson 6— Creating New Screens Part 2
In this lesson we will continue where we left off from Lesson 5— Creating New Screens Let us now finish the screens for the remaining menus on our Pokedex.
Let us create the screen for Grass Pokedex
Open the main.dart if not yet opened
Scroll down to line 138, where our FireScreen code block is, highlight the entire code block as shown below
Then, create a new line, after that, paste the code block
Revise the following as illustrated below
The code will be as follows
//This is our Grass Pokemon Screen
class GrassScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Grass Pokemon"),
),
body: Center(
child: RaisedButton(
child: Text('Go back!'),
onPressed: () {
// Navigate back to the first screen by popping the current route
// off the stack.
Navigator.pop(context);
},
),
),
);
}
}
Next, go to line 81 where it says Text(‘Grass’)
We will add the Navigator.pop and Navigator.push
Revise the code to look like below
The code will be
ListTile(
title: Text('Grass'),
onTap: () {
// Close the drawer
Navigator.pop(context);
Navigator.pushNamed(context, '/grass');
},
),
Lastly, go to line 19, add a new line
Then, add the code as shown below
The added line will be
'/grass': (context) => GrassScreen(),
Save and Run
Tap the Grass Pokedex
Now as part of learning by doing, continue the remaining Ice and Water Pokedex
The finale will have these added new screens
Hope you enjoy and completely done this lesson, till next time :)
To download the files for the tutorials see the article Downloading the Files