I am take this error and I dont know why ?
I am get this error messages but my app works flawlessly
Here the errors:
════════ 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 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 RepaintBoundary widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
Padding ← Expanded ← RepaintBoundary ← IndexedSemantics ← NotificationListener ← KeepAlive ← AutomaticKeepAlive ← KeyedSubtree ← SliverList ← MediaQuery ← ⋯
When the exception was thrown, this was the stack
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
and here my codes
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
controller: listScrollController,
children: [
Padding(
padding: context.paddingLeft + context.paddingTop,
child: Text(
Texts.headerText,
style: context.theme.textTheme.headline3!.copyWith(),
),
),
Expanded(
child: Padding(
padding: context.paddingAll,
child: SizedBox(
height: context.dynamicHeight(0.4),
child: Lottie.asset(Assets.asset1)),
),
),
Expanded(
child: Padding(
padding: context.paddingLeft,
child: Text(
Texts.viewText,
style: context.theme.textTheme.titleLarge,
),
),
),
Expanded(
child: Padding(
padding: context.paddingTop,
child: downButton(
() {
scrollToBottom();
},
),
),
),
Stack(
children: [
SizedBox(
height: context.dynamicHeight(2),
child: Padding(
padding: context.paddingTop * 2,
child: Lottie.asset(Assets.asset2, fit: BoxFit.cover),
),
),
],
),
],
),
);
Thank you :)
You can only use Expandedor Flexible for Row and Column Widget. Other than that, it will give you error of incorrect parent widget.
The error it self indicates incorrect use of parent widget meaning that the Parent widget is incorrect which is true in case of ListView being the parent(wrong) of Expanded.
Expanded only used for Row or Column.
you can't use it as children for other widget.
Remove all Expanded widget from ListView children.
or change ListView to Column, and wrap it with singleChildscrollView to make it scrollable
You do not have a Flex ancestor and the issue will cause in release mode.
An Expanded widget must be a descendant of a Row, Column, or Flex, and the path from the Expanded widget to its enclosing Row, Column, or Flex must contain only StatelessWidgets or StatefulWidgets (not other kinds of widgets, like RenderObjectWidgets).
you can refer to this link
https://api.flutter.dev/flutter/widgets/Expanded-class.html#:~:text=A%20widget%20that%20expands%20a,or%20vertically%20for%20a%20Column).
In your case writing down Colum instead of listview will solve your issue. or remove expanded from listview
Related
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()
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.
Since I introduced a PageView widget, I get this error:
════════ 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 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 RepaintBoundary widget.
The ownership chain for the RenderObject that received the incompatible parent data was: Padding ← Container ← AnimatedContainer-[LabeledGlobalKey<ImplicitlyAnimatedWidgetState<ImplicitlyAnimatedWidget>>#758ef] ← KeyboardAvoider ← Expanded ← VpFormContainer ← LoggedOutNickNamePage ← RepaintBoundary ← IndexedSemantics ← NotificationListener<KeepAliveNotification> ← ⋯ When the exception was thrown, this was the stack
#0 RenderObjectElement._updateParentData.<anonymous closure> package:flutter/…/widgets/framework.dart:5770
#1 RenderObjectElement._updateParentData package:flutter/…/widgets/framework.dart:5786
#2 RenderObjectElement.attachRenderObject package:flutter/…/widgets/framework.dart:5808
#3 RenderObjectElement.mount package:flutter/…/widgets/framework.dart:5501
#4 SingleChildRenderObjectElement.mount package:flutter/…/widgets/framework.dart:6117 ...
════════ 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 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 RepaintBoundary widget.
The ownership chain for the RenderObject that received the incompatible parent data was: Padding ← Container ← AnimatedContainer-[LabeledGlobalKey<ImplicitlyAnimatedWidgetState<ImplicitlyAnimatedWidget>>#758ef] ← KeyboardAvoider ← Expanded ← VpFormContainer ← LoggedOutNickNamePage ← RepaintBoundary ← IndexedSemantics ← NotificationListener<KeepAliveNotification> ← ⋯ When the exception was thrown, this was the stack
#0 RenderObjectElement._updateParentData.<anonymous closure> package:flutter/…/widgets/framework.dart:5770
#1 RenderObjectElement._updateParentData package:flutter/…/widgets/framework.dart:5786
#2 RenderObjectElement.attachRenderObject package:flutter/…/widgets/framework.dart:5808
#3 RenderObjectElement.mount package:flutter/…/widgets/framework.dart:5501
#4 SingleChildRenderObjectElement.mount package:flutter/…/widgets/framework.dart:6117 ...
I have been trying fixes for the last couple of hours, but nothing is working. Does anyone know exactly where to apply a fix and what is the fix?
Here is the PageView:
class LoggedOutPageView extends StatelessWidget {
final _controller = PageController(
initialPage: 0,
);
#override
Widget build(BuildContext context) {
print('building loggedOutPageView');
final pageView = PageView(
physics: const NeverScrollableScrollPhysics(),
controller: _controller,
clipBehavior: Clip.none,
children: [
LoggedOutNickNamePage(_controller),
LoggedOutEmailPage(_controller),
LoggedOutPasswordPage(),
],
);
final _pageContent = Expanded(
child: Container(child: pageView, color: Colors.transparent), flex: 1);
final _pageIndicator = Container(
height: 50,
child: SmoothPageIndicator(
controller: _controller,
count: 3,
effect: const JumpingDotEffect(),
),
color: Colors.transparent);
return VpFormPageScaffold([
VpLogoHeader(
onPressed: () {
print(_controller.page);
if (_controller.page > 0) {
_controller.previousPage(
duration: const Duration(milliseconds: 800),
curve: Curves.easeInOutCubic);
} else {
Navigator.pop(context);
}
},
pop: false),
_pageContent,
_pageIndicator
]);
}
}
VpFormPageScaffold:
class VpFormPageScaffold extends StatelessWidget {
VpFormPageScaffold(this.children);
List<Widget> children;
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: ConstrainedBox(
constraints: BoxConstraints.tightFor(
height: MediaQuery.of(context).size.height),
child: VpGradientContainer(
beginColor: initialGradientColor,
endColor: endGradientColor,
child: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: children)))));
}
}
VpGradientContainer:
class VpGradientContainer extends StatelessWidget {
const VpGradientContainer({this.child, this.beginColor, this.endColor});
final Widget child;
final Color beginColor;
final Color endColor;
#override
Widget build(BuildContext context) {
return Container(
child: child,
height: double.infinity,
width: double.infinity,
padding: const EdgeInsets.all(40),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [beginColor, endColor],
),
),
);
}
}
Expanded widgets must be placed inside Flex widgets. You are using Expanded widget where it cannot be used. You'll have to remove Expanded widget from here :
final _pageContent = Expanded(
child: Container(child: pageView, color: Colors.transparent), flex: 1);
Please checkout Flutter docs for Expanded Widget:
Expanded
A widget that expands a child of a Row, Column, or Flex
so that the child fills the available space.
Using an Expanded widget makes a child of a Row, Column, or Flex
expand to fill the available space along the main axis (e.g.,
horizontally for a Row or vertically for a Column). If multiple
children are expanded, the available space is divided among them
according to the flex factor.
An Expanded widget must be a descendant of a Row, Column, or Flex, and
the path from the Expanded widget to its enclosing Row, Column, or
Flex must contain only StatelessWidgets or StatefulWidgets (not other
kinds of widgets, like RenderObjectWidgets).
I'm a newbie who just started Flutter.
I want to use CustomScrollView as a child of Row/Column Widget
It works very well when CustomScrollView is root.
But as soon as I put it into Row Widget's child, it spouted an error.
Couldn't CustomScrollview be used as a child of Row widget?
if so, please tell me the reason, and What is the best alternative?
Or if there is an error in my code, I want you to correct it.
What I want to make
my CustomScrollViewWidget
I don't know if this is what you want, but here's my error.
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1758 pos 16:
'constraints.hasBoundedHeight': 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:
CustomScrollView
The following RenderObject was being processed when the exception was fired: RenderShrinkWrappingViewport#0344f relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
needs compositing
creator: ShrinkWrappingViewport ← IgnorePointer-[GlobalKey#e4530] ← Semantics ← _PointerListener ←
Listener ← _GestureSemantics ←
RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#a61b3] ← _PointerListener ← Listener
← _ScrollableScope ← _ScrollSemantics-[GlobalKey#42b3c] ← RepaintBoundary ← ⋯
parentData: <none> (can use size)
constraints: BoxConstraints(unconstrained)
size: MISSING
axisDirection: right
crossAxisDirection: down
offset: ScrollPositionWithSingleContext#46fe1(offset: 0.0, range: null..null, viewport: null,
ScrollableState, ClampingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#66c28,
ScrollDirection.idle)
This RenderObject had the following child:
child 0: RenderSliverList#42dfb NEEDS-LAYOUT NEEDS-PAINT
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderShrinkWrappingViewport#0344f relayoutBoundary=up14 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1702 pos 12: 'hasSize'
The relevant error-causing widget was
CustomScrollView
lib\0. TestCode.dart:31
════════════════════════════════════════════════════════════════════════════════
Here is my code!
class WrapVisit extends StatefulWidget {
WrapVisitState createState() => WrapVisitState();
}
class WrapVisitState extends State<WrapVisit> {
#override
Widget build(BuildContext context) {
return new Container(
padding: EdgeInsets.all(10),
color: Colors.white,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
new Text(
"브랜드관",
textAlign: TextAlign.left,
style: TextStyle(fontWeight: FontWeight.bold),
),
new Container(
margin: EdgeInsets.all(5),
child: new Text(
"전체보기",
textAlign: TextAlign.right,
style: TextStyle(
fontSize: 10,
color: Colors.black,
),
),
),
CustomScrollView(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
slivers: [
SliverList(
delegate: SliverChildListDelegate(
[
... SliverListChildWidgets ...
],
),
),
],
),
],
),
],
),
);
}
}
Column doesn't like children with unbounded height. To fix it, set CustomScrollView's shrinkWrap parameter to true.
You need to wrap the scroll view in either a sized box or container first. It needs a parent with set dimensions. There’s a couple widgets that don’t work in rows/columns unless you put them inside a sized parent first.
I have a layout structure in Flutter like this:
Inkwell
Card
ScopedModelDescendant
Column
Container[]
The number of containers in the column is variable.
The goal is that it should look like this:
But instead, it ends up doing this:
I've tried adding a clipBehavior property to the Card, and I've tried mixing in ClipRects anywhere in the structure, but nothing seems to work. My best guess is that a ClipRect above the Column doesn't help because the overflow happens within the column.
This is the error I'm getting:
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following message was thrown during layout:
flutter: A RenderFlex overflowed by 15 pixels on the bottom.
flutter:
flutter: The overflowing RenderFlex has an orientation of Axis.vertical.
flutter: The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
flutter: black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
flutter: Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
flutter: RenderFlex to fit within the available space instead of being sized to their natural size.
flutter: This is considered an error condition because it indicates that there is content that cannot be
flutter: seen. If the content is legitimately bigger than the available space, consider clipping it with a
flutter: ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
flutter: like a ListView.
flutter: The specific RenderFlex in question is:
flutter: RenderFlex#094c9 OVERFLOWING
flutter: creator: Column ← ScopedModelDescendant<EventModel> ← Semantics ← DefaultTextStyle ←
flutter: AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#5fe8b ink renderer] ←
flutter: NotificationListener<LayoutChangedNotification> ← CustomPaint ← _ShapeBorderPaint ← PhysicalShape
flutter: ← _MaterialInterior ← Material ← ⋯
flutter: parentData: <none> (can use size)
flutter: constraints: BoxConstraints(w=56.0, h=104.3)
flutter: size: Size(56.0, 104.3)
flutter: direction: vertical
flutter: mainAxisAlignment: start
flutter: mainAxisSize: max
flutter: crossAxisAlignment: stretch
flutter: verticalDirection: down
flutter: ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
Wrap widget solves your problem. If there is not enough space to fit the child in a Column or Row, you can use Wrap. You can use alignment, directionality and spacing properties to customize it.
Here is the simple example:
class WrapExample extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SizedBox(
width: 200,
height: 180,
child: Card(
clipBehavior: Clip.antiAlias,
child: Wrap(
direction: Axis.horizontal,
spacing: 8.0, // gap between adjacent chips
runSpacing: 4.0, // gap between lines
children: <Widget>[
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue.shade900, child: Text('AH')),
label: Text('Hamilton'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue.shade900, child: Text('ML')),
label: Text('Lafayette'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue.shade900, child: Text('HM')),
label: Text('Mulligan'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue.shade900, child: Text('JL')),
label: Text('Laurens'),
),
],
),
),
);
}
}
And here is the output:
You can also just wrap the widget you want to allow overflowing in a Positioned inside a Stack widget and set the the Positioned parameter top: 0.
Works like charm for me