gpt4 book ai didi

flutter - Flutter:[错误:flutter/lib/ui/ui_dart_state.cc(166)]未处理的异常

转载 作者:行者123 更新时间:2023-12-03 04:39:56 25 4
gpt4 key购买 nike

我有这个错误,我不明白我的错误在哪里

[ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception:NoSuchMethodError: The getter 'output' was called on null. E/flutter(16491): Receiver: null E/flutter (16491): Tried calling: output


错误是指该功能,但我没有错误语法
import 'dart:convert';
BluetoothConnection connection;

void _sendOnMessageToBluetooth() async {
connection.output.add(utf8.encode("1" + "\r\n"));
await connection.output.allSent;
setState(() {
deviceState = 1;
});
}
这就是我在叫它的地方
FlatButton(
onPressed: _sendOnMessageToBluetooth ==null? "": _sendOnMessageToBluetooth,
child:Text("ON",
style:TextStyle(color:Colors.red[400]),,),
谁能帮忙!

最佳答案

您正在使用“连接”变量,而没有先对其进行初始化或将其分配给某些对象。因此,当称为“connection.output”时,它将导致错误。尝试查找“连接”变量的初始化位置,然后从那里使用它,或者将其用作函数的参数。
这可能起作用:

void _sendOnMessageToBluetooth() async {
BluetoothConnection connection = new BluetoothConnection();
connection.output.add(utf8.encode("1" + "\r\n"));
await connection.output.allSent;
setState(() {
deviceState = 1;
});
}

关于flutter - Flutter:[错误:flutter/lib/ui/ui_dart_state.cc(166)]未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63425077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com