💻
Flutter documentation
  • Flutter documentation
    • Starting an App
    • Import
  • Visual Studio Code
  • Widgets
    • Stateless Widget
    • Stateful Widget
    • Scaffold
    • Text
      • OverFlow
      • Rounded background text
    • Padding
    • Align
    • DraggableScrollableSheet
    • Container
    • Decorated box
    • Expanded
    • IntrinsicHeight
    • IntrinsicWidth
    • ListView.builder(...)
    • Buttons
    • Gauge
    • Navigator
      • WillPopScope
    • Web View
    • Divider
    • Future builder
    • Image
      • Cached_network_image
      • Fade In Image
    • ClipOval
    • InkWell
    • Wrap
    • SingleChildScrollView
    • Stack
    • FittedBox
    • DropdownButton
    • ValueListenableBuilder
    • Maps
    • fl_chart
    • Set SystemNavigation Bar Color
    • Onesignal
    • Builder
    • Set orientation
    • SSE
    • Chat
    • Flutter_animate
    • Supabase
      • Android
    • Changing name and package name
    • Sign apk/abb
  • Dart
    • If / Else in one line
    • Functions
  • Others
  • Airtable
Powered by GitBook
On this page
  1. Widgets

Navigator

You can use the navigator to change between pages

First you will need to create a new page like stateless or statefull widget

To navigate to a new page:

Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => const SecondRoute()),
  );

To navigate to the previous page:

  Navigator.pop(context);
  
  //if you get a black screen use this
Navigator.of(context,rootNavigator:true).pop(context)

//going to the first page
Navigator.of(context).popUntil((route) => route.isFirst);

If you get the "Navigator operation requested with a context that does not include a Navigator" error you can solve it by adding a ´builder´


Builder(
  // The `builder` property allows the `RaisedButton` widget to be
  // built with a `context` that has access to a `Navigator`, which is
  // necessary to push a new route (page) onto the app's navigation stack.
  builder: (context) => RaisedButton( 
        onPressed: () {
          // Pushes a new route (page) onto the app's navigation stack,
          // and navigates to the new route.
          Navigator.push(context,
              MaterialPageRoute(
                  builder: (context) => YourNextPage()));
        },
        child: Text('YourButton'),
      ),
)

This code is used in Flutter mobile app development to navigate to a new screen (MainActivity) while removing all previous screens from the navigation stack.

Used for navigating between pages, preventing problems.

Navigator.of(context).pushAndRemoveUntil(
  MaterialPageRoute(
    builder: (context) {
      return MainActivity();
    },
  ),
  (Route<dynamic> route) => false,
);

To pass data from one screen to another, you have to make a constructor and pass the data with it.

Errors:

read this: https://medium.com/@kenzync/flutter-tip-navigator-operation-requested-with-a-context-that-does-not-include-a-navigator-d26f7b8c7b33

PreviousGaugeNextWillPopScope

Last updated 2 years ago