ListView(
children: [
new SizedBox(
height: 100.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
new Text("hi"),
new Text("hi"),
new Text("hi"),
],
),
),
],
)
I used the Sized Box and seems still got the error.
This is my widget tree:
SingleChildScrollView -> Column -> children
Performing hot reload... 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. flutter: flutter: When the exception was thrown, this was the stack: flutter: #0 RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:944:15) flutter:
#1 RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:997:6) flutter: #2 RenderObject.layout (package:flutter/src/rendering/object.dart:1555:9) flutter: #3
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #4 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #5
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #6 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #7
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #8 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #9
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #10 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #11
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #12 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #13 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15) flutter: #14 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #15 RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:199:11) flutter: #16 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #17 _RenderSingleChildViewport.performLayout (package:flutter/src/widgets/single_child_scroll_view.dart:479:13) flutter: #18 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #19
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #20 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #21
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #22 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #23
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #24 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #25
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #26 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #27
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #28 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #29 RenderPositionedBox.performLayout (package:flutter/src/rendering/shifted_box.dart:381:13) flutter: #30 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #31 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:141:11) flutter: #32
_ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:399:7) flutter: #33 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:211:7) flutter: #34 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:355:14) flutter: #35 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #36
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #37 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #38
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #39
_RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1143:11) flutter: #40 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #41
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #42 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #43
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #44 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #45
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #46 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #47 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:520:15) flutter: #48 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #49
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #50 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #51
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #52 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #53
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #54 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #55
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #56 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #57
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #58 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #59
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #60 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:2809:13) flutter: #61 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #62 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:520:15) flutter: #63 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #64
__RenderTheatre&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #65 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #66
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #67 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #68
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #69 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #70
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #71 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #72
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #73 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #74
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13) flutter: #75 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7) flutter: #76 RenderView.performLayout (package:flutter/src/rendering/view.dart:125:13) flutter: #77 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1445:7) flutter: #78 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:709:18) flutter: #79
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:270:19) flutter: #80
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:627:13) flutter: #81
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5) flutter: #82
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15) flutter: #83
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9) flutter: #84
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:751:7) flutter:
#86 _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19) flutter: #87
_Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5) flutter: #88 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12) flutter: (elided one frame from package dart:async) flutter: flutter: The following RenderObject was being processed when the exception was fired: flutter: RenderViewport#c5015 NEEDS-LAYOUT NEEDS-PAINT flutter: creator: Viewport ← _ScrollableScope ← IgnorePointer-[GlobalKey#58446] ← Semantics ← Listener ← flutter: _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#efcf9] ← flutter: _ExcludableScrollSemantics-[GlobalKey#1ff3b] ← Scrollable ← ListView ← Column ← Padding ← ⋯ flutter: parentData: <none> (can use size) flutter: constraints: BoxConstraints(0.0<=w<=335.0,
0.0<=h<=Infinity) flutter: size: MISSING flutter: axisDirection: down flutter: crossAxisDirection: right flutter: offset: ScrollPositionWithSingleContext#05c53(offset: 0.0, range: null..null, viewport: null, flutter: ScrollableState, AlwaysScrollableScrollPhysics -> BouncingScrollPhysics, IdleScrollActivity#31dab, flutter: ScrollDirection.idle) flutter: anchor: 0.0 flutter: This RenderObject had the following descendants (showing up to depth 5): flutter: RenderSliverPadding#912f7 NEEDS-LAYOUT NEEDS-PAINT flutter: RenderSliverList#41182 NEEDS-LAYOUT NEEDS-PAINT flutter: RenderRepaintBoundary#8a6de NEEDS-LAYOUT NEEDS-PAINT flutter: RenderConstrainedBox#4bfc3 NEEDS-LAYOUT NEEDS-PAINT flutter:
_RenderExcludableScrollSemantics#0976e NEEDS-LAYOUT NEEDS-PAINT flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════ flutter: Another exception was thrown: RenderBox was not laid out: RenderViewport#c5015 NEEDS-LAYOUT NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderViewport#c5015 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#a987c relayoutBoundary=up14 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#9bd09 relayoutBoundary=up13 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderPointerListener#12af7 relayoutBoundary=up12 NEEDS-PAINT Reloaded 1 of 493 libraries in 603ms. flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#27e1a relayoutBoundary=up11 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out:
_RenderExcludableScrollSemantics#85fc5 relayoutBoundary=up10 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderFlex#19bee relayoutBoundary=up9 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderPadding#e802a relayoutBoundary=up8 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out:
_RenderSingleChildViewport#5d1aa relayoutBoundary=up7 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#f73b8 relayoutBoundary=up6 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#610b2 relayoutBoundary=up5 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderPointerListener#cbdf9 relayoutBoundary=up4 NEEDS-PAINT flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#37577 relayoutBoundary=up3 NEEDS-PAINT flutter: Another exception was thrown: 'package:flutter/src/rendering/shifted_box.dart': Failed assertion: line 310 pos 12: 'child.hasSize': is not true. flutter: Another exception was thrown: RenderBox was not laid out:
_RenderSingleChildViewport#5d1aa relayoutBoundary=up7 NEEDS-P
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.4.4, on Mac OS X 10.13.1 17B1003, locale en-HK)
[✓] Android toolchain - develop for Android devices (Android SDK 26.0.2)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
[✓] Android Studio (version 3.1)
[✓] Connected devices (3 available)
Try this code,
You can implement scrollable row in flutter using below code
and for scrollable column just change Column with Row
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
Text('hi'),
Text('hi'),
Text('hi'),
]
)
)
Edit : The keyword new is optional in Dart 2
see the output here
You can use Expanded widget to wrap your listView.
Expanded widget tells the screen to allow as much as space the widget wants to take.
Or you can also write shrinkWrap:true in your ListView widget (works in a lot of cases).
try to set the following properties of your ListView
shrinkWrap: true,
physics: ClampingScrollPhysics(),
for me, most of the Unbound constraints and scrolling errors were solved.
A horizontal ListView will expand vertically to occupy the height of its parent. It happens to be that in this case the parent is a vertical ListView, which has infinite height. You need to constrain the height of your inner ListView.
Probably the simplest way to do that is through a SizedBox widget.
ListView(
children: [
SizedBox(
height: 300.0,
child: ListView(scrollDirection: Axis.horizontal, ...),
),
],
)
EDIT:
The problem is actually caused by the vertical ListView, because it is the child of a Column. The reason is similar as above, a ListView will expand to be the height of its parent and a Column has unbounded height.
This snippet displays the symptom.
Column(
children: <Widget>[
ListView(children: [Text("hi"), Text("hi"), Text("hi")]),
],
)
The solution in this case depends on your setup. You could wrap it around a SizedBox again. You could make the column items part of your ListView. Or you could also change the ListView for a Column.
Wrap the 'ListView' with an 'Expanded' widget.
new Expanded (
child: new ListView (
.....
)
)
You'll need to wrap your horizontal ListView inside SizedBox widget. Have a look at this sample code:
new SizedBox(
height: 72.0,
child: new ListView(
padding: const EdgeInsets.symmetric(vertical: 4.0),
children: listViewItems,
scrollDirection: Axis.horizontal,
),
),
So you can also do this:
Container(
height: 100.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
new Text("hi"),
new Text("hi"),
new Text("hi"),
]
),
),
by wrapping your ListView in a Container Widget
You can try this one as well for horizontal and vertical scrolling.
return Scaffold(
body: ListView.builder(
scrollDirection: Axis.vertical,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 200,
margin: EdgeInsets.all(20),
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 20,
itemBuilder: (BuildContext context, int index) {
return Container(
color: Colors.grey,
width: 100,
height: 100,
margin: EdgeInsets.all(20),
);
},
),
);
},
),
);
The reason is you cant use a Listview inside a Listview in flutter so you have to make one of them to either column or row as per requirement .
new Listview(
children: <Widget>[
new SizedBox(
height:100.0,
child: new Row(
children: <Widget>[
new Text("hi"),
new Text("hi"),
new Text("hi"),
]
)
)
]
)
This would satisfy your requirement according to me .
This might seem like a lazy answer but have you tried doing a $ flutter clean?
When I run this using the standard boilerplate given when you open a new flutter project it runs just fine, using the same code that gave you issues.
I know this is an older question but hopefully someone finds this useful.
This is what I used;
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body:
_listView(),
);
}
ListView _listView() {
return new ListView(
children: [
new SizedBox(
height: 100.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
new Text("hi"),
new Text("hi"),
new Text("hi"),
],
),
),
],
);
}
}
And this is what I got;
Related
I have an app that displays a snackbar when some action is done. I had tested this with my phone and some emulator and it works. Recently I installed an emulator with android 13 and maybe a bigger resolution and I'm getting this error:
The following assertion was thrown during performLayout():
Floating SnackBar presented off screen.
A SnackBar with behavior property set to SnackBarBehavior.floating is fully or partially off screen because some or all the widgets provided to Scaffold.floatingActionButton, Scaffold.persistentFooterButtons and Scaffold.bottomNavigationBar take up too much vertical space.
Consider constraining the size of these widgets to allow room for the SnackBar to be visible.
The relevant error-causing widget was
Scaffold
dashboard.dart:69
When the exception was thrown, this was the stack
#0 _ScaffoldLayout.performLayout.<anonymous closure>
#0 _ScaffoldLayout.performLayout.<anonymous closure>
scaffold.dart:1189
#1 _ScaffoldLayout.performLayout
scaffold.dart:1204
#2 MultiChildLayoutDelegate._callPerformLayout
custom_layout.dart:240
#3 RenderCustomMultiChildLayoutBox.performLayout
custom_layout.dart:410
#4 RenderObject._layoutWithoutResize
object.dart:2027
#5 PipelineOwner.flushLayout
object.dart:1020
#6 RendererBinding.drawFrame
binding.dart:516
#7 WidgetsBinding.drawFrame
binding.dart:865
#8 RendererBinding._handlePersistentFrameCallback
binding.dart:381
#9 SchedulerBinding._invokeFrameCallback
binding.dart:1289
#10 SchedulerBinding.handleDrawFrame
binding.dart:1218
#11 SchedulerBinding._handleDrawFrame
binding.dart:1076
#12 _invoke (dart:ui/hooks.dart:145:13)
#13 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:338:5)
#14 _drawFrame (dart:ui/hooks.dart:112:31)
The following RenderObject was being processed when the exception was fired: RenderCustomMultiChildLayoutBox#3f6d8 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderCustomMultiChildLayoutBox#3f6d8 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
needs compositing
parentData: <none> (can use size)
constraints: BoxConstraints(w=411.4, h=867.4)
size: Size(411.4, 867.4)
child 1: RenderRepaintBoundary#ba78b relayoutBoundary=up1
needs compositing
I have no idea how can I debug what is going on here. The code works in smaller devices/older versions of android. The popups are triggered quiet straightforward:
SnackBar getSnackbar({
required String message,
required Color backgroundColor,
}) {
return SnackBar(
elevation: 8,
backgroundColor: backgroundColor,
behavior: SnackBarBehavior.floating,
content: Row(children: [
Flexible(
child: Text(
message,
style: const TextStyle(
color: Colors.white,
),
),
)
]),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
);
}
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(getSnackbar(
backgroundColor: Colors.green,
message: 'File saved to $filename',
));
The screen where this is called does not have any Scaffold.floatingActionButton, Scaffold.persistentFooterButtons and Scaffold.bottomNavigationBar as the exception says. It is just a Scaffold with a body:
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('SomeScreen'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: _isLoading
? const Center(child: CircularProgressIndicator())
: Column(children: [
_displaySomething(),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
_displayAnotherThing(),
],
))
]),
),
);
}
Update: I have futher debugged the issue and it also happens in older versions of android. So it may be related to a recent update of flutter but I'm not able to find why.
I was able to see the problem appears only with behavior:SnackBarBehavior.floating,.
Also removing all the code from the Scaffolfd, leaving just the TextButton that triggers the snackbar is enough to reproduce the issue, but I don't know what can I do with it.
I faced this problem too. This problem arises due to the fact that your column takes up all the available space, you need to limit it somehow to give room for a snackbar
I cross posted this here, because I though it was a bug. But there it was explained that for the SnackBars you have to also consider other Scaffolds in the widget tree as moving backwards would keep the snackbar "flying" and could collide with elements of the previous Scaffolds.
So as a summary on how to solve this issue, take a look not only in the screen where you see the exception triggered but also from previous screens.
I want to add Column widget to Row widget.
I have a data structure as follows:
Scaffold
- Padding
- SingleChildScrollView
- Column
- Row
- CircleAvatar
- Column (The Column I am talking about below)
- Text
- Row
- Expanded
- MaterialButton
- Expanded
- Container
- Expanded
- MaterialButton
- ListTile
When adding a Column to a Row, I get an error:
════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during performLayout():
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.
These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child cannot simultaneously expand to fit its parent.
Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible children (using Flexible rather than Expanded). This will allow the flexible children to size themselves to less than the infinite remaining space they would otherwise be forced to take, and then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum constraints provided by the parent.
If this message did not help you determine the problem, consider using debugDumpRenderTree():
https://flutter.dev/debugging/#rendering-layer
http://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html
The affected RenderFlex is: RenderFlex#acbae relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
constraints: BoxConstraints(unconstrained)
size: MISSING
direction: horizontal
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: center
textDirection: ltr
verticalDirection: down
child 1: RenderConstrainedBox#404ec NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=3; fit=FlexFit.tight
constraints: MISSING
size: MISSING
additionalConstraints: BoxConstraints(w=180.0, h=50.0)
child: RenderSemanticsAnnotations#4f838 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none>
constraints: MISSING
semantic boundary
size: MISSING
child: _RenderInputPadding#04251 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none>
constraints: MISSING
size: MISSING
child: RenderConstrainedBox#3337d NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0)
constraints: MISSING
size: MISSING
additionalConstraints: BoxConstraints(88.0<=w<=Infinity, 36.0<=h<=Infinity)
child 2: RenderLimitedBox#593aa NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
constraints: MISSING
size: MISSING
maxWidth: 0.0
maxHeight: 0.0
child: RenderConstrainedBox#d1172 NEEDS-LAYOUT NEEDS-PAINT
parentData: <none>
constraints: MISSING
size: MISSING
additionalConstraints: BoxConstraints(biggest)
child 3: RenderConstrainedBox#42764 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=3; fit=FlexFit.tight
constraints: MISSING
size: MISSING
additionalConstraints: BoxConstraints(w=180.0, h=50.0)
child: RenderSemanticsAnnotations#7ec96 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none>
constraints: MISSING
semantic boundary
size: MISSING
child: _RenderInputPadding#6aa1f NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none>
constraints: MISSING
size: MISSING
child: RenderConstrainedBox#e1f60 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0)
constraints: MISSING
size: MISSING
additionalConstraints: BoxConstraints(88.0<=w<=Infinity, 36.0<=h<=Infinity)
The creator information is set to: Row ← Column ← Row ← Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#10aed] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#23575] ← Listener ← _ScrollableScope ← ⋯
The nearest ancestor providing an unbounded width constraint is: RenderFlex#ede32 relayoutBoundary=up13 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
See also: https://flutter.dev/layout/
If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was
Row
When the exception was thrown, this was the stack
#0 RenderFlex.performLayout.<anonymous closure>
#1 RenderFlex.performLayout
#2 RenderObject.layout
#3 RenderBox.layout
#4 ChildLayoutHelper.layoutChild
#5 RenderFlex._computeSizes
#6 RenderFlex.performLayout
#7 RenderObject.layout
#8 RenderBox.layout
#9 ChildLayoutHelper.layoutChild
#10 RenderFlex._computeSizes
#11 RenderFlex.performLayout
#12 RenderObject.layout
#13 RenderBox.layout
#14 ChildLayoutHelper.layoutChild
#15 RenderFlex._computeSizes
#16 RenderFlex.performLayout
#17 RenderObject.layout
#18 RenderBox.layout
#19 _RenderSingleChildViewport.performLayout
#20 RenderObject.layout
#21 RenderBox.layout
#22 RenderProxyBoxMixin.performLayout
#23 RenderObject.layout
#24 RenderBox.layout
#25 RenderProxyBoxMixin.performLayout
#26 RenderObject.layout
#27 RenderBox.layout
#28 RenderProxyBoxMixin.performLayout
#29 RenderObject.layout
#30 RenderBox.layout
#31 RenderProxyBoxMixin.performLayout
#32 RenderObject.layout
#33 RenderBox.layout
#34 RenderProxyBoxMixin.performLayout
#35 RenderObject.layout
#36 RenderBox.layout
#37 RenderProxyBoxMixin.performLayout
#38 RenderObject.layout
#39 RenderBox.layout
#40 RenderProxyBoxMixin.performLayout
#41 RenderObject.layout
#42 RenderBox.layout
#43 RenderProxyBoxMixin.performLayout
#44 RenderCustomPaint.performLayout
#45 RenderObject.layout
#46 RenderBox.layout
#47 RenderProxyBoxMixin.performLayout
#48 RenderObject.layout
#49 RenderBox.layout
#50 RenderPadding.performLayout
#51 RenderObject.layout
#52 RenderBox.layout
#53 MultiChildLayoutDelegate.layoutChild
#54 _ScaffoldLayout.performLayout
#55 MultiChildLayoutDelegate._callPerformLayout
#56 RenderCustomMultiChildLayoutBox.performLayout
#57 RenderObject._layoutWithoutResize
#58 PipelineOwner.flushLayout
#59 RendererBinding.drawFrame
#60 WidgetsBinding.drawFrame
#61 RendererBinding._handlePersistentFrameCallback
#62 SchedulerBinding._invokeFrameCallback
#63 SchedulerBinding.handleDrawFrame
#64 SchedulerBinding._handleDrawFrame
#68 _invoke (dart:ui/hooks.dart:150:10)
#69 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318:5)
#70 _drawFrame (dart:ui/hooks.dart:115:31)
(elided 3 frames from dart:async)
The following RenderObject was being processed when the exception was fired: RenderFlex#acbae relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderFlex#acbae relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
constraints: BoxConstraints(unconstrained)
size: MISSING
direction: horizontal
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: center
textDirection: ltr
verticalDirection: down
child 1: RenderConstrainedBox#404ec NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=3; fit=FlexFit.tight
constraints: MISSING
size: MISSING
additionalConstraints: BoxConstraints(w=180.0, h=50.0)
child: RenderSemanticsAnnotations#4f838 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none>
constraints: MISSING
semantic boundary
size: MISSING
child: _RenderInputPadding#04251 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none>
constraints: MISSING
size: MISSING
child: RenderConstrainedBox#3337d NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0)
constraints: MISSING
size: MISSING
additionalConstraints: BoxConstraints(88.0<=w<=Infinity, 36.0<=h<=Infinity)
child 2: RenderLimitedBox#593aa NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
constraints: MISSING
size: MISSING
maxWidth: 0.0
maxHeight: 0.0
child: RenderConstrainedBox#d1172 NEEDS-LAYOUT NEEDS-PAINT
parentData: <none>
constraints: MISSING
size: MISSING
additionalConstraints: BoxConstraints(biggest)
child 3: RenderConstrainedBox#42764 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=3; fit=FlexFit.tight
constraints: MISSING
size: MISSING
additionalConstraints: BoxConstraints(w=180.0, h=50.0)
child: RenderSemanticsAnnotations#7ec96 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none>
constraints: MISSING
semantic boundary
size: MISSING
child: _RenderInputPadding#6aa1f NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none>
constraints: MISSING
size: MISSING
child: RenderConstrainedBox#e1f60 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0)
constraints: MISSING
size: MISSING
additionalConstraints: BoxConstraints(88.0<=w<=Infinity, 36.0<=h<=Infinity)
════════════════════════════════════════════════════════════════════════════════
…
My code:
Row(
children: [
CircleAvatar(
backgroundImage: NetworkImage(userAvatarUrl),
),
Column(
children: [
Text(userName),
Row(
children: …,
),
],
),
],
),
Feel free to leave a comment if you need more information.
How to add Column widget to Row widget? I would appreciate any help. Thank you in advance!
If the children inside the Row inside the Column can be Expanded, then consider wrapping the Column in an Expanded like so:
Row(
children: [
CircleAvatar(
backgroundImage: NetworkImage(userAvatarUrl),
),
Expanded(
child: Column(
children: [
Text(userName),
Row(
children: …,
),
],
),
)
],
),
import 'package:flutter/material.dart';
void main() {
runApp(StackApp());
}
Simple Class Stack I am trying to use the stack to overlay rectangles one above the other
class StackApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
Container(
width: 100,
height: 100,
color: Colors.red,
),
Container(
width: 90,
height: 90,
color: Colors.green,
),
Container(
width: 80,
height: 80,
color: Colors.blue,
),
],
);
}
}
I am getting this error message
I/flutter ( 8912): (elided 10 frames from class _AssertionError, package dart:async, and package dart:async-patch)
I/flutter ( 8912):
I/flutter ( 8912): The following RenderObject was being processed when the exception was fired:
RenderStack#322e9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
I/flutter ( 8912): creator: Stack ← StackApp ← [root]
I/flutter ( 8912): parentData:
I/flutter ( 8912): constraints: BoxConstraints(w=411.4, h=866.3)
I/flutter ( 8912): size: MISSING
I/flutter ( 8912): alignment: AlignmentDirectional.topStart
I/flutter ( 8912): textDirection: null
I/flutter ( 8912): fit: loose
I/flutter ( 8912): overflow: clip
I/flutter ( 8912): This RenderObject had the following descendants (showing up to depth 5):
I/flutter ( 8912): child 1: RenderConstrainedBox#49f71 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 8912): child: RenderDecoratedBox#2c55a NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 8912): child 2: RenderConstrainedBox#c71ea NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 8912): child: RenderDecoratedBox#4ad6c NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 8912): child 3: RenderConstrainedBox#5304a NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 8912): child: RenderDecoratedBox#9516e NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 8912):
════════════════════════════════════════════════════════════════════════════════════════════════════
You need to wrap your app in a MaterialApp, CupertinoApp or WidgetsApp. This is almost mandatory. But if you don't want to use one of these for some reason, then set alignment in your Stack like alignment: Alignment.topLeft to fix this.
I have the following Table inside Card. Since I added the padding widget, I get the following error:
I/flutter (19671): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (19671): The following assertion was thrown during performLayout():
I/flutter (19671): 'package:flutter/src/rendering/table.dart': Failed assertion: line 882 pos 16: 'tableWidth >=
I/flutter (19671): targetWidth': is not true.
I/flutter (19671):
I/flutter (19671): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (19671): more information in this error message to help you determine and fix the underlying cause.
I/flutter (19671): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (19671): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (19671):
I/flutter (19671): When the exception was thrown, this was the stack:
I/flutter (19671): #2 RenderTable._computeColumnWidths (package:flutter/src/rendering/table.dart:882:16)
I/flutter (19671): #3 RenderTable.performLayout (package:flutter/src/rendering/table.dart:1000:33)
code:
body: Container(
padding: EdgeInsets.all(5.0), margin: EdgeInsets.all(10.0),
child: Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Table(
children: list)
])
)
)
Why adding the padding widget throws this error?
How I can add padding and margin for my Card?
Because of 2 it won't account for growth in the container based on the padding, it will pad inward causing the inners to overflow. Just use the provided properties from Container.
Container has a padding and margin property which can be applied. You don't nee to wrap your Containers child with padding.
Container(
child: Text(),
padding: EdgeInsets.all(5.0),
margin: EdgeInsets.all(10.0)
)
See Container-class for more properties that can be used
The code below works without using Row widget but it gives an error on using a nested list View with Row how can I use a Row if that's my Use Case in the above code I have one row inside which there are two columns
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("Dashboard"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.add_circle),
iconSize: 50.0,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => AddMember(),
),
);
},
),
],
),
drawer: MainDrawer(),
body: Container(
decoration: BoxDecoration(
image: Background().buildBackgroundImage(),
),
child: ListView(
children: <Widget>[
Row(
children: <Widget>[
Column(
children: <Widget>[
Text("1"),
],
),
Column(
children: <Widget>[
Text("Hammad"),
ListView.builder(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return Text("data");
},
itemCount: 100,
),
],
),
],
)
],
),
),
);
} }
The code gives the following error?
I/flutter ( 6704): RenderShrinkWrappingViewport#9e1c7 relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 6704): creator: ShrinkWrappingViewport ← _ScrollableScope ← IgnorePointer-[GlobalKey#aa619] ← Semantics ←
I/flutter ( 6704): Listener ← _GestureSemantics ←
I/flutter ( 6704): RawGestureDetector-[LabeledGlobalKey#dbe17] ←
I/flutter ( 6704): _ScrollSemantics-[GlobalKey#17359] ← RepaintBoundary ← CustomPaint ← RepaintBoundary ←
I/flutter ( 6704): NotificationListener ← ⋯
I/flutter ( 6704): parentData: (can use size)
I/flutter ( 6704): constraints: BoxConstraints(unconstrained)
I/flutter ( 6704): size: MISSING
I/flutter ( 6704): axisDirection: down
I/flutter ( 6704): crossAxisDirection: right
I/flutter ( 6704): offset: ScrollPositionWithSingleContext#d8d3b(offset: 0.0, range: null..null, viewport: null,
I/flutter ( 6704): ScrollableState, ClampingScrollPhysics -> ClampingScrollPhysics, IdleScrollActivity#ce116,
I/flutter ( 6704): ScrollDirection.idle)
I/flutter ( 6704): This RenderObject had the following descendants (showing up to depth 5):
I/flutter ( 6704): RenderSliverPadding#a684d NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 6704): RenderSliverList#59143 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 6704): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: RenderShrinkWrappingViewport#9e1c7 relayoutBoundary=up14 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#0105f relayoutBoundary=up13 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#cdf64 relayoutBoundary=up12 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#8301a relayoutBoundary=up11 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#89bf4 relayoutBoundary=up10 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#6bd35 relayoutBoundary=up9 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#417b1 relayoutBoundary=up8 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#97f18 relayoutBoundary=up7 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#df728 relayoutBoundary=up6 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: RenderFlex#44487 relayoutBoundary=up5 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: RenderBox was not laid out: RenderFlex#99d5f relayoutBoundary=up4 NEEDS-PAINT
I/flutter ( 6704): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 443 pos 12: 'child.hasSize': is not true.
I/flutter ( 6704): Another exception was thrown: NoSuchMethodError: The getter 'scrollOffsetCorrection' was called on null.
I/flutter ( 6704): Another exception was thrown: NoSuchMethodError: The method 'debugAssertIsValid' was called on null.
I/flutter ( 6704): Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.
Wrap your Columns with Flexible Widget.
Flexible(
child: Column(
children: <Widget>[
Keep in mind, whenever you are working with either Row widget or Column widget, you have to give definite sizes (less than the total available space) to all other widgets, but if you are not sure about the sizes, then give definite sizes to all the widgets, which needs minimum size to look fine, and for the other widgets use Expanded widget.
Look at this code for idea
Row(
children: <Widget>[
Expanded(
//Widget that is long and can cause overflow
child: LongWidget(),
),
//Give definite Size to this widget
FixedSizedWidget()
],
),