【发布时间】: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,
],
);
}
}
【问题讨论】: