【发布时间】:2021-01-26 09:38:22
【问题描述】:
我正在使用flutter_bluetooth_serial 库,并且在initState() 函数中我正在使用listen 来调用一个函数。当应用程序最初启动时它工作正常,但是当我在应用程序上第二次访问此屏幕时,我得到一个红色屏幕,上面写着“状态不佳:流已被收听”。
我是 Flutter 新手,所以请提供可以帮助我解决此问题的确切代码。
@override
void initState() {
super.initState();
widget.connection.input.listen(_onDataReceived).onDone(() {
// Example: Detect which side closed the connection
// There should be `isDisconnecting` flag to show are we are (locally)
// in middle of disconnecting process, should be set before calling
// `dispose`, `finish` or `close`, which all causes to disconnect.
// If we except the disconnection, `onDone` should be fired as result.
// If we didn't except this (no flag set), it means closing by remote.
if (isDisconnecting) {
print('Disconnecting locally!');
} else {
print('Disconnected remotely!');
}
if (this.mounted) {
setState(() {});
}
});
}
【问题讨论】:
标签: flutter dart bluetooth flutter-dependencies android-bluetooth