我正在从蓝牙设备接收此文本数据包“ start12345678910”。相同的包裹会连续发送,但是在我打印时它会损坏,有时会丢失。我试图增加/减少蓝牙设备的延迟。打印文本流()时,缺少一些文本,如下所述 8,9,10,star
I/flutter (14766): ENTERING PRINTING MODE******************
I/flutter (14766): current value is: 45678910start1234567 and next value: t12345678910start123
I/flutter (14766): EXit printing mode****************
我认为是快照占用一部分数据,而不是一次获取每个包。
如何修改代码以不丢失数据,以便可以打印列表中的每个流? 谢谢
class MyPage extends StatefulWidget {
const SensorPage({Key key, this.device}) : super(key: key);
final BluetoothDevice device;
@override
_MyPageState createState() => _MyPageState();
}
class _MyPageState extends State<MyPage> {
final String serviceUUID = "49535343-fe7d-4ae5-8fa9-9fafd205e455";
final String characteristicUUID = "49535343-1e4d-4bd9-ba61-23c647249616";
//for storage
TextEditingController controller = TextEditingController();
String stateText;
Future<Directory> _appDocDir;
bool isReady;
Stream<List<int>> stream;
List<String> myInputList = List();
.
.
.
.
.
.
.
Container(
child: StreamBuilder<List<int>>(
stream: stream,
builder: (BuildContext context,
AsyncSnapshot<List<int>> snapshot) {
if (snapshot.hasError)
return Text('Error: ${snapshot.error}');
if (snapshot.connectionState == ConnectionState.active) {
print("ENTERING PRINTING MODE******************");
var currentValue = _dataParser(snapshot.data);
print("current value is: $currentValue");
print("EXit printing mode****************");
myInputList.add(currentValue);
print(myInputList);