【问题标题】:BoxConstraints forces an infinite height. errorBoxConstraints 强制无限高。错误
【发布时间】:2021-10-15 08:29:32
【问题描述】:

我希望显示进度圈,但是当我单击验证按钮时出现此错误 我在 ModalProgressHUD 小部件中收到错误

"BoxConstraints 强制无限高 RenderBox 未布置:RenderConstrainedBox#45825 relayoutBoundary=up14 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': 断言失败:第 1930 行第 12 行:'hasSize' "

这是我的代码

return Scaffold(
          key: page,
            body: ListView(
              children: [
                Stack(
                    fit: StackFit.passthrough,
                  children: [
                    Positioned(
                      child: Image.asset('images/1.png'),
                      width: size.width * 0.21,
                    ),
                    ...
                    Center(
                      child: Container(
                        margin: EdgeInsets.only(top: size.height * 0.1),
                        child: Column(
                          children: <Widget>[
                             Text("Informations Personnelles",
                                textAlign: TextAlign.center,
                                style: TextStyle(color: Colors.black54 , fontSize: 20 , fontWeight: FontWeight.w300 )
                            ),
                          ],
                        ),
                      ),
                    ),
                    ModalProgressHUD(
                        inAsyncCall: Provider.of<ModelHUD>(context).isloading,
                        child: Form(
                          key: _globalKey,
                          child: Padding(
                            padding: EdgeInsets.only(top : size.height*0.2),
                            child: Column(
                              children: [
                                SizedBox(height: size.height * 0.07,),
                                Center(
                                  ...
                                Center(
                                    child: MaterialButton(
                                      minWidth: size.width * 0.8,
                                      color: Color(0xffc0ddfe),
                                      height: 50,
                                      elevation: 3,
                                      shape: RoundedRectangleBorder(
                                          borderRadius: BorderRadius.all(
                                              Radius.circular(30.0))),
                                      onPressed: () {
                                        final modelhud = Provider.of<ModelHUD>(context ,listen: false);
                                        modelhud.changeIsLoading(true);
                                        uploadPic(context).then((value)
                                        {
                                          if(_profession == true)
                                            _store.addEleveInfos(u.uid,etabChoisi,niveau,Etats[2]);
                                          else {
                                            _store.addProfInfos(u.uid,etabChoisi,niveau);
                                          }
                                          _store.finaliser(u.uid);
                                          _store.changeProfession(u.uid , _profession);
                                          modelhud.changeIsLoading(false);
                                          Navigator.pushReplacementNamed(context, Home.id);
                                        });

                                      },
                                      child: Text("VALIDER",
                                          textAlign: TextAlign.center,
                                          style: TextStyle(color: Colors.white,
                                              fontSize: 20,
                                              fontWeight: FontWeight.w300)
                                      ),
                                    )
                                ),
                                SizedBox(height: size.height*0.2,),

                              ],
                            ),
                          ),


                        )
                    )
                  ]
              ),
              ]
            )
        );

这是 ModalProgressHUD 的代码

class ModalProgressHUD extends StatelessWidget {
  final bool inAsyncCall;
  final double opacity;
  final Color color;
  final Widget progressIndicator;
  final Offset? offset;
  final bool dismissible;
  final Widget child;

  ModalProgressHUD({
    Key? key,
    required this.inAsyncCall,
    this.opacity = 0.3,
    this.color = Colors.grey,
    this.progressIndicator = const CircularProgressIndicator(),
    this.offset,
    this.dismissible = false,
    required this.child,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (!inAsyncCall) return child;

    Widget layOutProgressIndicator;
    if (offset == null)
      layOutProgressIndicator = Center(child: progressIndicator);
    else {
      layOutProgressIndicator = Positioned(
        child: progressIndicator,
        left: offset!.dx,
        top: offset!.dy,
      );
    }

    return new Stack(
      children: [
        child,
        new Opacity(
          child: new ModalBarrier(dismissible: dismissible, color: color),
          opacity: opacity,
        ),
        layOutProgressIndicator,
      ],
    );
  }
}

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    ListView 为其子级提供无限的垂直空间,但小部件不能有无限的高度。

    您可能在ModalProgressHUD 中有一个小部件,它试图占据整个可用空间,在这种情况下是无限的。尝试查找BoxConstraints.expandSizedBox.expand,或者您可以通过添加ModalProgressHUD 代码来编辑您的问题,我们可以看看。

    【讨论】:

      猜你喜欢
      • 2022-01-04
      • 1970-01-01
      • 2020-12-22
      • 2023-04-09
      • 2020-04-27
      • 2019-11-04
      • 2019-12-02
      • 2019-02-25
      • 2020-09-21
      相关资源
      最近更新 更多