I have a UI where there is SingleChildScrollView
-> Column
-> Expanded
-> ChildOfExpanded
But I can't put a SingleChildScrollView as parent of Column because of the Expanded. I've tried multiple solutions, like the one on the docs but no one worked so far.
That's the code:
Column(
children: [
// Other widgets (Containers, Padding, ecc.)
Expanded(
child: TabBarView(
children: [
// Other widgets
],
),
)
],
),
I don't have a fixed height, so I can't replace the Expanded
with a SizedBox or something like that.
That's the error I'm getting:
The following assertion was thrown during performLayout(): RenderFlex
children have non-zero flex but incoming height constraints are
unbounded.
When a column is in a parent that does not provide a finite height
constraint, for example if it is in a vertical scrollable, it will try
to shrink-wrap its children along the vertical 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 vertical 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#7d8dc relayoutBoundary=up12
NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I've tried with a Flexible as said in the error, but then I get this:
Horizontal viewport was given unbounded height. The relevant error-causing widget was
TabBarView lib/…/screens/specific_launch.dart:193 ════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library
═════════════════════════════════ RenderBox was not laid out:
RenderViewport#57f46 NEEDS-LAYOUT NEEDS-PAINT
NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart': Failed assertion: line 1940
pos 12: 'hasSize' The relevant error-causing widget was
TabBarView lib/…/screens/specific_launch.dart:193
In this UI is fundamental to have a dynamic height, so a ScrollView cannot be avoided
question from:
https://stackoverflow.com/questions/65870149/flutter-singlechildscrollview-column-and-expanded