flutter column widget receive null about height in runtime - flutter

AnimatedContainer(
duration: Duration(milliseconds: 500),
height: isExpanded == true ? 100 : 0,
child: Column(
children: <Widget>[
GridView.extent(
maxCrossAxisExtent:
SetDeviceRatio.safeBlockHorizontal * 30,
children: List.generate(foodCode.length, (index) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
height: 50,
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[Text(foodCode[index])],
),
),
);
})),
],
),
),
I made code like this and in runtime it said
RenderBox was not laid out: RenderConstrainedBox#fce1e relayoutBoundary=up9 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1687 pos 12: 'hasSize'
The relevant error-causing widget was
AnimatedContainer
lib/MainUI/MainCategoryUI.dart:71
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════
The method '>' was called on null.
Receiver: null
Tried calling: >(1e-10)
The relevant error-causing widget was
Column
when i delete Column it works well but i don't get it why.
in column there is gridview and each row has same height and can calculate how long height need
so i thought column didn't need height variable.

Related

Flutter - Fixed button next to horizontal scroll

I have a dialog with a button and I want to add a horizontal scroll next to the button, so this way the button is fixed in the left and the scroll is in the right. I tried using a Row but I got the following error:
The following assertion was thrown during performResize():
Horizontal viewport was given unbounded width.
.
.
.
The following assertion was thrown during performLayout():
RenderBox was not laid out: RenderViewport#48cb5 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1982 pos 12: 'hasSize'
.
.
.
The specific code I used for this is the following:
SizedBox(
height: 80,
child: Row(
children: <Widget>[
AddUsersButton(newTaskCubit: newTaskCubit),
SizedBox(
height: 80,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
UserExample(newTaskCubit: newTaskCubit),
UserExample(newTaskCubit: newTaskCubit),
UserExample(newTaskCubit: newTaskCubit),
UserExample(newTaskCubit: newTaskCubit),
],
),
)
],
),
),
Give SizeBox() width also and use shrikWrap with your Listview .As the scroll is Horizontal its asking for you a fixed widht.
You can use shrinkWrap: true, on ListView
SizedBox(
height: 80,
child: ListView(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
children: <Widget>[....],
),
You can check more about What does the shrinkWrap property do in Flutter?

RenderBox was not laid out stack

Hello this is my error:
RenderBox was not laid out: RenderFlex#b7b0f relayoutBoundary=up1 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1940 pos 12: 'hasSize'
This is my code:
#override
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder(
future: createListOfMatches(),
builder: (context, snapshot) {
return Row(
children: [match()],
);
}),
floatingActionButton:
FloatingActionButton(child: Text('next'), onPressed: () => next()),
);
}
match() {
return Stack(
children: [
Positioned(
top: top,
left: left,
child: Draggable(
data: 10,
onDragUpdate: (details) {
top = top + details.delta.dy;
left = left + details.delta.dx;
print('$top, $left');
setState(() {});
},
child: Material(
child: Container(
height: 50, width: 50, child: Image.asset('match.jpg'))),
feedback: Material(
child: Container(
height: 50, width: 50, child: Image.asset('match.jpg'))),
)),
],
);
}
thank you in advance
In the flutter documentation there are a few common failures:
there is also ‘RenderBox was not laid out’"
While this error is pretty common, it’s often a side effect of a
primary error occurring earlier in the rendering pipeline.
What does the error look like?
The message shown by the error looks like this:
content_copy RenderBox was not laid out: RenderViewport#5a477
NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
How might you run into this error?
Usually, the issue is related to violation of box constraints, and it
needs to be solved by providing more information to Flutter about how
you’d like to constrain the widgets in question. You can learn more
about how constraints work in Flutter on the page Understanding
constraints.
The RenderBox was not laid out error is often caused by one of two
other errors:
‘Vertical viewport was given unbounded height’ ‘An
InputDecorator…cannot have an unbounded width’
I hope this could help you a little.

Problems with a ListView

I make a application in flutter.
It's simple. In the principal layout exist an stack. In the first level are a background (what its a simple gradient), and in the second lever are the "body" of the application.
In this body of application i have a column (To put one item below another). this column are divided by separate widgets. One is for the "tile", and other is for a ListView, this ListView will show information from a database, but in this moment i only create 10 items for an example.
The code is this:
//This for a homepage
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Stack(
children: [
Background(),
HomeBody(),
],
),
);
The background (are in another file, in the homepage are imported):
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [0.2, 0.8],
colors: [
Color(0xff2E305F),
Color(0xff202333),
],
)),
);
And this is the "body":
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
PageTitle(),
Changes(),
],
),
);
}
}
class PageTitle extends StatelessWidget {
const PageTitle({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 20),
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 25,
),
Text(
'Biggest Title',
style: TextStyle(
color: Colors.white,
fontSize: 55.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(
//height: 1,
),
Text(
'low subtitle',
style: TextStyle(
color: Colors.white,
fontSize: 14.0,
fontWeight: FontWeight.w300,
),
),
],
),
),
);
}
}
class Changes extends StatelessWidget {
const Changes({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return ListView(
children: [
Text('Text0'),
Text('Text0'),
Text('Text0'),
Text('Text0'),
Text('Text0'),
Text('Text0'),
Text('Text0'),
Text('Text0'),
Text('Text0'),
Text('Text0'),
Text('Text0'),
],
);
}
}
The error is:
═══════ Exception caught by rendering library ═════════════════════════════════
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.
The relevant error-causing widget was
ListView
lib/widgets/home_body_screen.dart:64
When the exception was thrown, this was the stack
#0 RenderViewport.computeDryLayout.<anonymous closure>
package:flutter/…/rendering/viewport.dart:1369
#1 RenderViewport.computeDryLayout
package:flutter/…/rendering/viewport.dart:1430
#2 RenderBox.performResize
package:flutter/…/rendering/box.dart:2332
#3 RenderObject.layout
package:flutter/…/rendering/object.dart:1758
#4 RenderProxyBoxMixin.performLayout
package:flutter/…/rendering/proxy_box.dart:116
...
The following RenderObject was being processed when the exception was fired: RenderViewport#33c99 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderViewport#33c99 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
offset: ScrollPositionWithSingleContext#b9cb0(offset: 0.0, range: null..null, viewport: null, ScrollableState, AlwaysScrollableScrollPhysics -> ClampingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#03740, ScrollDirection.idle)
anchor: 0.0
center child: RenderSliverPadding#e0507 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: paintOffset=Offset(0.0, 0.0)
constraints: MISSING
geometry: null
padding: EdgeInsets.zero
textDirection: ltr
child: RenderSliverList#2982b NEEDS-LAYOUT NEEDS-PAINT
parentData: paintOffset=Offset(0.0, 0.0)
constraints: MISSING
geometry: null
no children current live
RenderBox was not laid out: RenderViewport#33c99 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1930 pos 12: 'hasSize'
The relevant error-causing widget was
ListView
lib/widgets/home_body_screen.dart:64
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderViewport#33c99 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1930 pos 12: 'hasSize'
The relevant error-causing widget was
ListView
lib/widgets/home_body_screen.dart:64
I'm a newest in flutter, i understand some things, but not all.
My opinion is: "this error is caused by her possition, yeah, its scrollable but he does not know where ends". Sorry if i wrong.
thanks all!
To use ListView inner SingleChildScrollView, you need to disable scrolling property of ListView.
ListView(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
primary: false,
children: []
)

flutter ListView returning 'hasSize' error

I am using list view to build my flutter list. the code:
#override
Widget build(BuildContext context) {
return Expanded(
child: Container(
color: kMainColor,
child: Stack(
fit: StackFit.expand,
children: [
ListView(
shrinkWrap: true,
controller: _scrollController,
children: [
Text("ff"),
Text("ff"),
Text("ff"),
],
),
]
)
)
);
}
}
but I get this error :
RenderBox was not laid out: RenderViewport#b8187 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1940 pos 12: 'hasSize'
I don't know what this error is and what is causing it. I tried to wrap the listView in Container and give it a height it also returned an error. what can I do to fix it?

Get an error `Failed assertion: line 1687 pos 12: 'hasSize'` when render ListTile inside `Row`

I have below code in flutter.
Widget build(BuildContext context) {
return Center(
child: Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
children: <Widget>[
SizedBox(
height: 100,
child: ListTile(
leading: IconButton(
iconSize: 30,
icon: roundImage(post.userPicture, Icon(Icons.person)),
onPressed: () {},
),
subtitle: Text(this.post.message),
)),
],
),
],
),
),
);
}
But I get this error:
════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderPhysicalShape#7713c relayoutBoundary=up3
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1687 pos 12: 'hasSize'
The relevant error-causing widget was
Card
I have added SizedBox in the Row but it still complains about hasSize error. How can I solve this issue?
It's not clear what you're trying to achieve, but instead of using SizedBox you can try wrapping inside Expanded or Flexible widgets.
I tried adding a width of 200 to your SizedBox and it worked.
Although using Expanded as suggested by #dhanasekar works well too.
Add Flexible
Row(
children: [
new Flexible(
child: new TextField(
decoration: const InputDecoration(helperText: "Enter App ID"),
style: Theme.of(context).textTheme.body1,
),
),
],
),
I was getting exactly this while trying to have a Column with one of its children being a ScopedModelDescendant.
I was going crazy with this same error.
A combination of reading this thread and educating myself on layout widgets gave me the solution:
I've wrapped the ScopedModelDescendant child in a Flexible widget, like this:
Column(
children: [
Flexible(child: ScopedModelDescendant<MyAPIProvider>(...)
...
And now it works.