简体   繁体   English

Go 返回上一页 flutter

[英]Go back to previous page in flutter

I have a flutter app that connects via bluetooth with a device by pressing on the device name from the list of paired devices.我有一个 flutter 应用程序,它通过按配对设备列表中的设备名称通过蓝牙连接设备。 This is the coding:这是编码:

final BluetoothDevice server;


 DataCollectionPage({required this.server});
...............................................................................

               child: ListView(
                 children: devices
                     .map((_device)=> BluetoothDeviceListEntry(
                   device: _device,
                   enabled: true,
                   onTap: (){
                     if (kDebugMode) {
                       print("item");
                     }
                     _startDataCollection(context, _device);
                   },
................................................................................
void _startDataCollection(BuildContext context, BluetoothDevice server){
 Navigator.of(context).push(MaterialPageRoute(builder: (context){
   return DataCollectionPage(server: server);
 }));
}

Then once I navigate to the " DataCollectionPage " page, I perform some actions and data collection methods and at the end I will be in other page named "DataCollectionTimer" .然后,一旦我导航到“ DataCollectionPage ”页面,我将执行一些操作和数据收集方法,最后我将在另一个名为“DataCollectionTimer”的页面中。 In this page a timer will be displayed on the screen for few seconds then at the end of this timer a Dialog will show to give some message and then finally Once I press the button close on this dialog, I want to go back to DataCollectionPage.在此页面中,一个计时器将在屏幕上显示几秒钟,然后在该计时器结束时将显示一个对话框以提供一些消息,最后一旦我按下此对话框上的按钮关闭,我想 go 返回 DataCollectionPage。 So If I try to use所以如果我尝试使用

MaterialPageRoute( builder: (context) => DataCollectionPage(),   ),

It will give an error because parameter 'server' is required which I obtained from the list of paired devices that was in a different class. Is there a way to go back to DataCollectionPage from the current one without going all the way back to the page where the list of paired devices is there.它会出错,因为需要参数“服务器”,这是我从另一个 class 中的配对设备列表中获得的。有没有办法从当前的 go 返回到 DataCollectionPage 而无需一直返回页面配对设备列表在哪里。

Thank you in advance先感谢您

You need to make the server field optional and then use popUntil您需要将服务器字段设为可选,然后使用 popUntil

final BluetoothDevice? server;

DataCollectionPage({this.server});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM