Using Named route:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
title: 'Navigation and routes', | |
home: MyApp(), | |
routes: <String, WidgetBuilder>{ | |
'/SecondPage': (BuildContext context) => new SecondPage(), | |
}, | |
), | |
); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[ | |
RaisedButton( | |
onPressed: () => Navigator.pushNamed(context, '/SecondPage'), | |
child: Text('Second Page'), | |
), | |
], | |
), | |
); | |
} | |
} | |
class SecondPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text('Second Page'),), | |
body: Center( | |
child: RaisedButton( | |
onPressed: () => Navigator.pop(context), | |
child: Text('Go Back'), | |
), | |
), | |
); | |
} | |
} |
No comments:
Post a Comment