「Flutter/画面遷移」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→その2) |
(→元の画面に戻る) |
||
| 行36: | 行36: | ||
==元の画面に戻る== | ==元の画面に戻る== | ||
Navigator.pop(context); | Navigator.pop(context); | ||
| + | |||
| + | ==遷移先から遷移元に戻った時の処理== | ||
| + | Navigator.push(context, new MaterialPageRoute<Null>( | ||
| + | settings: const RouteSettings(name: "/text"), | ||
| + | builder: (BuildContext context) => TextPage(title: 'page use') | ||
| + | )).then((result) { | ||
| + | setState(() { | ||
| + | print ("ここで戻ってきた時の処理"); | ||
| + | }); | ||
| + | }); | ||
==参考== | ==参考== | ||
https://qiita.com/tatsu/items/38cd85efd93005b95af9 | https://qiita.com/tatsu/items/38cd85efd93005b95af9 | ||
2019年5月6日 (月) 01:40時点における版
画面遷移サンプル
その1
routerをMyAppの中に追加
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
routes: <String, WidgetBuilder> {
'/help': (BuildContext context) => new MyHomePage(title: 'page help'),
'/privacy': (BuildContext context) => new MyHomePage(title: 'page privacy'),
'/use': (BuildContext context) => new MyHomePage(title: 'page use'),
},
);
}
}
画面遷移
Navigator.of(context).pushNamed('/use');
その2
router&画面遷移
Navigator.push(context, new MaterialPageRoute<Null>(
settings: const RouteSettings(name: "/use"),
builder: (BuildContext context) => MyHomePage(title: 'page use')
));
元の画面に戻る
Navigator.pop(context);
遷移先から遷移元に戻った時の処理
Navigator.push(context, new MaterialPageRoute<Null>(
settings: const RouteSettings(name: "/text"),
builder: (BuildContext context) => TextPage(title: 'page use')
)).then((result) {
setState(() {
print ("ここで戻ってきた時の処理");
});
});
