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 :)
CodePudding user response:
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
CodePudding user response:
You can only use Expanded
or 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
.
CodePudding user response:
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
In your case writing down Colum instead of listview will solve your issue. or remove expanded from listview