How do I fix 'RenderFlex overflowed by 283 pixels on the bottom' in flutter? - flutter

The error occurs in a screen where I am trying to render a list of contributions. I have tried a number of things (listed below), none of which works.
Wrapping my column widget with Expanded()
Wrapping my Column widget with Flexible()
Wrapping my Listview.builder() with SingleScrollView() then adding physics: NeverScrollableScrollPhysics() in it.enter image description here
I have a contributions screen with contains a Lisview.builder()
This is my contributions screen
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My Chamas'),
centerTitle: true,
),
floatingActionButton: CustomFloatingActionButton(
buttonLabel: 'Contribute +',
),
resizeToAvoidBottomInset: false,
body: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.22,
margin: EdgeInsets.only(top: 20),
child: PageView.builder(
itemCount: widget.availableChamas.length, // number of cards
controller: PageController(viewportFraction: 0.8),
onPageChanged: (int index) => setState(() => _index = index),
/*** Begin snapping chama cards */
itemBuilder: (_, i) {
return Transform.scale(
scale: i == _index ? 1 : 0.9,
child: Card(
elevation: 6,
margin: EdgeInsets.only(right: 0),
color: Theme.of(context).primaryColor, // Card backgound color
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
stops: [0.1, 0.9],
colors: [Colors.indigo, Colors.teal],
),
),
child: ChamaCard(
id: widget.availableChamas[i].id,
name: widget.availableChamas[i].name,
totalMembers: widget.availableChamas[i].totalMembers,
totalContributions: widget.availableChamas[i].totalContributions,
),
),
),
);
/*** End snapping chama cards */
},
),
),
SizedBox(height: 15),
Container(
padding: EdgeInsets.only(right: 15, left: 15),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
'All my chamas',
style: TextStyle(fontSize: 15, color: Colors.red[900]),
),
Icon(
Icons.arrow_forward,
size: 17,
color: Colors.red[900],
)
],
),
SizedBox(height: 15),
Row(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('My', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
'Contributions',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
),
SizedBox(width: 5),
Text(
'to this chama',
style: TextStyle(color: Colors.green[800]),
)
],
),
],
)
],
),
SizedBox(height: 10),
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return ChamaListItem(
id: widget.availableContributions[index].id,
amount: widget.availableContributions[index].amount,
contributionDate: widget.availableContributions[index].contributionDate,
);
},
itemCount: widget.availableContributions.length,
),
],
),
)
],
),
);
}
This is my ChamaListItem widget which simply holds a single contribution card. This is what I am iterating to build a scrollable list in my Listview.builder()
Widget build(BuildContext context) {
return Card(
elevation: 4,
shadowColor: Color.fromRGBO(255, 255, 255, 0.5),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Date',
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: 5),
Text(
'$contributionDate',
style: TextStyle(color: Colors.red[900]),
)
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text('Kes'),
SizedBox(width: 1),
Text(
'$amount',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
],
)
],
),
),
);
}
This is the error thrown in the console
Performing hot reload...
Syncing files to device sdk gphone x86 arm...
Reloaded 5 of 566 libraries in 1,183ms.
======== Exception caught by rendering library =====================================================
The following assertion was thrown during layout:
A RenderFlex overflowed by 283 pixels on the bottom.
The relevant error-causing widget was:
Column file:///Users/Steve/StudioProjects/m_chama/lib/screens/myChamas.dart:35:13
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#3a382 relayoutBoundary=up1 OVERFLOWING
... needs compositing
... parentData: offset=Offset(0.0, 105.5); id=_ScaffoldSlot.body (can use size)
... constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=697.5)
... size: Size(392.7, 697.5)
... direction: vertical
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
====================================================================================================

Wrap Column widget with SingleChiledScrollView

Related

RenderFlex children have non-zero flex but incoming width constraints are unbounded - Flutter

I'm trying to show cart items horizontally using listview builder but it is throwing up following error
RenderFlex children have non-zero flex but incoming width constraints are unbounded (When a row is in a parent that does not provide a finite width constraint, for example if it is in a horizontal scrollable, it will try to shrink-wrap its children along the horizontal axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining space in the horizontal direction.)
I already wrapped the list view builder with defined height but still throwing up the error
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('MY CART', style: GoogleFonts.oswald(color: Colors.black, fontSize: 18.0, fontWeight: FontWeight.w400)),
const SizedBox(height: 20.0),
SizedBox(
height: 180.0,
width: double.infinity,
child: ListView.builder(
itemCount: 2,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index){
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 150.0,
width: 150.0,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/dress.jpg')
),
borderRadius: BorderRadius.all(Radius.circular(15.0))
),
),
const SizedBox(width: 10.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('PRODUCT TITLE',
style: GoogleFonts.oswald(
textStyle: const TextStyle(
color: Colors.black,
fontSize: 14.0)), overflow: TextOverflow.visible,),
const SizedBox(height: 5.0),
Text('SIZE: M',
style: GoogleFonts.oswald(
textStyle: const TextStyle(
color: Colors.black45,
fontSize: 16.0))),
const SizedBox(height: 10.0),
Text('10 DOLLARS',
style: GoogleFonts.oswald(
textStyle: const TextStyle(
color: Colors.black,
fontSize: 16.0))),
],
),
)
],
);
},
),
),
],
)
This was happened because you use expanded in row inside horizontal listview, you have two option :
One: remove the expanded widget inside Row inside itemBuilder.
Two: set width for item inside itemBuilder:
itemBuilder: (context, index){
return SizedBox(
width: 400.0, // <--- add this
child: return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 150.0,
...
);
}

The following assertion was thrown during layout: A RenderFlex overflowed by 71 pixels on the right

======== Exception caught by rendering library =====================================================
The following assertion was thrown during layout:
A RenderFlex overflowed by 71 pixels on the right.
The relevant error-causing widget was:
Row Row:file:///Users/ddo/Desktop/projects/yedek/deneme_kaynak/lib/views/screens/category/screens/first_screen.dart:82:40
The overflowing RenderFlex has an orientation of Axis.horizontal.
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#37132 relayoutBoundary=up13 OVERFLOWING
... parentData: offset=Offset(12.0, 20.0) (can use size)
... constraints: BoxConstraints(w=134.6, 0.0<=h<=Infinity)
... size: Size(134.6, 36.0)
... direction: horizontal
... mainAxisAlignment: center
... mainAxisSize: max
... crossAxisAlignment: center
... textDirection: ltr
... verticalDirection: down
◢◤◢◤◢◤
Widget build(BuildContext context) {
List<Category> childs = widget.snapshot.data.allCategories
.where((element) => element.parentId == widget.id)
.toList();
return Positioned(
left: MediaQuery.of(context).size.width * .2,
child: Container(
width: MediaQuery.of(context).size.width * .8,
height: MediaQuery.of(context).size.height,
child: Column(
children: [
childs.length != 0
? Container(
width: MediaQuery.of(context).size.width * .8,
height: MediaQuery.of(context).size.height,
child: MasonryGridView.count(
cacheExtent: 4,
padding: EdgeInsets.fromLTRB(0, 0, 0, 250),
crossAxisCount: 2,
//mainAxisSpacing: 2,
//crossAxisSpacing: 2,
itemCount: childs.length + 1,
itemBuilder: (context, int) => int == 0
? Card(
margin: EdgeInsets.fromLTRB(3, 3, 3, 1),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
gradientFrom[3],
gradientTo[3],
])),
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 20, horizontal: 12),
/*
> > > > > ROW < < < < <
//first_screen.dart:82:40 Row
*/
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
/*Padding(
padding:
const EdgeInsets.all(0.0),
child: Image.asset(
"assets/images/welding.png",
width: MediaQuery.of(context)
.size
.width *
.14,
),
),*/
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: MediaQuery.of(context).size.width * .5,
child: Text(widget.category,
textScaleFactor: 1,
overflow: TextOverflow.clip,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
fontSize: 15.0)),
),
/* Text('see_all'.tr(),textScaleFactor: 1,
style: TextStyle(
color: Colors.white70,
fontSize: 10)),*/
],
),
/* Icon(
Icons.chevron_right,
color: Colors.white,
)*/
]),
),
),
)
: Column(
children: [
int == 1 ? SizedBox(height: 75,): SizedBox(),
InkWell(
onTap: () {
gotoSuborProd(widget.snapshot, int, childs);
},
child: Card(
margin: EdgeInsets.fromLTRB(3, 2, 3, 2),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border:
Border.all(color: gradientFrom1[int % 5], width: 5)
/*gradient: LinearGradient(colors: [
gradientFrom[int % 5],
gradientTo[int % 5],
])*/
),
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 20, horizontal: 3),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
imageGet(Uri.encodeComponent(
childs[int - 1].imageUrl ?? "")),
Padding(padding: EdgeInsets.only(bottom: 16.0)),
Text(childs[int - 1].category,
textScaleFactor: 1,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 14.0)),
/*Text(
childs[int-1].seoTitle.toString(),textScaleFactor: 1,
style: TextStyle(
color: Colors.white70,
fontSize: 12.0)),*/
]),
),
),
),
),
],
)
// ignore: missing_return
),
)
: Container(),
],
),
));
}
Wrap your Column with Expanded widget, this will solve BoxConstraints(w=134.6, 0.0<=h<=Infinity
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 20, horizontal: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded( //here
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
children: [
move your title Widget to top of the Column like shown in screenshot:

Flutter: Container above ListView scrollable

I want to display a Container with Text followed by a ListView of categories. In my current code, it works out except that I wasn't able to figure out, how to make the Text and Container scrollable as well (so it moves upside away out of the frame).
It looks currently like this:
The blue container is static and stays at its location while the red ListView is perfectly fine scrollable.
Current Code:
body: Container(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Container(
padding: EdgeInsets.fromLTRB(15, 0, 0, 10),
child: Align(
alignment: Alignment.topLeft,
child: const Text("Browse through the individual categories...", style: TextStyle(fontSize: 32, color: Colors.black, fontWeight: FontWeight.w900)),
),
),
Expanded(
child: ListView.builder(
itemCount: 20,
itemBuilder: (context, index){
return Padding(
padding: const EdgeInsets.all(8.0),
child: Category(),
);
}
),
),
],
),
I tried to implement this answer.
body: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Container(
padding: EdgeInsets.fromLTRB(15, 0, 0, 30),
child: Align(
alignment: Alignment.topLeft,
child: const Text("Browse through the individual categories...", style: TextStyle(fontSize: 32, color: Colors.black, fontWeight: FontWeight.w900)),
),
),
Expanded(
child: ListView.builder(
shrinkWrap: true,
primary: false,
itemCount: 20,
itemBuilder: (context, index){
return Padding(
padding: const EdgeInsets.all(8.0),
child: Category(),
);
}
),
),
],
),
),
I get the following errors:
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
RenderBox was not laid out: RenderFlex#12630 relayoutBoundary=up11 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
Add these lines in your listview
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
You can skip the Expanded widget for this solution.
Just removed SingleChildScrollView widget it will work.
Wrap with SingleChildScrollView widget and then add physics : NeverScrollableScrollPhysics() to ListView widget.

Flutter: VerticalDivider is not shown

I have this widget tree:
Scaffold
AppBar
Column
Center
SingleChildScrollView
FutureBuilder
Container
Flex
direction: Axis.vertical,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FlatButton(
color: Colors.red,
onPressed: () => {},
padding: EdgeInsets.all(10.0),
child: Row(
children: <Widget>[
Icon(
Icons.star,
color: Colors.red,
),
Text(
"4.5",
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold),
)
],
),
),
VerticalDivider(
width: 1,
color: Colors.black,
thickness: 1,
indent: 2,
endIndent: 2,
),
FlatButton() //like above
VerticalDivider()//like above
FlatButton()//like above
The codes make this image:
I wondered why VerticalDivider is not shown ?
I am using flutter_linux_1.17.0-stable flutter sdk
I think this happen, when you parent widget does't have specific height.
Moreover, if you look implementation of VerticalDivider they didn't specify size of sizedbox or container that's why it doesn’t have any height, any by IntrinsicHeight widget, we can specify child widget should be hight of parent.
Wrap your row widget with IntrinsicHeight.
Flex
direction: Axis.vertical,
children: <Widget>[
IntrinsicHeight( // added widget
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[

Flutter bottom Overflow

Can anyone help me with this exception that I keep running into? I am not sure what attempt next in order to fix the overflow as the panel expands. I've tried wrapping it into a flexible widget but that doesn't seem to fix the issue.
Here is my exception:
════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 68 pixels on the bottom.
The relevant error-causing widget was:
Column file:///Users/selorm/AndroidStudioProjects/flutter_master/lib/src/widgets/weather_widget.dart:17:14
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#8829e relayoutBoundary=up1 OVERFLOWING
... needs compositing
... parentData: offset=Offset(0.0, 0.0) (can use size)
... constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=410.6)
... size: Size(411.4, 410.6)
... direction: vertical
... mainAxisAlignment: center
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════
Here is my code:
#override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Flexible(
//flex: 2,
//fit: FlexFit.loose,
child: Text(
this.weather.cityName.toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.w900,
letterSpacing: 5,
color: AppStateContainer.of(context).theme.accentColor,
fontSize: 25),
),
),
SizedBox(
height: 20,
),
Flexible(
//flex: 1,
child:Text(
this.weather.description.toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.w100,
letterSpacing: 5,
fontSize: 20,
color: AppStateContainer.of(context).theme.accentColor),
),
),
WeatherSwipePager(weather: weather),
Padding(
child: Divider(
color:
AppStateContainer.of(context).theme.accentColor.withAlpha(50),
),
padding: EdgeInsets.all(10),
),
ForecastHorizontal(weathers: weather.forecast),
Padding(
child: Divider(
color:
AppStateContainer.of(context).theme.accentColor.withAlpha(50),
),
padding: EdgeInsets.all(10),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ValueTile("wind speed", '${this.weather.windSpeed} m/s'),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15),
child: Center(
child: Container(
width: 1,
height: 30,
color: AppStateContainer.of(context)
.theme
.accentColor
.withAlpha(50),
)),
),
ValueTile(
"sunrise",
DateFormat('h:m a').format(DateTime.fromMillisecondsSinceEpoch(
this.weather.sunrise * 1000))),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15),
child: Center(
child: Container(
width: 1,
height: 30,
color: AppStateContainer.of(context)
.theme
.accentColor
.withAlpha(50),
)),
),
ValueTile(
"sunset",
DateFormat('h:m a').format(DateTime.fromMillisecondsSinceEpoch(
this.weather.sunset * 1000))),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15),
child: Center(
child: Container(
width: 1,
height: 30,
color: AppStateContainer.of(context)
.theme
.accentColor
.withAlpha(50),
)),
),
ValueTile("humidity", '${this.weather.humidity}%'),
]
),
],
),
);
}
}
You have to two quick options:
use ListView() with shrinkWrap set to true
#override
Widget build(BuildContext context) {
return ListView(
shrinkWrap: true,
children: <Widget>[
// Children
],
);
}
wrap Column() with singleChildScrollView()
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
// Children
],
),
);
}
That's it