Navigation Step 18

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.

Example Code

file_type_dartlang main.dart
class MyApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   return MaterialApp(

    
     routes: {
       '/home': (context) => HomeScreen(),
       '/slideshow': (context) => SlideshowScreen()
     },

     home: HomeScreen(),
   );
 }
}

class HomeScreen extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   return Scaffold(
     appBar: AppBar(title: Text('Home'), backgroundColor: Colors.red,),
     body: Center(
       child: Row(
         mainAxisAlignment: MainAxisAlignment.center,
         children: <Widget>[
           FlatButton(child: Text('push'), color: Colors.green, onPressed: () {

             // Navigator.push(
             //   context,
             //   MaterialPageRoute(builder: (context) => SlideshowScreen(name: 'Jeff'))
             // );


           //  Navigator.pushNamed(
           //     context,
           //     '/slideshow'
           //   );

             Navigator.pushNamed(
               context,
               '/slideshow'
             );

           },),

         ],
       ),
     ),
   );
 }
}

Q&A Chat