[flutter] Navigator 테스트

from flutter 2018. 4. 30. 02:22
void main() {
runApp(new MaterialApp(
home: new MyAppHome(), // becomes the route named '/'
routes: <String, WidgetBuilder> {
'/a': (BuildContext context) => new MyPage(title: 'page A'),
'/b': (BuildContext context) => new MyPage(title: 'page B'),
'/c': (BuildContext context) => new MyPage(title: 'page C'),
},
));
}

class MyAppHome extends StatefulWidget {
@override
_MyAppHomeState createState() => new _MyAppHomeState();
}

class _MyAppHomeState extends State<MyAppHome> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text("data"),),
body: Center(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new RaisedButton(
child: new Text("A"),
onPressed: ()=>Navigator.pushNamed(context, '/a'),
),
new Padding(padding: const EdgeInsets.all(20.0),),
new RaisedButton(
child: new Text("B"),
onPressed: ()=>Navigator.pushNamed(context, '/b'),
),
new Padding(padding: const EdgeInsets.all(20.0),),
new RaisedButton(
child: new Text("C"),
onPressed: ()=>Navigator.pushNamed(context, '/c'),
)
],
),
),
);
}
}


class MyPage extends StatefulWidget {
final String title;
MyPage({this.title});



@override
_MyPageState createState() => new _MyPageState();
}

class _MyPageState extends State<MyPage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text(widget.title),),
body: new Center(
child: new RaisedButton(
child: new Text("back"),
onPressed: ()=>Navigator.pop(context),
),
),
);
}
}


참고  : https://docs.flutter.io/flutter/widgets/Navigator-class.html



stack 의 형식으로 navigator가 동작


,