gpt4 book ai didi

flutter - RenderFlex 在底部溢出了 41 个像素。相关的导致错误的小部件是 Column

转载 作者:行者123 更新时间:2023-12-03 03:12:07 29 4
gpt4 key购买 nike

我需要创建一个搜索框,搜索结果在 ListView.Builder ,但我崩溃了!我试图通过获取 Container 来解决它高度值 MediaQuery.of(context).size.height但让我遇到同样的问题!

════════ Exception caught by rendering library ═════════════════════

The following assertion was thrown during layout: A RenderFlex overflowed by 41 pixels on the bottom.

The relevant error-causing widget was Column lib/pages/search.dart:78 The overflowing RenderFlex has an orientation of Axis.vertical. The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size. This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

The specific RenderFlex in question is: RenderFlex#1a63c relayoutBoundary=up1 OVERFLOWING ════════════════════════════════════════════════════════════



我的代码:
body: Column(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.all(10),
padding: EdgeInsets.only(right: 10),
decoration: BoxDecoration(
color: Colors.white,
border: new Border.all(
color: Colors.grey,
width: 1,
),
borderRadius: BorderRadius.all(new Radius.circular(10))),
child: DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.keyboard_arrow_down),
iconEnabledColor: Colors.grey,
iconSize: 50,
elevation: 16,
isExpanded: true,
style: TextStyle(color: Colors.black),
underline: Container(
height: 2,
),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>["Swift", "Dart"]
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)),
Container(
margin: EdgeInsets.all(10),
child: Column(
children: <Widget>[
TextField(
obscureText: true,
onChanged: (value) {
filterSearchResults(value);
},
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Color.fromRGBO(111, 192, 81, 1),
width: 1.5),
borderRadius: BorderRadius.circular(10)),
contentPadding:
EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
hintText: "Search",
prefixIcon: new Icon(Icons.search, color: Colors.grey),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10)),
borderSide: BorderSide(width: 1, color: Colors.grey),
)),
),
ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: items.length,
itemBuilder: (context, index) {
return ListTile(
title: Text('${items[index]}'),
);
},
),
],
),
),
],
),

这是什么问题,我该如何解决??

最佳答案

您需要放置Expanded在两个地方

body: Column(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.all(10),
padding: EdgeInsets.only(right: 10),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.grey,
width: 1,
),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.keyboard_arrow_down),
iconEnabledColor: Colors.grey,
iconSize: 50,
elevation: 16,
isExpanded: true,
style: TextStyle(color: Colors.black),
underline: Container(height: 2),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>["Swift", "Dart"]
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
Expanded( //TODO: Add Expanded here
child: Container(
margin: EdgeInsets.all(10),
child: Column(
children: <Widget>[
TextField(
obscureText: true,
onChanged: (value) {
filterSearchResults(value);
},
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Color.fromRGBO(111, 192, 81, 1),
width: 1.5,
),
borderRadius: BorderRadius.circular(10),
),
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
hintText: "Search",
prefixIcon: new Icon(Icons.search, color: Colors.grey),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10)),
borderSide: BorderSide(width: 1, color: Colors.grey),
),
),
),
Expanded( //TODO: Add Expanded here
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: items.length,
itemBuilder: (context, index) {
return ListTile(
title: Text('${items[index]}'),
);
},
),
),
],
),
),
),
],
)

关于flutter - RenderFlex 在底部溢出了 41 个像素。相关的导致错误的小部件是 Column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59491328/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com