In Flutter, How to define a tabbarview's height dynamically? - flutter

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??

Related

ListView and Expanded not work in flutter

I need help to solve this problem. The expanded renders the child but does not expand.
return Scaffold(
body: ListView(
children: [
_HomeBody(child: child,)
],
)
);
_HomeBody
return Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height
child: Column(
children: [
AppBarMenu(),
Expanded(child: child), // A RenderFlex overflowed by 1246 pixels on the bottom.
Footer()
],
),
);
Error Output
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 1246 pixels on the bottom.
The relevant error-causing widget was:
Column
lib\…\views\home_view.dart:19
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#90f9f OVERFLOWING:
needs compositing
creator: Column ← ConstrainedBox ← Container ← HomeView ← Builder ←
RepaintBoundary-[GlobalKey#97a2c] ← IgnorePointer ← AnimatedBuilder ← FractionalTranslation ←
SlideTransition ← AnimatedBuilder ← RepaintBoundary ← ⋯
parentData: <none> (can use size)
constraints: BoxConstraints(w=966.0, h=840.0)
size: Size(966.0, 840.0)
direction: vertical
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: start
textDirection: ltr
verticalDirection: down
HomeLayout code
child code
You can't have Expanded inside of a scrolling view (SignleChildScrollView, ListView, etc..)
cause like this you are telling the child of the expanded to take of the whole vertical space allowed to you, and the scroll view can allow infinite vertical space, so in a nutshell, you are telling the child of the Expanded take the size of infinity. hope this clarifies the error

RenderBox was not laid out flutter listview

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,

RenderFlex error in flutter after a stateful widget is called inside a singlechildscrollview column

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.

Flutter/Dart - A RenderFlex overflowed by 99804 pixels on the bottom

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

Flutter drawer test errors with "A RenderFlex overflowed by 188 pixels on the right."

I am writing some tests for my app. Currently I am stuck on testing the drawer. On emulators of various sizes it runs without a problem (from 240x432 to 1440x2960) but when I try to run a simple test the following error is thrown:
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 188 pixels on the right.
The overflowing RenderFlex has an orientation of Axis.horizontal.
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#1ae2c relayoutBoundary=up17 OVERFLOWING:
creator: Row ← Center ← Padding ← Container ← IconTheme ← Builder ← Listener ← _GestureSemantics ←
RawGestureDetector ← GestureDetector ← Listener ← InkWell ← ⋯
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(0.0<=w<=256.0, 0.0<=h<=Infinity)
size: Size(256.0, 24.0)
direction: horizontal
mainAxisAlignment: start
mainAxisSize: min
crossAxisAlignment: center
textDirection: ltr
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════
Within the code I have narrowed it down to some RaisedButtons. When the Row within is below a certain length, the error doesn't show.
When I comment out the following code, ALL tests run without an issue.
Padding(
padding: EdgeInsets.symmetric(vertical: 32, horizontal: 16),
child: Column(
children: [
FacebookSignInButton(
onPressed: _fbLogin,
),
GoogleSignInButton(
onPressed: _googleLogin,
)
],
crossAxisAlignment: CrossAxisAlignment.stretch,
))
Changing the text within ("Continue with Facebook", "Sign in with Google") to something shorter also fixes this.
The test (note I'm currently just trying to not error, asserts will be put in once I get this figured out)
testWidgets("Drawer",
(WidgetTester tester) async {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
BuildContext savedContext;
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (BuildContext context) {
savedContext = context;
return Scaffold(
key: _scaffoldKey,
drawer: HomePageDrawer(),
body: Container(),
);
},
),
),
);
await tester.pump(); // no effect
_scaffoldKey.currentState.openDrawer();
await tester.pump();
});