Flutter 颤振:无限宽
我正在学习颤振课程,以下是我的相关代码:Flutter 颤振:无限宽,flutter,constraints,Flutter,Constraints,我正在学习颤振课程,以下是我的相关代码: Container( color: kBottomContainerColour, margin: EdgeInsets.only(top: 10.0), width: double.infinity, height: kBottomContainerHeight, ), 我一直
Container(
color: kBottomContainerColour,
margin: EdgeInsets.only(top: 10.0),
width: double.infinity,
height: kBottomContainerHeight,
),
我一直在想:
These invalid constraints were provided to _RenderColoredBox's layout() function by the following function, which probably computed the invalid constraints in question:
RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:268:14)
The offending constraints were: BoxConstraints(w=Infinity, h=80.0)
The relevant error-causing widget was:
Container file:///F:/Works/Projects/flutter/Flutter-Course-Resources/bmi-calculator-flutter1/lib/input_page.dart:241:24
虽然它在课程中运行良好
请帮助不要使用双精度无穷大。使用MediaQuery从当前小部件上下文获取大小,并从中获取宽度。 在这种情况下,请执行以下操作:
Container(color: kBottomContainerColour,
margin: EdgeInsets.only(top: 10.0),
width: MediaQuery.of(context).size.width
height: kBottomContainerHeight,
),
请注意,每次使用MediaQuery时,小部件都将重新加载其状态。因此,请确保分解您的小部件,并遵循谷歌的性能指南:
而不是
宽度:double.infinity
使用
你的集装箱在哪?它是否在
行
、列
或堆栈
小部件中?
width: MediaQuery.of(context).size.width