如何解决RenderCustomMultiChildLayoutBox 对象在布局过程中被赋予无限大小
我正在使用 BLE esp32 从传感器获取数据,但是当我想通过从 BLE 设备获取数据进行校准时,它给了我这个错误。 我一按配置它就会移动到设备设置页面 我想要的是,在我从 BLE 获得值 1 之前,它应该继续显示此屏幕,一旦 1 出现,它应该转到另一个屏幕以显示完成的消息和图片。而是显示底部溢出错误消息“蓝牙未激活”,我该如何避免?并跳转到下一页? BLE 也处于活动状态,因为我检查了另一个屏幕上出现的值,但是对于连接的设备,此屏幕上没有发生这种情况
代码:
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,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,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,);
}
},],);
}
}
我的屏幕如下所示:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。