I need to create a search box with the result of searching in ListView.Builder
, but I have a crash! I tried to solve it with get the Container
height value MediaQuery.of(context).size.height
but get me the same issue!
════════ 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 ════════════════════════════════════════════════════════════
My Code:
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]}'),
);
},
),
],
),
),
],
),
What is the issue and how can I solve it??
You need to place Expanded
in two places
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]}'),
);
},
),
),
],
),
),
),
],
)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments