无效的浮力扑来导致迟到初始错误
我正在构建一个通过蓝牙进行通信的颤音应用程序。当应用程序连接到另一端时,我会在屏幕上几秒钟收到此错误,直到建立连接,然后它消失了,如下所示:
在红色屏幕上:lateinitializationerror:field'连接'初始化。
我认为导致此错误的原因是:
late BluetoothConnection connection ;
但是,如果我删除了迟到,则由于无效安全性,我会遇到错误。我试图禁用整个项目的无效安全性,但错误没有停止。
我还试图使其无效:
BluetoothConnection? connection ;
但是随后我在其他属性中遇到了其他错误:属性“与“连接”无法无条件访问,因为接收器可以是'null'。。
bool get isConnected => connection.isConnected;
I am building a flutter app to communicate via bluetooth. When the app is connecting to the other end I get this error for few seconds on the screen until the connection is established then it goes away whish is like this:
On a red screen: LateInitializationError: Field 'connection' has not been initialized.
I think what is causing this error is this line:
late BluetoothConnection connection ;
But if I remove the late then I get an error because of the null safety. I tried to disable the null safety on the whole project but the error didnt stopp.
I also tried to make it nullable :
BluetoothConnection? connection ;
but then i get other errors in other properties depending on it : The property 'isConnected' can't be unconditionally accessed because the receiver can be 'null'.
bool get isConnected => connection.isConnected;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于那些遇到类似问题的人,这就是我解决的方式:
首先,我将声明表格更改为:
使BluetoothConnection Nullable Nullable,然后在代码的其余部分添加了一些更改以求解我遇到的错误。
上一个代码:
新代码:
感谢@jameslin
For those who had similar issue, here is how I solved it:
First I changed the declaration form to:
To make BluetoothConnection nullable and then I added some changes to the rest of the code to solve the errors I got.
Previous code:
New code:
Thanks to @jameslin