TabBarView expanded inside a column error - flutter

I am getting this error from the TabBarView.
When I use a container with a specific height there are no errors.
but I don't want to set a specific height
I want it to take the rest of the column. So I tried using expanded and flexible but I am getting this error.
i really need to use TabBarView I can't use any other options.
Can any body help plz
Exception has occurred.
FlutterError (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#c8da4 relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE(creator: Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a14ea] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#45e38] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#ecd8b] ← NotificationListener<ScrollMetricsNotification> ← RepaintBoundary ← ⋯, parentData: <none> (can use size), constraints: BoxConstraints(0.0<=w<=363.4, 0.0<=h<=Infinity), size: MISSING, direction: vertical, mainAxisAlignment: start, mainAxisSize: min, crossAxisAlignment: center, verticalDirection: down)
The creator information is set to:
Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a14ea] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#45e38] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#ecd8b] ← NotificationListener<ScrollMetricsNotification> ← RepaintBoundary ← ⋯
The nearest ancestor providing an unbounded width constraint is: _RenderSingleChildViewport#b15e8 relayoutBoundary=up13 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
needs compositing
creator: _SingleChildViewport ← IgnorePointer-[GlobalKey#a14ea] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#45e38] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#ecd8b] ← NotificationListener<ScrollMetricsNotification> ← RepaintBoundary ← CustomPaint ← ⋯
parentData: <none> (can use size)
constraints: BoxConstraints(0.0<=w<=363.4, h=636.6)
size: MISSING
offset: Offset(0.0, -0.0)
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)
import 'package:flutter/material.dart';
import 'package:news_app/helper/enum.dart';
import 'package:news_app/screens/home/home_top_bar.dart';
import 'package:news_app/screens/home/latest_widget.dart';
import 'package:news_app/screens/home/news_tile.dart';
import 'package:news_app/screens/home/see_all_widget.dart';
import 'package:news_app/screens/home/trending_widget.dart';
import 'package:news_app/widgets/text_fields/search_field.dart';
class HomeSection extends StatefulWidget {
const HomeSection({super.key});
#override
State<HomeSection> createState() => _HomeSectionState();
}
class _HomeSectionState extends State<HomeSection>
with TickerProviderStateMixin {
TextEditingController search = TextEditingController();
#override
Widget build(BuildContext context) {
final TabController tabController = TabController(
length: 2,
initialIndex: 1,
vsync: this,
);
return Column(
children: [
const HomeTopBar(),
SearchField(
controller: search,
onChanged: (value) {},
prefixIcon: Icon(
Icons.search,
size: 30,
color: Theme.of(context).secondaryHeaderColor,
),
suffixIcons: Image.asset(
'assets/icons/slider_menu.png',
color: Theme.of(context).secondaryHeaderColor,
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.0101,
),
Expanded(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SeeAllBar(heading: "Trending"),
TrendingWidget(
newsCategory: "Europe",
title: "Russian warship: Moskva sinks in Black Sea",
publishedTime: "4h ago",
image: Image.asset('assets/temp/trending1.png'),
publisher: "BBC",
publisherLogo: Image.asset('assets/temp/bbc.png'),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.0101,
),
const SeeAllBar(heading: "Latest"),
TabBar(
controller: tabController,
isScrollable: true,
tabs: const [
Text("All"),
Text("Politics"),
],
),
Expanded(
child: TabBarView(
controller: tabController,
children: const [
Text("All"),
Text("Politics"),
],
),
),
],
),
),
),
],
);
}
}

If you need scrolling only for TabBarView - wrap main Column with fixed height container. Then you can use Expanded inside without SingleChildScrollView.
return Container(
color: Colors.redAccent,
height: MediaQuery.of(context).size.height, //<<< your device height
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: _topHeight,
width: double.infinity,
color: Colors.orange,
child: Center(child: Text('TopBar')),
),
Container(
height: _searchHeight,
width: double.infinity,
color: Colors.yellowAccent,
child: Center(child: Text('Search Field')),
),
SizedBox(
height: _sizeBoxHeight,
),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Trending Bar"),
Container(
height: 210,
width: double.infinity,
color: Colors.blueAccent,
child: Center(child: Text('Trending widget')),
),
SizedBox(
height: _sizeBoxHeight,
),
const Text("Latest"),
TabBar(
controller: tabController,
isScrollable: true,
tabs: const [
Text("All"),
Text("Politics"),
],
),
Expanded(
child: TabBarView(
controller: tabController,
children: [
ListView.builder(itemBuilder: (context, index) {
return Text ('All $index');
}, itemCount: 100,),
ListView.builder(itemBuilder: (context, index) {
return Text ('Politics $index');
}, itemCount: 100,),
],
),
),
],
),
),
],
),
);

Related

Flutter Web SingleChildScrollView Incorrect use of ParentDataWidget

This is how my code looks like, and to make it work correctly in web i have to do one part scrollable because of adapty.
Scaffold(
body: Row(
children: [
Column(
children: [
Expanded(
child: Container(
width: 200,
color: Colors.blue,
),
)
],
),
Expanded(
child: Column(
children: [
Row(
children: [
Expanded(
child: Container(
height: 108,
color: AppColors.bg.secondary,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Padding(
padding: EdgeInsets.only(left: 40),
child: Text(
'Contacts',
style: TextStyle(
fontSize: 40,
color: Colors.black,
),
),
),
Padding(
padding: const EdgeInsets.only(right: 40),
child: InkWell(
onTap: () {},
child: Container(
decoration: BoxDecoration(borderRadius: BorderRadius.circular(20), color: AppColors.bg.fields),
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 77, vertical: 8),
child: Text('Save changes'),
),
),
),
)
],
),
),
),
],
),
Expanded(
child: SingleChildScrollView(
child: WidgetsContainer(
createNewManager: model.createNewManager,
managers: model.managers,
)),
)
],
),
),
],
),
);
You may see that i use Expanded widget to make SingleChildeScrollView fill all free space
and this is error
Incorrect use of ParentDataWidget.
The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a
RenderObject, which has been set up to accept ParentData of incompatible type ParentData.
Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically,
Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a _SingleChildViewport widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
RepaintBoundary ← NotificationListener<ScrollNotification> ←
NotificationListener<ScrollMetricsNotification> ← _MaterialScrollbar ← Scrollbar ← Scrollable ←
SingleChildScrollView ← Expanded ← ShimmerWaiting ← FutureBuilder<dynamic> ← ⋯
this is how my screen looks like
also this is what futureBuilder in class WidgetsContainer returns me
Column(
children: [ManagerContainer(createNewManager: createNewManager), ServicesContainer()],
);

Another exception was thrown: A RenderFlex overflowed by 4.1 pixels on the bottom

I am need to create to Material Widget per row, but when i create it i wanted to add padding when i do so for the column the yellow error appears with this error:
Another exception was thrown: A RenderFlex overflowed by 4.1 pixels on
the bottom.
Another exception was thrown: A RenderFlex overflowed by 4.1 pixels on
the bottom.
Another exception was thrown: A RenderFlex overflowed by 4.1 pixels on
the bottom.
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY
╞═════════════════════════════════════════════════════════ The
following assertion was thrown during layout: A RenderFlex overflowed
by 0.200 pixels on the right. The relevant error-causing widget was:
Row
Row:file:///E:/work/nabaa_mobile-main/lib/ui/screens/home/widgets/bottom_home_page/home.dart:134:25
To inspect this widget in Flutter DevTools, visit:
http://127.0.0.1:9101/#/inspector?uri=http%3A%2F%2F127.0.0.1%3A56940%2FUjrL2FntShg%3D%2F&inspectorRef=inspector-1305
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#164c6
relayoutBoundary=up1 OVERFLOWING: creator: Row ← Column ← Semantics ←
DefaultTextStyle ← AnimatedDefaultTextStyle ←
_InkFeatures-[GlobalKey#020b0 ink renderer] ← NotificationListener ← CustomPaint ←
_ShapeBorderPaint ← PhysicalShape ← _MaterialInterior ← Material ← ⋯ parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use
size) constraints: BoxConstraints(0.0<=w<=135.2, 0.0<=h<=Infinity)
size: Size(135.2, 40.0) direction: horizontal mainAxisAlignment:
start mainAxisSize: max crossAxisAlignment: center textDirection: ltr
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: A RenderFlex overflowed by 12 pixels on
the bottom. Another exception was thrown: A RenderFlex overflowed by
0.200 pixels on the right. Another exception was thrown: A RenderFlex overflowed by 12 pixels on the bottom. Another exception
was thrown: A RenderFlex overflowed by 0.200 pixels on the right.
Another exception was thrown: A RenderFlex overflowed by 12 pixels
on the bottom. Another exception was thrown: A RenderFlex
overflowed by
0.200 pixels on the right. Another exception was thrown: A RenderFlex overflowed by 12 pixels on the bottom. Performing hot
reload... Reloaded 1 of 1166 libraries in 4,534ms. Performing hot
reload... Reloaded 1 of 1166 libraries in 3,199ms. ══╡ EXCEPTION
CAUGHT BY RENDERING LIBRARY
╞═════════════════════════════════════════════════════════ The
following assertion was thrown during layout: A RenderFlex overflowed
by 0.200 pixels on the right. The relevant error-causing widget was:
Row
Row:file:///E:/work/nabaa_mobile-main/lib/ui/screens/home/widgets/bottom_home_page/home.dart:140:27
To inspect this widget in Flutter DevTools, visit:
http://127.0.0.1:9101/#/inspector?uri=http%3A%2F%2F127.0.0.1%3A56940%2FUjrL2FntShg%3D%2F&inspectorRef=inspector-2705
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#4f67e
relayoutBoundary=up1 OVERFLOWING: creator: Row ← Column ← Padding ←
DefaultTextStyle ← AnimatedDefaultTextStyle ←
_InkFeatures-[GlobalKey#c9285 ink renderer] ← NotificationListener ← CustomPaint ←
_ShapeBorderPaint ← PhysicalShape ← _MaterialInterior ← Material ← ⋯ parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use
size) constraints: BoxConstraints(0.0<=w<=135.2, 0.0<=h<=Infinity)
size: Size(135.2, 40.0) direction: horizontal mainAxisAlignment:
start mainAxisSize: max crossAxisAlignment: center textDirection: ltr
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: A RenderFlex overflowed by 12 pixels on
the bottom.
========================================================================
the code is
GridView.count(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
crossAxisCount: 2,
mainAxisSpacing: 4,
scrollDirection: Axis.vertical,
crossAxisSpacing: 4.w,
// padding: EdgeInsets.all(9),
children: List.generate(4, (index) {
return Material(
// padding: const EdgeInsets.all(8.0),
shape: RoundedRectangleBorder(
// side: ,
borderRadius: BorderRadius.circular(18.0),
),
type: MaterialType.button,
color: whiteColor,
elevation: 5,
// clipBehavior: Clip.antiAliasWithSaveLayer,
shadowColor: blackColor.withOpacity(0.5),
child: Column(
children: [
Row(
children: [
CircleAvatar(
foregroundColor: blackColor,
child: ClipOval(
child:
Image.asset('assets/images/meta-logo.png'),
),
),
Padding(
padding: EdgeInsetsDirectional.only(start: 4.w),
child: Text(
"company_name".tr,
// textAlign: TextAlign.end,
style: Get.textTheme.headline3!
.copyWith(color: faddenGreyColor),
),
),
],
),
Align(
alignment: AlignmentDirectional.centerStart,
heightFactor: 0.3.h,
child: Text(
"opportunity_title".tr,
style: Get.textTheme.headline4,
),
),
Row(
children: [
Icon(
Icons.calendar_today_outlined,
color: faddenGreyColor,
size: 13.sp,
),
Padding(
padding: EdgeInsetsDirectional.only(start: 2.w),
child: Text(
"date".tr,
style: Get.textTheme.headline3!.copyWith(
color: faddenGreyColor,
),
),
),
],
),
Row(
children: [
Icon(
Icons.location_on_outlined,
color: faddenGreyColor,
size: 15.sp,
),
Padding(
padding: EdgeInsetsDirectional.only(start: 2.w),
child: Text(
"location".tr,
style: Get.textTheme.headline3!.copyWith(
color: faddenGreyColor,
),
),
),
],
),
SizedBox(height: 2.h),
],
),
);
}),
),
-> Use Can Use For This Code SingleChildScrollView
import 'package:flutter/material.dart';
class Data extends StatefulWidget {
const Data({Key? key}) : super(key: key);
#override
_DataState createState() => _DataState();
}
class _DataState extends State<Data> {
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: GridView.count(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
crossAxisCount: 2,
mainAxisSpacing: 4,
scrollDirection: Axis.vertical,
crossAxisSpacing: 4,
// padding: EdgeInsets.all(9),
children: List.generate(4, (index) {
return Material(
// padding: const EdgeInsets.all(8.0),
shape: RoundedRectangleBorder(
// side: ,
borderRadius: BorderRadius.circular(18.0),
),
type: MaterialType.button,
color: Colors.white,
elevation: 5,
// clipBehavior: Clip.antiAliasWithSaveLayer,
shadowColor: Colors.black.withOpacity(0.5),
child: Column(
children: [
Row(
children: [
CircleAvatar(
foregroundColor: Colors.black,
child: ClipOval(
child: Image.asset('assets/images/meta-logo.png'),
),
),
Padding(
padding: EdgeInsetsDirectional.only(start: 4),
child: Text(
"company_name",
// textAlign: TextAlign.end,
style: TextStyle(),
),
),
],
),
Align(
alignment: AlignmentDirectional.centerStart,
child: Text(
"opportunity_title",
style: TextStyle(),
),
),
Row(
children: [
Icon(
Icons.calendar_today_outlined,
color: Colors.red,
size: 13,
),
Padding(
padding: EdgeInsetsDirectional.only(start: 2),
child: Text(
"location",
style: TextStyle(),
),
),
],
),
Row(
children: [
Icon(
Icons.location_on_outlined,
color: Colors.red,
size: 15,
),
Padding(
padding: EdgeInsetsDirectional.only(start: 2),
child: Text(
"location",
style: TextStyle(),
),
),
],
),
SizedBox(height: 2),
],
),
);
}),
),
);
}
}
Expanded all your widget in Column
GridView.count(
shrinkWrap: true,
physics: const ScrollPhysics(),
crossAxisCount: 2,
mainAxisSpacing: 4,
scrollDirection: Axis.vertical,
crossAxisSpacing: 4,
// padding: EdgeInsets.all(9),
children: List.generate(4, (index) {
return Material(
// padding: const EdgeInsets.all(8.0),
shape: RoundedRectangleBorder(
// side: ,
borderRadius: BorderRadius.circular(18.0),
),
type: MaterialType.button,
elevation: 5,
// clipBehavior: Clip.antiAliasWithSaveLayer,
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Expanded(
child: Row(
children: [
Expanded(
child: CircleAvatar(
child: ClipOval(
child: Image.asset('images/profile.png'),
),
),
),
Expanded(
child: Padding(
padding: EdgeInsetsDirectional.only(start: 4),
child: Text(
"company_name",
// textAlign: TextAlign.end,
),
),
),
],
),
),
Expanded(
child: Align(
alignment: AlignmentDirectional.centerStart,
heightFactor: 0.3,
child: Text(
"opportunity_title",
),
),
),
Expanded(
child: Row(
children: [
Expanded(
child: Icon(
Icons.calendar_today_outlined,
),
),
Expanded(
child: Padding(
padding: EdgeInsetsDirectional.only(start: 2),
child: Text(
"date",
),
),
),
],
),
),
Expanded(
child: Row(
children: [
Expanded(
child: Icon(
Icons.location_on_outlined,
),
),
Expanded(
child: Padding(
padding: EdgeInsetsDirectional.only(start: 2),
child: Text(
"location",
),
),
),
],
),
),
],
),
),
);
}),
),
output:

ReorderableListView: Exception: BoxConstraints forces an infinite height

TL;DR - How to achieve shrinkWrap = true in a ReorderableListView?
I was trying to create a ReoderableListView with Column<-Container as parent, this error occured.
I/flutter (32618): The following assertion was thrown during performLayout():
I/flutter (32618): BoxConstraints forces an infinite height.
I/flutter (32618): The following RenderObject was being processed when the exception was fired: RenderStack#23840 relayoutBoundary=up17 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
I/flutter (32618): creator: Stack ← _Theatre ← Overlay-[GlobalKey#dc153 ReorderableListView overlay key] ←
I/flutter (32618): ReorderableListView ← StreamBuilder<QuerySnapshot> ← Column ← Padding ← Padding ← Container ←
I/flutter (32618): BoardCard ← Column ← _SingleChildViewport ← ⋯
I/flutter (32618): parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
I/flutter (32618): constraints: BoxConstraints(0.0<=w<=328.0, 0.0<=h<=Infinity)
I/flutter (32618): size: MISSING
I/flutter (32618): alignment: AlignmentDirectional.topStart
I/flutter (32618): textDirection: ltr
I/flutter (32618): fit: expand
I/flutter (32618): overflow: clip
I/flutter (32618): This This RenderObject had the following child:
I/flutter (32618): child 1: _RenderLayoutBuilder#55d3d NEEDS-LAYOUT NEEDS-PAINT
This would have been fixed very easily if it was ListView by using shrinkWrap = true but ReorderableListView does not have the this property.
Here is the code
#override
Widget build(BuildContext context) {
final _listTitleStyle =
TextStyle(fontSize: 20, fontWeight: FontWeight.w500);
final _listSubTitleStyle = TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
color: Color(0xff7D7373),
);
return Container(
padding: EdgeInsets.all(8),
margin: EdgeInsets.all(8),
child: Column(
children: <Widget>[
Container(
child: Row(
children: <Widget>[
Expanded(
child: Row(
textBaseline: TextBaseline.alphabetic,
crossAxisAlignment: CrossAxisAlignment.baseline,
children: <Widget>[
Text(
widget.cardTitle,
style: _listTitleStyle,
),
SizedBox(
width: 2,
),
Text(
widget.cardSubTitle,
style: _listSubTitleStyle,
),
],
),
),
Icon(Icons.keyboard_arrow_down),
],
),
),
SizedBox(
height: 8,
),
StreamBuilder<QuerySnapshot>(
stream: widget.query,
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
return _buildList(context, snapshot.data.documents);
}),
],
),
);
}
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
snapshot.forEach((snap) {
print("debug 1 ${snap.data}");
print(TodoItem.fromSnapshot(snap, snap.reference).toString());
});
return ReorderableListView(
onReorder: (oldIndex, newIndex){},
children: snapshot
.map((data) => TodoTile(TodoItem.fromSnapshot(data, data.reference), key: UniqueKey(),))
.toList(),
);
}
I have fixed this problem by replacing ReorderableListView by the package flutter_reorderable_list, it accepts a child (Widget) unlike ReorderableListView which accepts children (List)
Its implementation is a bit more complex. You can look at the example to get some understanding of implementing it correctly.
I agree with Abdulrahman Falyoun. you just have to make the height dynamic and adjust it based on the number of items in the list.
Container(
height: (list.length * 40).toDouble(),
padding: const EdgeInsets.all(10),
child: ReorderableListView(
children: list.map((item) {
return getItem(item);
}).toList(),
onReorder: _onReorder,
),
)
or if it's within a column, then have it wrap with Expanded()
use Columnto listview and apply shrinkWrap = true
#override
Widget build(BuildContext context) {
final _listTitleStyle =
TextStyle(fontSize: 20, fontWeight: FontWeight.w500);
final _listSubTitleStyle = TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
color: Color(0xff7D7373),
);
return Container(
padding: EdgeInsets.all(8),
margin: EdgeInsets.all(8),
child: Listview(
shrinkWrap = true
children: <Widget>[
Container(
child: Row(
children: <Widget>[
Expanded(
child: Row(
textBaseline: TextBaseline.alphabetic,
crossAxisAlignment: CrossAxisAlignment.baseline,
children: <Widget>[
Text(
widget.cardTitle,
style: _listTitleStyle,
),
SizedBox(
width: 2,
),
Text(
widget.cardSubTitle,
style: _listSubTitleStyle,
),
],
),
),
Icon(Icons.keyboard_arrow_down),
],
),
),
SizedBox(
height: 8,
),
StreamBuilder<QuerySnapshot>(
stream: widget.query,
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
return _buildList(context, snapshot.data.documents);
}),
],
),
);
}
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
snapshot.forEach((snap) {
print("debug 1 ${snap.data}");
print(TodoItem.fromSnapshot(snap, snap.reference).toString());
});
return ReorderableListView(
onReorder: (oldIndex, newIndex){},
children: snapshot
.map((data) => TodoTile(TodoItem.fromSnapshot(data, data.reference), key: UniqueKey(),))
.toList(),
);
}

Insert a Row inside a Column in Flutter

My UI screen is basically rendered using a Column Widget and inside this widget, I am inserting all the other UI components. One of these happens to be a Row ( consisting of 2 text fields). This is the Row Widget :
var phoneNumber = new Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(20.0),
child: countryCodePicker,
),
new Padding(
padding: const EdgeInsets.all(20.0),
child: mobileNumber,
),
],
);
The Main UI Screen being :
return SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
customerName,
emailAddress,
// new Container(
// child: deliveryOptionRow,
// ),
mobileNumber,
countryCodePicker,
templateMessagesDropDown,
templateMessageTextField,
sendGoogleReview,
],
)
);
I see this exception when I add the Row to the Column
The following RenderObject was being processed when the exception was fired:
flutter: _RenderListTile#06b03 relayoutBoundary=up11 NEEDS-LAYOUT NEEDS-PAINT
flutter: creator: _ListTile ← MediaQuery ← Padding ← SafeArea ← Semantics ← Listener ← _GestureSemantics ←
flutter: RawGestureDetector ← GestureDetector ← InkWell ← ListTile ← ListTileTheme ← ⋯
flutter: parentData: offset=Offset(0.0, 0.0) (can use size)
flutter: constraints: BoxConstraints(unconstrained)
flutter: size: MISSING
flutter: This RenderObject had the following descendants (showing up to depth 5):
flutter: _RenderRadio#302a4 relayoutBoundary=up12 NEEDS-PAINT
flutter: RenderParagraph#58a45 NEEDS-LAYOUT NEEDS-PAINT
What would be the best way to add the row inside the main UI screen.
this should solve your problem,
var phoneNumber = new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: new Padding(
padding: const EdgeInsets.all(20.0),
child: countryCodePicker,
),
),
Expanded(
child: new Padding(
padding: const EdgeInsets.all(20.0),
child: mobileNumber,
),
),
],
);
hope it helps!
If your Row contains a TextField or TextFormField or any other widget which tries to grow to infinity, you need to provide an intrinsic width to it. You can do it in several ways:
Use Expanded:
Row(
children: [
Expanded(
child: TextField(), // <-- Wrapped in Expanded.
),
],
)
Use Flexible:
Row(
children: [
Flexible(
child: TextField(), // <-- Wrapped in Flexible.
),
],
)
Provide a fixed width:
Row(
children: [
SizedBox(
width: 200, // <-- Fixed width.
child: TextField(),
),
],
)

A RenderFlex overflowed by 112 pixels on the bottom

I am using AnimatedContainer. it animate size from 0 to some size and it contain some text and all other things. on pressing one button animation is started and it shows flowing errors.
On the button press i just set value of sizeOfLevel. initially value of it is 0.
Code:
AnimatedContainer(
curve: Curves.bounceIn,
duration: Duration(milliseconds: 200),
width: sizeOfLevel,
height: sizeOfLevel,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
image: DecorationImage(
image: AssetImage('images/levelunlockScreen.jpg'),
fit: BoxFit.cover),
border: Border.all(
style: BorderStyle.solid, width: 4.0, color: Colors.white)),
child: Column(
children: <Widget>[
Center(
child: new Text(
"Unlock Level",
style: TextStyle(color: Colors.white, fontSize: 30.0),
),
),
],
),
),
Errors:
I/flutter ( 4579): The following message was thrown during layout:
I/flutter ( 4579): A RenderFlex overflowed by 112 pixels on the bottom.
I/flutter ( 4579): The overflowing RenderFlex has an orientation of Axis.vertical.
I/flutter ( 4579): The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
I/flutter ( 4579): black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
I/flutter ( 4579): Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
I/flutter ( 4579): RenderFlex to fit within the available space instead of being sized to their natural size.
I/flutter ( 4579): This is considered an error condition because it indicates that there is content that cannot be
I/flutter ( 4579): seen. If the content is legitimately bigger than the available space, consider clipping it with a
I/flutter ( 4579): ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
I/flutter ( 4579): like a ListView.
I/flutter ( 4579): The specific RenderFlex in question is:
I/flutter ( 4579): RenderFlex#4086c OVERFLOWING
I/flutter ( 4579): creator: Column ← Padding ← DecoratedBox ← ConstrainedBox ← Container ← AnimatedContainer ← Center
I/flutter ( 4579): ← Stack ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← AnimatedBuilder
I/flutter ( 4579): ← ⋯
I/flutter ( 4579): parentData: offset=Offset(4.0, 4.0) (can use size)
I/flutter ( 4579): constraints: BoxConstraints(w=115.7, h=115.7)
I/flutter ( 4579): size: Size(115.7, 115.7)
I/flutter ( 4579): direction: vertical
I/flutter ( 4579): mainAxisAlignment: start
I/flutter ( 4579): mainAxisSize: max
I/flutter ( 4579): crossAxisAlignment: center
I/flutter ( 4579): verticalDirection: down
" Warping your parent Column into - SingleChildScrollView" works to me, I'm animate the height of the AnimatedContainer.
Older code
return new AnimatedContainer(
curve: Curves.easeInOutCubic,
height: showSearchBar ? 350 : 0,
duration: new Duration(seconds: 3),
child: Container(
margin: EdgeInsets.all(10),
child: Card(
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text('Busque por pacientes'),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 0, vertical: 20),
child: Column(
children: this.children,
),
),
RaisedButton(
color: themeSecondary,
onPressed: () {
print('raised clicked');
},
child: Text('Buscar'),
)
]),
),
),
),
);
And the newer, warping the SingleChildScrollView
return new AnimatedContainer(
curve: Curves.easeInOutCubic,
height: showSearchBar ? 350 : 0,
duration: new Duration(seconds: 3),
child: Container(
margin: EdgeInsets.all(10),
child: Card(
child: Padding(
padding: EdgeInsets.all(20),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text('Busque por pacientes'),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 0, vertical: 20),
child: Column(
children: this.children,
),
),
RaisedButton(
color: themeSecondary,
onPressed: () {
print('raised clicked');
},
child: Text('Buscar'),
)
]),
),
),
),
),
);