Answers for "flutter navigation"

13

flutter navigate to new screen

// Within the `FirstRoute` widget
onPressed: () {
  Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => SecondRoute()),
  );
}
Posted by: Guest on March-25-2020
3

flutter navigation

// inside MaterialApp in main.dart
routes: {
        '<route_name>': (context) => MySecondscreen(),
      },
      
// where you want to execute the code
Navigator.pushNamed(context, '<route_name>');
Posted by: Guest on June-02-2021
0

flutter unload screen from stack

Navigator.pushAndRemoveUntil(
  context,
  MaterialPageRoute(builder: (context) => MainPage()),
  (Route<dynamic> route) => false,
);
Posted by: Guest on July-10-2020
0

navigation route flutter

<!-------- Intialize the route ---------->
class secondroute extends StatelessWidget {
  const secondroute({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    //PreferencesService preferencesService = locator<PreferencesService>();
    //NavigationService navigationService = locator<NavigationService>();
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      initialRoute: '/second',
      key: Key('second_key'),
      routes: {
        '/second': (context) => DestinationRoute(),
      },
    );
  }
}
///// Set in Desired page //////
ElevatedButton(
   onPressed: () {
       //locator<NavigationService>().navigateTo(RoutePaths.firstroute);
       //Get.to(() => DestinationRoute());
            Navigator.pushNamed(context, '/second');
              },
Posted by: Guest on July-04-2021

Browse Popular Code Answers by Language