How To Navigate To Other Screens in Flutter

In this article, you will learn How To Navigate To Other Screens in Flutter. In Flutter you don’t need to install any third-party packages or…

The post How To Navigate To Other Screens in Flutter appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Jatin Hemnani

In this article, you will learn How To Navigate To Other Screens in Flutter.

In Flutter you don’t need to install any third-party packages or dependencies. Navigation comes out of the box in Flutter which great compared to React Native.

Creating Screens

main.dart

class Screen1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home'),
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              'Screen 1',
              style: TextStyle(fontSize: 40),
            ),
            OutlineButton(
              child: Text('Go To Screen 2'),
              onPressed: () {
                Navigator.push(context,
                    MaterialPageRoute(builder: (context) => Screen2()));
              },
            ),
          ],
        ),
      ),
    );
  }
}

class Screen2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Screen 2'),
        centerTitle: true,
      ),
      body: Center(
        child: Text(
          'Screen 2',
          style: TextStyle(fontSize: 40),
        ),
      ),
    );
  }
}

Here, you have the Screen1 Widget with Center & Column widget. After the Text() widget you have an OutlineButton() with onPressed. The function inside onPressed is used for navigating to different screens. To navigate to another screen you use

Navigator.push method with respective parameters, first param is the context and the second param is the MaterialPageRoute() with the Screen name.

Result

The post How To Navigate To Other Screens in Flutter appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Jatin Hemnani


Print Share Comment Cite Upload Translate Updates
APA

Jatin Hemnani | Sciencx (2021-03-01T14:18:23+00:00) How To Navigate To Other Screens in Flutter. Retrieved from https://www.scien.cx/2021/03/01/how-to-navigate-to-other-screens-in-flutter/

MLA
" » How To Navigate To Other Screens in Flutter." Jatin Hemnani | Sciencx - Monday March 1, 2021, https://www.scien.cx/2021/03/01/how-to-navigate-to-other-screens-in-flutter/
HARVARD
Jatin Hemnani | Sciencx Monday March 1, 2021 » How To Navigate To Other Screens in Flutter., viewed ,<https://www.scien.cx/2021/03/01/how-to-navigate-to-other-screens-in-flutter/>
VANCOUVER
Jatin Hemnani | Sciencx - » How To Navigate To Other Screens in Flutter. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/01/how-to-navigate-to-other-screens-in-flutter/
CHICAGO
" » How To Navigate To Other Screens in Flutter." Jatin Hemnani | Sciencx - Accessed . https://www.scien.cx/2021/03/01/how-to-navigate-to-other-screens-in-flutter/
IEEE
" » How To Navigate To Other Screens in Flutter." Jatin Hemnani | Sciencx [Online]. Available: https://www.scien.cx/2021/03/01/how-to-navigate-to-other-screens-in-flutter/. [Accessed: ]
rf:citation
» How To Navigate To Other Screens in Flutter | Jatin Hemnani | Sciencx | https://www.scien.cx/2021/03/01/how-to-navigate-to-other-screens-in-flutter/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.