我有一个显示相机的颤动应用程序,然后使用git://github.com/arashbi/flutter_qrcode_reader扫描qr代码,在回调中,我想导航到另一个屏幕以显示我得到的信息从一些查询。问题是,似乎Navigator得到了错误的上下文,因此我没有看到整页导航,而是将第二页作为小部件推送到我的第一页内。
第一页的构建如下:
@override
Widget build(BuildContext context) {
Widget main =
new Scaffold(
appBar: _buildAppBar(),
body: Column(
children: <Widget>[
_eventButton ?? new Text(""),
new Center(
child: new Text("Hi"))
],
),
floatingActionButton: new FloatingActionButton(
onPressed:
() {
new QRCodeReader()
.setAutoFocusIntervalInMs(200)
.setForceAutoFocus(true)
.setTorchEnabled(true)
.setHandlePermissions(true)
.setExecuteAfterPermissionGranted(true)
.scan().then((barcode) => _showTicketPage(barcode));
}
,
child: new Icon(Icons.check),
),
);
if (!_loading) {
return main;
} else {
return new Stack(
children: [main,
new Container(
decoration: new BoxDecoration(
color: Color.fromRGBO(220, 220, 220,
0.3) // Specifies the background color and the opacity
),
child: new Center(child: new CircularProgressIndicator(),))
]
);
}
}
&#39;嗨&#39; Widget用于调试,导航方法是
void _showTicketPage(var barcode) {
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) => TicketScreen(barcode)));
}
获取条形码后,第二个屏幕 - TicketScreen - 被推到&#39;嗨&#39;窗口小部件。我甚至不知道这是可能的。
我试图获取屏幕的上下文,将其保存到字段var中,但这也没有帮助。
我该如何解决?我没有想法了。