【发布时间】:2022-11-16 21:34:04
【问题描述】:
我正在用 flutter 创建一个移动应用程序。首先,我必须连接到蓝牙。连接到特定设备后,我必须重定向到下一页,即主页。此屏幕不显示设备的任何信息,但我必须在此屏幕中通过蓝牙接收数据。 我做这样的事情:
if (snapshot.data == BluetoothDeviceState.connected) {
WidgetsBinding.instance.addPostFrameCallback(
(_) {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => MainScreen()));
BluetoothServiceList(device: d);
BluetoothDeviceStateHandler(
device: d,
);
},
);
return ElevatedButton(
child: const Text('CONNECTED'),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => MainScreen()));
BluetoothServiceList(device: d);
BluetoothDeviceStateHandler(
device: d,
);
});
}
BluetoothServiceList 和BluetoothDeviceStateHandler 这两个函数存在于另一个屏幕中,但我不应该再显示这个屏幕了。
所有的功能都应该在这个类中执行而不显示任何东西。我只想在从其他设备接收数据时显示警报。
class MainScreen extends StatelessWidget {
const MainScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: new Stack(
children: <Widget>[
new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/Fond.png"),
fit: BoxFit.cover,
),
),
),
Align(
alignment: Alignment.bottomLeft,
child: FloatingActionButton(
onPressed: () {},
child: Image.asset('assets/Alerte notif.png'),
elevation: 30,
),
),
Align(
alignment: Alignment.bottomRight,
child: FloatingActionButton(
onPressed: () {},
child: Image.asset('assets/Panneau distance rouge.png'),
elevation: 15,
),
),
Align(
alignment: Alignment.bottomCenter,
child: TextButton(
onPressed: () {},
child: (Image.asset(
'assets/camion2.png',
height: 200,
width: 500,
)),
),
),
],
)),
);
}
}
这里有人可以帮助我吗?我想知道我的逻辑是否正确,是否有针对我所想的解决方案。
【问题讨论】:
标签: flutter function dart triggers execute