我使用此代码加载了新页面,但无济于事! 它与StatefulWidget有关吗? (MaterialButton在一个稳定的小部件下)
MaterialButton(
onPressed: () {
titlenote = titleinput.text;
subtitlenote = subtitleinput.text;
Navigator.of(context).pop();
new MaterialPageRoute(builder: (context) {
return notes();
});
},
这是新页面的无固定小部件:
class notes extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: new Column(children: <Widget>[
new Container(
padding: EdgeInsets.fromLTRB(8, 20, 8, 20),
color: Colors.transparent,
child: new CheckboxListTile(
value: true,
onChanged: (bool a) {},
title: Text("$titlenote"),
selected: true,
checkColor: Colors.green,
activeColor: Colors.black,
tristate: true,
subtitle: Text("$subtitlenote"),
),
alignment: Alignment.center,
)
]),
);
}
}
答案 0 :(得分:0)
您创建了MaterialPageRoute
,但从未使用导航器来推送它。顺便说一句,您可以使用pushReplacement
一次弹出和推送:
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) {
return notes();
}));
N.B:关键字new
自Dart 2起就没有用了,您可以在每次看到它时将其删除。