Flutter - Fixed button next to horizontal scroll - flutter

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?

Related

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?

How to solve "RenderBox was not laid out:" in ListView.Builder widget in flutter?

I'm using ListView.Builder inside Expanded widget, but it's through exception
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
RenderBox was not laid out: RenderRepaintBoundary#508c1 NEEDS-LAYOUT NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1696 pos 12: 'hasSize'
ListView.builder widget named LogTimeline
Widget build(BuildContext context) {
return Expanded(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: timelineList.length,
itemBuilder: (context, index) {
return Container(
child: Row(
children: [
Column(
children: [
Container(),
Container(),
Container(),
],),
],),
),}
),),}
LogTimeline widget used in
Wrap(
children: [
LogHeader(
headerTitle: "Overtime log",
),
LogTimeline(
timelineList: overtimeList,
),
],
)
when ListView.builder used in a wrap widget, it shows "Bottom OverFlowed"
How can I solve this exception, why this exception occurs,
Full code link
Try removing the Expanded Widget and see

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.

flutter column widget receive null about height in runtime

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.

Flutter ListView crashes inside column

I need some help figuring out how I can render the ListView.
I have been following along a Flutter tutorial and I have had to stop because I can't get around this issue.
From what I can understand the ListView tries to take up an infinite amount of space which obviously crashes the app.
I have also come to understand the you can't have a ListView as a direct child of a Column/Row (I explain what I have tried to do about that below)
https://flutter.io/docs/development/ui/layout/box-constraints#flex
Here's the code:
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Container(
margin: EdgeInsets.all(10),
child: ProductControl(_addProduct),
),
ListView.builder(
itemCount: _products.length,
itemBuilder: (BuildContext context, int index) => Card(
child: Column(
children: <Widget>[
Image.asset('assets/food.jpg'),
Text(_products[index])
],
),
),
)
],
);
}
This is what is being said in the beginning of the stacktrace:
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performResize():
flutter: Vertical viewport was given unbounded height.
flutter: Viewports expand in the scrolling direction to fill their
container.In this case, a vertical
flutter: viewport was given an unlimited amount of vertical space in
which to expand. This situation
flutter: typically happens when a scrollable widget is nested inside
another scrollable widget.
flutter: If this widget is always nested in a scrollable widget there
is no need to use a viewport because
flutter: there will always be enough vertical space for the children.
In this case, consider using a Column
flutter: instead. Otherwise, consider using the "shrinkWrap" property
(or a ShrinkWrappingViewport) to size
flutter: the height of the viewport to the sum of the heights of its children.
And this is taken from the bottom of the stacktrace:
flutter: The following RenderObject was being processed when the
exception was fired:
flutter: RenderViewport#cab62 NEEDS-LAYOUT NEEDS-PAINT
flutter: creator: Viewport ← _ScrollableScope ← IgnorePointer-
[GlobalKey#b71f9] ← Semantics ← Listener ←
flutter: _GestureSemantics ← RawGestureDetector-
[LabeledGlobalKey<RawGestureDetectorState>#d0420] ←
flutter: _ScrollSemantics-[GlobalKey#02b55] ← Scrollable ←
PrimaryScrollController ← ListView ← Column ← ⋯
flutter: parentData: <none> (can use size)
flutter: constraints: BoxConstraints(0.0<=w<=375.0, 0.0<=h<=Infinity)
flutter: size: MISSING
flutter: axisDirection: down
flutter: crossAxisDirection: right
flutter: offset: ScrollPositionWithSingleContext#892dc(offset: 0.0,
range: null..null, viewport: null,
flutter: ScrollableState, AlwaysScrollableScrollPhysics ->
BouncingScrollPhysics, IdleScrollActivity#9455f,
flutter: ScrollDirection.idle)
flutter: anchor: 0.0
flutter: This RenderObject had the following descendants (showing up to
depth 5):
flutter: RenderSliverPadding#c8ab3 NEEDS-LAYOUT NEEDS-PAINT
flutter: RenderSliverList#66f1b NEEDS-LAYOUT NEEDS-PAINT
I have tried to wrap the ListView.builder in an Expanded widget but that doesn't work for me. (Which is what is being done in the tutorial)
I tried to wrap the Column in an IntrinsicHeight Widget with no success.
The only way I manage to get around this issue is by wrapping the ListView.builder in a Container widget with a set height property. But having to use a Container with a set height does not seem right to me.
I can try to post the full code to recreate this if needed.
try using 'Expanded' instead of Container or other layouts:
Column(
children: <Widget>[
Expanded(
//color: Colors.white,
child:
ListView.builder(
itemCount: list.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
contentPadding: EdgeInsets.all(10.0),
title: new Text('title'),
subtitle: new Text('sub title'),
onTap: () => clicked(list[index]['url']),
onLongPress: () => downloadAndStoreFile(list[index]['url'],
list[index]['name'], list[index]['title']),
);
}),
)
],
),
Add this to ListView.Builder =
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Container(
margin: EdgeInsets.all(10),
child: ProductControl(_addProduct),
),
ListView.builder(
physics: NeverScrollableScrollPhysics(), ///
shrinkWrap: true, ///
scrollDirection: Axis.vertical, ///
itemCount: _products.length,
itemBuilder: (BuildContext context, int index) => Card(
child: Column(
children: <Widget>[
Image.asset('assets/food.jpg'),
Text(_products[index])
],
),
),
)
],
);
}
I think I managed to solve this as a last minute effort right after posting the question.
Something I didn't show in my question was another piece of code.
Basically this is what my code looked like.
body: Column(
children: <Widget>[
Column(
children: <Widget>[
Container(
margin: EdgeInsets.all(10),
child: ProductControl(_addProduct),
),
ListView.builder(
itemCount: _products.length,
itemBuilder: (BuildContext context, int index) => Card(
child: Column(
children: <Widget>[
Image.asset('assets/food.jpg'),
Text(_products[index])
],
),
),
)
],
),
],
),
The issue was that I had a Column with a Column as a direct child and apparently ListView does not like that.. So by removing the first Column I could then wrap my ListView in an Expanded widget and everything works. Maybe this can help someone else.
Both Column and ListView expands their size to maximum => Error
3 Solutions:
Wrap ListView with Expanded or Flexible
Column(
children: <Widget>[
Expanded(
child: ListView(),
)
],
)
Limit ListView height with Container or SizedBox
Column(
children: <Widget>[
Container(
height: 200,
child: ListView(),
)
],
)
My favorite solution: just add shrinkWrap and NeverScrollableScrollPhysics()
Column(
children: <Widget>[
ListView(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
)
],
)