Flutter 在布局过程中,RenderCustomMultiChildLayoutBox对象的大小为无限大
我使用BLE esp32从传感器获取数据,但当我想通过从BLE设备获取数据进行校准时,它会给我这个错误。 A我一按配置,它就会移动到设备设置页面 我想要的是,在我从BLE得到值1之前,它应该继续显示这个屏幕,一旦1出现,它应该转到另一个屏幕,显示消息和图片。相反,显示底部溢出错误消息“Bluetooth is not active”,我如何避免?然后跳到下一页?BLE也处于活动状态,因为我检查了其他屏幕上出现的值,但对于连接的设备,该屏幕上没有出现BLE 代码:Flutter 在布局过程中,RenderCustomMultiChildLayoutBox对象的大小为无限大,flutter,dart,error-handling,bluetooth-lowenergy,Flutter,Dart,Error Handling,Bluetooth Lowenergy,我使用BLE esp32从传感器获取数据,但当我想通过从BLE设备获取数据进行校准时,它会给我这个错误。 A我一按配置,它就会移动到设备设置页面 我想要的是,在我从BLE得到值1之前,它应该继续显示这个屏幕,一旦1出现,它应该转到另一个屏幕,显示消息和图片。相反,显示底部溢出错误消息“Bluetooth is not active”,我如何避免?然后跳到下一页?BLE也处于活动状态,因为我检查了其他屏幕上出现的值,但对于连接的设备,该屏幕上没有出现BLE 代码: 导入'dart:typed_da
导入'dart:typed_data';
导入“package:epicare/confDeviceOne.dart”;
导入“package:epicare/ConfigurationScreen.dart”;
进口“包装:颤振/材料.省道”;
进口“包装:飞舞蓝/飞舞蓝.飞镖”;
进口“包装:颤振旋转套件/颤振旋转套件.dart”;
进口“包装:fluttoast/fluttoast.dart”;
导入“Homepage.dart”;
类ConfDeviceSet扩展StatefulWidget{
const ConfDeviceSet({Key Key,this.device}):super(Key:Key);
最终蓝牙设备;
@凌驾
_ConfDeviceSetState createState()=>\u ConfDeviceSetState();
}
类_ConfDeviceSetState扩展了状态{
//BLE
最终管柱服务_UUID=“4fafc201-1fb5-459e-8fcc-c5c9c331914b”;
//最终管柱服务_UUID=“0365a300-8d69-4066-80c7-554298a6ec5e”;
//最终管柱特征_UUID=“cf01c075-cb75-4dea-819e-2a79dd466bcb”;
最终串特征_UUID=“beb5483e-36e1-4688-b7f5-ea07361b26a8”;
布尔已经准备好了;
溪流;
列出最后一个值;
List traceDust=List();
@凌驾
void initState(){
isReady=false;
discoverServices();
}
discoverServices()异步{
List services=wait widget.device.discoverServices();
services.forEach((服务){
if(service.uuid.toString()==service\u uuid){
服务.特征.forEach((特征){
if(characteristic.uuid.toString()==characteristic\u uuid){
characteristic.setNotifyValue(!characteristic.isNotifying);
流=特征值;
//打印(流);
lastValue=特征值。lastValue;
//打印(最后值);
设置状态(){
isReady=真;
});
}
});
}
});
}
_数据分析器(列表数据){
var值=Uint8List.fromList(数据);
打印(“stream.value:$value”);//stream.value:[33]
var hr=ByteData.sublistView(值0,1);
打印(“心率:${hr.getUint8(0)}”);
返回hr.getUint8(0);//心率:33
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
背景颜色:Colors.white,
appBar:appBar(
背景颜色:常量颜色(0xffE5E0A1),
海拔:0,
标题:对,
标题:正文(
“配置”,
样式:TextStyle(
字体大小:15.0,
颜色:颜色,黑色,
fontFamily:“蒙特塞拉特”,
fontWeight:fontWeight.normal,
),
),
领先:IconButton(
图标:图标(
Icons.arrow_back,
颜色:颜色,黑色,
),
已按下:(){
导航器。推(
上下文
材料路线(
生成器:(上下文){
返回ConfigurationScreen();
},
),
);
},
),
),
正文:专栏(
儿童:[
容器(
填充:仅限边缘设置(顶部:65),
对齐:对齐.center,
子:文本(
“设备设置…”,
样式:TextStyle(
fontFamily:“蒙特塞拉特”,
fontWeight:fontWeight.w600,
尺寸:17,
颜色:常量颜色(0xa8000000),
身高:1.3333,
),
文本高度行为:
TextHeightBehavior(ApplyHeightToFirstAscend:false),
textAlign:textAlign.center,
),
),
容器(
填充:边缘组。对称(垂直:120),
子对象:const SpinKitFadingCircle(
颜色:常量颜色(0xffF1C40E),
尺寸:200,
),
),
StreamBuilder(
小溪:小溪,
initialData:lastValue,
生成器:(BuildContext上下文,
异步快照(快照){
如果(snapshot.connectionState==
ConnectionState.active&&snapshot.hasData){
var currentValue=_数据解析器(snapshot.data);
如果(currentValue==1)
{
打印(“测试配置1”);
导航器。推(
上下文
材料路线(
生成器:(上下文){
返回confDeviceOne(设备:widget.device,);
},
),
);
}
else if(currentValue==0)
{
打印(“测试配置0”);
导航器。推(
上下文
材料路线(
生成器:(上下文){
返回confDeviceOne(设备:widget.device,);
},
),
);
}
}
否则{
flattertoast.showtoos(消息:“蓝牙未激活”);
返回主页(设备:widget.device,);
}
},
),
],
),
);
}
}
我的屏幕如下所示:
当我按波段配置时:
它去那里了
import 'dart:typed_data';
import 'package:epicare/ConfDeviceDone.dart';
import 'package:epicare/ConfigurationScreen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_blue/flutter_blue.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'Homepage.dart';
class ConfDeviceSet extends StatefulWidget {
const ConfDeviceSet({Key key, this.device}) : super(key: key);
final BluetoothDevice device;
@override
_ConfDeviceSetState createState() => _ConfDeviceSetState();
}
class _ConfDeviceSetState extends State<ConfDeviceSet> {
// BLE
final String SERVICE_UUID = "4fafc201-1fb5-459e-8fcc-c5c9c331914b";
//final String SERVICE_UUID = "0365a300-8d69-4066-80c7-554298a6ec5e";
//final String CHARACTERISTIC_UUID = "cf01c075-cb75-4dea-819e-2a79dd466bcb";
final String CHARACTERISTIC_UUID = "beb5483e-36e1-4688-b7f5-ea07361b26a8";
bool isReady;
Stream<List<int>> stream;
List<int> lastValue;
List<double> traceDust = List();
@override
void initState() {
isReady = false;
discoverServices();
}
discoverServices() async {
List<BluetoothService> services = await widget.device.discoverServices();
services.forEach((service) {
if (service.uuid.toString() == SERVICE_UUID) {
service.characteristics.forEach((characteristic) {
if (characteristic.uuid.toString() == CHARACTERISTIC_UUID) {
characteristic.setNotifyValue(!characteristic.isNotifying);
stream = characteristic.value;
//print(stream);
lastValue = characteristic.lastValue;
//print(lastValue);
setState(() {
isReady = true;
});
}
});
}
});
}
_dataParser(List<int> data) {
var value = Uint8List.fromList(data);
print("stream.value: $value"); // stream.value: [33]
var hr = ByteData.sublistView(value, 0, 1);
print("Heart rate: ${hr.getUint8(0)}");
return hr.getUint8(0); // Heart rate: 33
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: const Color(0xffE5E0A1),
elevation: 0,
centerTitle: true,
title: Text(
"Configuration",
style: TextStyle(
fontSize: 15.0,
color: Colors.black,
fontFamily: 'Montserrat',
fontWeight: FontWeight.normal,
),
),
leading: IconButton(
icon: Icon(
Icons.arrow_back,
color: Colors.black,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return ConfigurationScreen();
},
),
);
},
),
),
body: Column(
children: [
Container(
padding: EdgeInsets.only(top: 65),
alignment: Alignment.center,
child: Text(
'Device setting up...',
style: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.w600,
fontSize: 17,
color: const Color(0xa8000000),
height: 1.3333333333333333,
),
textHeightBehavior:
TextHeightBehavior(applyHeightToFirstAscent: false),
textAlign: TextAlign.center,
),
),
Container(
padding: EdgeInsets.symmetric(vertical: 120),
child: const SpinKitFadingCircle(
color: const Color(0xffF1C40E),
size: 200,
),
),
StreamBuilder<List<int>>(
stream: stream,
initialData: lastValue,
builder: (BuildContext context,
AsyncSnapshot<List<int>> snapshot) {
if (snapshot.connectionState ==
ConnectionState.active && snapshot.hasData) {
var currentValue = _dataParser(snapshot.data);
if (currentValue == 1)
{
print("Test Conf 1");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return ConfDeviceDone(device: widget.device,);
},
),
);
}
else if (currentValue == 0)
{
print("Test Conf 0");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return ConfDeviceDone(device: widget.device,);
},
),
);
}
}
else {
Fluttertoast.showToast(msg: "Bluetooth is not Active");
return Homepage(device: widget.device,);
}
},
),
],
),
);
}
}