android - RenderBox 未布置:RenderRepaintBoundary#21325 NEEDS-LAYOUT NEEDS-PAINT
问题描述
我正在尝试创建一个文本字段,并且每次运行代码时都会显示以下 renderBox 错误。请帮助我度过难关。
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Row(
children: <Widget>[
Container(
// padding: EdgeInsets.all(30),
child: TextField(
style: TextStyle(
color: Colors.black,
),
decoration: kCityTextFieldInputDecoration,
),
),
],
),
),
);
}
并且kCityTextFieldInputDecoration
是
const kCityTextFieldInputDecoration = InputDecoration(
filled: true,
fillColor: Colors.white,
icon: Icon(
Icons.location_city,
color: Colors.white,
),
hintText: 'Enter city name',
hintStyle: TextStyle(
color: Colors.grey,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
borderSide: BorderSide.none,
),
);
解决方案
这是获得无限宽度的问题。您可以只用 Container 包装Expanded
或在其中提供宽度。
return Scaffold(
body: SafeArea(
child: Row(
children: <Widget>[
Expanded(
child: Container(
// padding: EdgeInsets.all(30),
child: TextField(
style: TextStyle(
color: Colors.black,
),
decoration: kCityTextFieldInputDecoration,
),
),
)
],
),
),
);
推荐阅读
- javascript - 当 Animated.View 有一个 Animated.ScrollView 作为孩子时,PanResponder 在 Android 上无法正常工作
- html - 如果我必须将文本拆分为多个 div,我将如何使 text-align 的行为方式与对单个文本的行为方式相同
- python - 使用 Keras fit_generator 训练后保存的模型无法正确给出预测
- java - 覆盖等于和等于之间有什么区别?
- excel - 如何插入一个要求输入日期的输入框,然后在该日期之后添加到行?
- javascript - 如何遍历 JavaScript 中的静态值(常量)列表?
- android - 无法生成用于在 Android Studio 中发布的签名 APK
- html - 在较小的屏幕上更改网格项目的顺序
- excel - 无法让 VBA 编辑现有超链接
- spring - 如何在 Spring Boot 中结合 REST 和 Websocket?