TextField
FocusNode
を入力してから、await
に戻って戻ると、ナビゲーションが行われるときにFocusScope.of(context).requestFocus(myNode)
に設定する必要があります。
簡単なデモ:
class FirstPage extends StatefulWidget {
@override
_FirstPageState createState() => new _FirstPageState();
}
class _FirstPageState extends State<FirstPage> {
FocusNode n = new FocusNode();
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title:new Text("First Page")),
body: new Center(
child: new Column(
children: <Widget>[
new TextField(
focusNode: n,
),
new RaisedButton(onPressed:()async{
bool focus = await Navigator.of(context).push(new MaterialPageRoute(builder: (_)=>new SecondPage()));
if (focus == true|| focus==null){
FocusScope.of(context).requestFocus(n);
}
},
child: new Text("NAVIGATE"),),
],
),
),
);
}
}
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title:new Text("Second Page")),
body: new Center(
child: new RaisedButton(onPressed:(){Navigator.pop(context,true);},child: new Text("BACK"),),
),
);
}
}