Add New Activity Route Screen in Flutter Android iOS Example Tutorial

Every application has contain more than one screen now days. Screens are also known as Activity or Routes in mobile application world. In flutter world we mostly say new screens as Routes. Every new screen can be created using individual classes in flutter app. Each class which has used to make View has Widget build area. So in this tutorial we would Add New Activity Route Screen in Flutter Android iOS App Example Tutorial.

Contents in this project Add New Activity Route Screen in Flutter Android iOS Example Tutorial:

1. Import material.dart package in your app’s main.dart file.

2. Create our void main() method. Inside the main() method we would pass our first home screen using home property. main() method calls every time when your app runs.

  • home : Pass here class route name which you want to became your Home screen.

3. Create our First screen class named as HomeActivity extends StatelessWidget.

4. Create a function named as gotoSecondActivity() with BuildContext argument in Home Activity class. In this function we would use Navigator.push() method with Context and MaterialPageRoute() method and pass here our next activity name on which we want to go on when this function called.

5. Create Widget build area in HomeActivity class and make a Raised button Widget in Center widget. We would call the gotoSecondActivity() function on Raised button onPress event.

6. Create our Second screen class named as SecondActivity extends StatelessWidget.

  • goBack() : In this method we would call Navigator.pop() method with context argument. We would call this function on Raised button on Press event to go back to previous screen by closing this current screen route.

7. Complete source code for main.dart file:

Screenshots:

Add New Activity Route Screen in Flutter Android iOS Example Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *