The ListView is not working. I want to display 3 different stateful widgets to a inside list view but I am getting error
Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderViewport#01b62 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
Column(
children: <Widget>[
//wrap with list of widget
ListView(
children: [
Expanded(child: Body(box.get('state'), true)),
Divider(color: Colors.black),
Expanded(child: Body(box.get('state'), false)),
],
)
],
),
I am using this code to display widgets inside ListView.
my Body widget return listview.builder or sometimes simple text widget.
When I not using only column widget screen splits in two part - upper listview.builder and lower listview.builder
and when I am using this code it throwing an error.
Desired output-
first body widget should be display in entire screen and once first widget end second body widget should be display in entire screen.
How to do this? And why does this error occur?
Note: shrinkwrap is true inside Body widget(listview.builder).
You need to add this code
physics: NeverScrollableScrollPhysics(),
in the all ListView.builder,
Related
I want to build a page that contains so many widgets.
That page's widget tree is like this.
Material
Scaffold
SafeArea
NestedScrollView
TabBarView
ScrollConfiguration
SingleChildScrollView
Column
NestedScrollView
ScrollConfiguration
TabBarView
Everything was fine before the last TabBarView was added.
After adding the last TabBarView, the page was not displayed in my device screen.
And this error was logged.
The following assertion was thrown during performResize():
Horizontal viewport was given unbounded height.
Viewports expand in the cross axis to fill their container and constrain their children to match their extent in the cross axis. In this case, a horizontal viewport was given an unlimited amount of vertical space in which to expand.
The following assertion was thrown during performLayout():
RenderBox was not laid out: RenderViewport#cf3d7 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1979 pos 12: 'hasSize'
And, this is the Widget contains the last TabBarView.
Widget build(BuildContext context) {
return NestedScrollView(
headerSliverBuilder: (context, value) {
return [
SliverToBoxAdapter(child: AreaTypeDesignTabBar()),
];
},
body: ScrollConfiguration(
behavior: NonGlowScrollBehavior(),
child: TabBarView(
physics: const NeverScrollableScrollPhysics(),
controller: _tabController.tabController,
children: [
VisionWidget(
areaType: AreaType.CAREER,
visionText: getVisionByAreaType(AreaType.CAREER),
),
VisionWidget(
areaType: AreaType.STUDY,
visionText: getVisionByAreaType(AreaType.STUDY),
),
VisionWidget(
areaType: AreaType.SOCIAL,
visionText: getVisionByAreaType(AreaType.SOCIAL),
),
],
),
),
);
}
Maybe, because the height of TabBarView is not static, so the upper SingleChildScrollView could not be rendered.
To Solve this problem, I tried to wrap the second picture's Column with Expanded, but failed.
Also, I tried to only wrap the second picture's TabBarView with Expanded, but failed...
In this situation, how do I set the TabBarView's height dynamically??
This is the likes Widget which shows likes. It is called inside a scrollview column of another dart file. Everything was working fine before this widget's addition
#override
Widget build(BuildContext context) {
return Container(
height: 100,
child: Row(
children: <Widget>[
Expanded(
child: ListTile(
leading: IconButton(
icon: likedByReader
? Icon(Icons.favorite, color: Colors.orange)
: Icon(Icons.favorite, color: Colors.grey),
onPressed: _pressed,
),
),
),
Expanded(
child: Text('${likesList.length} likes'),
)
],
),
);
}
This is how LikeWidget is called
Expanded(child: LikeWidget(widget.readerEmail, widget.blogUIDInFirebase),),
Error shown in the console
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
RenderBox was not laid out: _RenderSingleChildViewport#89f28 relayoutBoundary=up10 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1694 pos 12: 'hasSize'
You can't use Expanded inside a SingleChildScrollView. since the SingleChildScrollView has special constraints and Expanded it's expecting to be used inside a Column or Row .
There is a similar question here , and basically you should do conditional rendering for this to work, return a column when the content height is smaller than the parent height, and return a scrollview when the content doesn't fit .For this i would use a LayoutBuilder, but a CustomScrollView seems to be more performant Check the answers of that question.
Can anybody see why I'm getting this error on the first child: Column? I'm using a stack in my build. and tried wrapping each widget in a Flexible widget but can't figure out where the code is overflowing. The screen flashes the telltale yellow/black renderflex lines for just a second but then seems to render just fine. The messages in the console are annoying though as is the little yellow/black flash at the beginning.
A RenderFlex overflowed by 99804 pixels on the bottom.
The relevant error-causing widget was:
Column file:///E:/FlutterProjects/myproject/lib/builders/CustomPageView.dart:47:26
Here's the code. Line 47 is the first child: column.
class _CustomPageViewState extends State<CustomPageView> {
Widget build(context) {
return PageView.builder(
itemCount: widget.speakcrafts.length,
itemBuilder: (context, int currentIndex) {
return createViewItem(widget.speakcrafts[currentIndex], context);
},
);
}
Widget createViewItem(SpeakContent speakcraft, BuildContext context) {
var contsize = MediaQuery.of(context).size.width * 0.60;
var contHeightsize = MediaQuery.of(context).size.height;
return Stack(
children: <Widget>[
Container(
color: Colors.black12,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.network(
speakcraft.gavatar,
height: contsize,
width: contsize,
),
PlayerWidget2(url: kUrl),
],
),
),
],
),
),
],
);
And here's the full error code with chunhunghan's ConstrainedBox suggestion;
A RenderFlex overflowed by 99325 pixels on the right.
The relevant error-causing widget was:
Row file:///E:/FlutterProjects/speakoholic/lib/builders/CustomPageView.dart:121:25
The specific RenderFlex in question is: RenderFlex#d5393 relayoutBoundary=up8 OVERFLOWING
parentData: offset=Offset(0.0, 556.9); flex=null; fit=null (can use size)
constraints: BoxConstraints(0.0<=w<=674.9, 0.0<=h<=Infinity)
size: Size(674.9, 100000.0)
direction: horizontal
mainAxisAlignment: center
mainAxisSize: max
crossAxisAlignment: center
textDirection: ltr
verticalDirection: down
child 1: RenderErrorBox#d3900
parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
constraints: BoxConstraints(unconstrained)
size: Size(100000.0, 100000.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════════════════════════
A RenderFlex overflowed by 100385 pixels on the bottom.
The relevant error-causing widget was:
Column file:///E:/FlutterProjects/speakoholic/lib/builders/CustomPageView.dart:49:28
It turns out I had to follow the error further down the widget tree of this widget;
child: PlayerWidget2(url: kUrl))
Within PlayerWidget2 was a path that was null prior to a PageViewBuilder being built. This threw a null path error which lead to the renderflex error. Once built, the null was filled in with a path. So in order to get rid of the errors I simply added a default path to the widget to fill in the null until the PageViewBuilder was built.
you can wrap your whole body content as a child of SingleChildScrollView SinglechildScrollView widget which may help you to overcome from this issue,or you can also make use of listview which can arrange list of widgets properly ListView
Code: Basically I have a simple app with three images aligned. I have 1 column and two rows. First row has two images and second row has 1 image aligned. Its the structure of the app. It just aligns perfectly when run below code in device but the moment I run on WEB there is this overflow. I try resizing the browser window only then it begins to become pretty again. Is there a workaround for Flutter Web please on how should I do the alignments here? Below code is inside body and inside Scaffold. I am attaching pics from device where there is no issue and from Flutter web where there is overflow issue.
return Column(
mainAxisAlignment: MainAxisAlignment.center,
//crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: FlatButton(
child: Image.asset('images/image1.png'),
),
),
Expanded(
child: FlatButton(
child: Image.asset('images/image1.png'),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: Image.asset('images/image1.png'),
),
],
),
],
);
}
Error:
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY
╞═════════════════════════════════════════════════════════ The
following assertion was thrown during layout: A RenderFlex overflowed
by 1238 pixels on the bottom.
The relevant error-causing widget was: Column
file:///C:/Users/1025632/Documents/GitHub/flutter-course/diceylips/lib/main.dart:43:12
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#1ad1e
relayoutBoundary=up1 OVERFLOWING: creator: Column ← DicePage ←
_BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ←
CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
_InkFeatures-[GlobalKey#cb60e ink renderer] ← NotificationListener ←
PhysicalModel ← ⋯ parentData: offset=Offset(0.0, 56.0); id=_ScaffoldSlot.body (can use size) constraints:
BoxConstraints(0.0<=w<=1280.0, 0.0<=h<=554.0) size: Size(1280.0,
554.0)
direction: vertical
mainAxisAlignment: center
mainAxisSize: max
crossAxisAlignment: center
verticalDirection: down
Image with no issue in device
Image with overflow issue in chrome
Wrap the column with a sized box or container with defined height and width
SizedBox(
height:200,
width:200,
child: your column goes here,
)
Add below code inside Container
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
....
....
)
This is the generic way to define full width and height to your Container
If you don't try to fit your widget in screen and scroll is an option for you, you can use listview or a similar widget.
ListView(
children: <Widget>[
Column(
Otherwise, wrapping Container with MediaQuery.of(context).size.width and MediaQuery.of(context).size.height will work but there is just one catch here, if you use an appbar this height should be "MediaQuery.of(context).size.height - AppBar().preferredSize.height"
I am try use SliverList for render data from backend (Firestore) in list. But I get error:
The following assertion was thrown building
NotificationListener: Incorrect use of
ParentDataWidget.
Flexible widgets must be placed inside Flex widgets. Flexible(no
depth, flex: 1, dirty) has no Flex ancestor at all. The ownership
chain for the parent of the offending Flexible was: RepaintBoundary
← IndexedSemantics ← NotificationListener ←
KeepAlive ← AutomaticKeepAlive ← KeyedSubtree ← SliverList ← Viewport
← IgnorePointer-[GlobalKey#1e502] ← Semantics ← ⋯
new CustomScrollView(
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate([
new Flexible(
child:
new FirestoreAnimatedList(
query: reference
.orderBy('timestamp', descending: true)
.snapshots(),
itemBuilder: (_, DocumentSnapshot snapshot,
Animation<double> animation) {
return new Widget(
snapshot: snapshot,
animation: animation,
But if I remove Flexible it give error:
The following assertion was thrown during performResize(): Vertical
viewport was given unbounded height.
Viewports expand in the scrolling direction to fill their container.In
this case, a vertical viewport was given an unlimited amount of
vertical space in which to expand. This situation typically happens
when a scrollable widget is nested inside another scrollable widget.
If this widget is always nested in a scrollable widget there is no
need to use a viewport because there will always be enough vertical
space for the children. In this case, consider using a Column instead.
Otherwise, consider using the "shrinkWrap" property (or a
ShrinkWrappingViewport) to size the height of the viewport to the sum
of the heights of its children. User-created ancestor of the
error-causing widget was: FirestoreAnimatedList
If I replace FirestoreAnimatedlist with Placeholder() there is no problem:
new CustomScrollView(
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate([
Placeholder(),
Placeholder(),
Placeholder(),
How I can solve?
Thanks everyone!
Incorrect use of ParentDataWidget error in Flutter occurs when the Child widget has not matched the parent widget.
In your case, this error happens due to the Flexible() widget. It is not a descendant of a Flex widget:
new CustomScrollView(
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate([
new Flexible(
child:
new FirestoreAnimatedList()
...
To solve this error, your child widget must have the expected parent widget. Some of the widget and their parent widgets are:
Widget
Parent Widget
Expanded()
Row(), Column(), Flex()
Flexible()
Row(), Column(), Flex()
Positioned()
Stack()
TableCell()
Table()
Here Flexible is a descendant of Flex:
Flex(
direction: Axis.horizontal,
children: [
Flexible(
child: MyWidget(),
),
],
)
Row is also a Flex widget:
Row(
children: [
Expanded(
child: MyWidget(),
),
],
)
And so is Column:
Column(
children: [
Flexible(
child: MyWidget(),
),
],
)
Another option is to just get rid of the Flexible widget by wrapping your widget in a Container():
Container(
child: MyWidget(),
)