首页 > 解决方案 > 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,
  ),
);


标签: androidflutterflutter-layout

解决方案


这是获得无限宽度的问题。您可以只用 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,
                ),
              ),
            )
          ],
        ),
      ),
    );

推荐阅读