Flutter exception after adding the Padding widget - flutter

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

Related

The ownership chain for the RenderObject that received the incompatible parent data in Flutter

An error occurred saying Incorrect use of ParentDataWidget when I use the Expanded widget as follows,
What I did do wrong here?
As well, what is the ownership chain meaning?
Code is as follows,
Expanded(
child: Wrap(
alignment: WrapAlignment.spaceAround,
children: <Widget>[
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
verticalDirection: VerticalDirection.down,
children: <Widget>[
Text(
"${Constants.ASSIGNMENT_PREFIX} ${assignment?.id}",
style: Theme.of(context)
.textTheme
.headline6),
_getAssignState(
assignment?.status),
],
),
),
],
),
)
Full Error as follows,
======== Exception caught by widgets library =======================================================
The following assertion was thrown while applying parent data.:
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 WrapParentData.
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 Wrap widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
Row ← Expanded ← Wrap ← Expanded ← Row ← Padding ← Padding ← DecoratedBox ← Container ← Listener ← ⋯
When the exception was thrown, this was the stack:
#0 RenderObjectElement._updateParentData.<anonymous closure> (package:flutter/src/widgets/framework.dart:5723:11)
#1 RenderObjectElement._updateParentData (package:flutter/src/widgets/framework.dart:5739:6)
#2 RenderObjectElement.attachRenderObject (package:flutter/src/widgets/framework.dart:5761:7)
#3 RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5440:5)
#4 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6228:11)
...
====================================================================================================
Reloaded 1 of 2005 libraries in 1,286ms.
you can only use Expanded as a child of Column and Row or FLex widget.
Expanded: A widget that expands a child of a Row, Column, or Flex so
that the child fills the available space.
child: Wrap(
alignment: WrapAlignment.spaceAround,
children: <Widget>[
// Expanded( => remove this
Row()

RenderPadding object was given an infinite size during layout

I was trying to have another widget in my flutter page so instead of having a container I used (column /list view )
this is the code (main things have red line )
enter image description here
now Im getting these errors
child: RenderPointerListener#c3ba4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData:
constraints: MISSING
size: MISSING
behavior: deferToChild
listeners: down
child: ChartContainerRenderObject#c7bf3 NEEDS-LAYOUT NEEDS-PAINT
parentData:
constraints: MISSING
semantic boundary
size: MISSING
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════
RenderPadding object was given an infinite size during layout.
The relevant error-causing widget was
SafeArea
lib\dept.dart:62
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════
A RenderFlex overflowed by Infinity pixels on the bottom.
The relevant error-causing widget was
Column
lib\dept.dart:60
the issue was solved by adding height:value to the container
child: ListView(
shrinkWrap: true,
children: [
Container(
height: 400,
child: SafeArea(.......)),
Container(child:new Text("palestine");))
This issue can be solved by adding Flexible to your widget.

Failed assertion: line 320 pos 12: 'width > 0.0': is not true for simple sidebar in Flutter

I created a sidebar to my app to show some icons:
Widget build(BuildContext context) {
return Container(
color: widget.backgroundColor,
//width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
child: FittedBox(
child: Image(image: AssetImage('my_icon.png')))),
FittedBox(child: Image(image: AssetImage('my_st.png'))),
FittedBox(child: Image(image: AssetImage('my_cart_2.png'))),
FittedBox(child: Image(image: AssetImage('my_info_2.png'))),
FittedBox(child: Image(image: AssetImage('my_rotate_2.png')))
],
),
);
}
Even though it renders perfectly, I get this error:
════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/box.dart': Failed assertion: line 320 pos 12: 'width > 0.0': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=BUG.md
The relevant error-causing widget was:
FittedBox file:///home/user/AndroidStudioProjects/flutter_app/lib/sidebar.dart:23:22
When the exception was thrown, this was the stack:
#2 BoxConstraints.constrainSizeAndAttemptToPreserveAspectRatio (package:flutter/src/rendering/box.dart:320:12)
#3 RenderFittedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:2433:30)
#4 RenderObject.layout (package:flutter/src/rendering/object.dart:1777:7)
#5 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:768:15)
#6 RenderObject.layout (package:flutter/src/rendering/object.dart:1777:7)
Where the error happens in the first FittedBox. If I remove that, I get the error on the second FittedBox.
I thought it had something to do with the Image not having width, but setting width to them (just to test) didn't work.
Even though I get errors, the sidebar renders correctly.
No need to wrap Image in a FittedBox. Just pass a BoxFit to Image's fit parameter.
Image(image: AssetImage('my_icon.png'), fit: BoxFit.fitWidth)

How can show grid view with other view in single page #flutter

How to add grid view and other view in same page?
I try with listview but it is showing error
I/flutter (10293): Another exception was thrown:
'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed
assertion: line 461 pos 12: 'child.hasSize': is not true. I/flutter
(10293): Another exception was thrown: NoSuchMethodError: The getter
'scrollOffsetCorrection' was called on null. I/flutter (10293):
Another exception was thrown: NoSuchMethodError: The method
'debugAssertIsValid' was called on null. I/flutter (10293): Another
exception was thrown: NoSuchMethodError: The getter 'visible' was
called on null
body:ListView(
children: <Widget>[
Text("checking"),
Container(
child: GridView.count(
crossAxisCount: 3,
childAspectRatio: .6,
children: _list.map((p) => ProductManagment(p)).toList(),
),
)
],
)
Another attempt
body:ListView(
children: <Widget>[
Text("checking"),
GridView.count(
crossAxisCount: 3,
childAspectRatio: .6,
children: _list.map((p) => ProductManagment(p)).toList(),
)
],
)
again error
I/flutter (10293): Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#f955c relayoutBoundary=up6 NEEDS-PAINT
I/flutter (10293): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#a9147 relayoutBoundary=up5 NEEDS-PAINT
I/flutter (10293): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#4a4c9 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (10293): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 461 pos 12: 'child.hasSize': is not true.
I/flutter (10293): Another exception was thrown: NoSuchMethodError: The getter 'scrollOffsetCorrection' was called on null.
I/flutter (10293): Another exception was thrown: NoSuchMethodError: The method 'debugAssertIsValid' was called on null.
I/flutter (10293): Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.
I think you should just set height of the Container or warp it by Expanded widget. And tell what happen?. Might be size is missing thats way error occurred.
EDITED :
body:ListView(
children: <Widget>[
Text("checking"),
Container(
height: 300.0
child: GridView.count(
crossAxisCount: 3,
childAspectRatio: .6,
children: _list.map((p) => ProductManagment(p)).toList(),
),
)
],
)
Set height: 300.0 in container. (You can set height/width as per your requirement or try with Expanded widget)

Flutter Nested List View why Cant i use a Row?

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()
],
),