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,);
              }
            },],);
  }
}

我的屏幕如下所示:

当我按下频段配置时:

enter image description here

它转到显示错误的屏幕:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)