I have an error Incorrect use of ParentDataWidget
, but the place in the code where it is located is unknown. I tried to use Flutter DevTools
, but there is nothing there either. How can I find where the problem is? The place where the error occurs, I found out approximately through the breakpoints, but there is nowhere Column ← Expanded ← _SingleChildViewport ← IgnorePointer-[GlobalKey#70e68]
The error shows that the exception is triggered inside the flutter framework
, but where exactly in the code the exception is triggered is not clear. How can you find the problem in this case? Usually the error says, in such a file and on which line the problem is, but here it is just an exception and the place where it is triggered is unknown I will be glad to any ideas
======== 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 _SingleChildViewport widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
Column ← Expanded ← _SingleChildViewport ← IgnorePointer-[GlobalKey#70e68] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#9a817] ← Listener ← _ScrollableScope ← ⋯
When the exception was thrown, this was the stack:
#0 RenderObjectElement._updateParentData.<anonymous closure> (package:flutter/src/widgets/framework.dart:5991:11)
#1 RenderObjectElement._updateParentData (package:flutter/src/widgets/framework.dart:6008:6)
#2 RenderObjectElement.attachRenderObject (package:flutter/src/widgets/framework.dart:6031:36)
#3 RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5677:5)
#4 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6525:11)
... Normal element mounting (91 frames)
#95 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (19 frames)
#114 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#115 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6518:36)
#116 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6531:32)
... Normal element mounting (261 frames)
#377 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#378 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6518:36)
#379 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6531:32)
... Normal element mounting (60 frames)
#439 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#440 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6518:36)
#441 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6531:32)
... Normal element mounting (34 frames)
#475 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#476 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6518:36)
#477 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6531:32)
... Normal element mounting (269 frames)
#746 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#747 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6518:36)
#748 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6531:32)
... Normal element mounting (356 frames)
#1104 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#1105 Element.updateChild (package:flutter/src/widgets/framework.dart:3500:18)
#1106 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4805:16)
#1107 _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:495:11)
#1108 Element.rebuild (package:flutter/src/widgets/framework.dart:4463:5)
#1109 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4757:5)
#1110 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4752:5)
#1111 _InheritedProviderScopeElement.mount (package:provider/src/inherited_provider.dart:395:11)
... Normal element mounting (7 frames)
#1118 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1125 _NestedHookElement.mount (package:nested/nested.dart:187:11)
#1126 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#1127 Element.updateChild (package:flutter/src/widgets/framework.dart:3500:18)
#1128 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4805:16)
#1129 _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:495:11)
#1130 Element.rebuild (package:flutter/src/widgets/framework.dart:4463:5)
#1131 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4757:5)
#1132 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4752:5)
#1133 _InheritedProviderScopeElement.mount (package:provider/src/inherited_provider.dart:395:11)
... Normal element mounting (7 frames)
#1140 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1147 _NestedHookElement.mount (package:nested/nested.dart:187:11)
#1148 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#1149 Element.updateChild (package:flutter/src/widgets/framework.dart:3500:18)
#1150 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4805:16)
#1151 _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:495:11)
#1152 Element.rebuild (package:flutter/src/widgets/framework.dart:4463:5)
#1153 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4757:5)
#1154 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4752:5)
#1155 _InheritedProviderScopeElement.mount (package:provider/src/inherited_provider.dart:395:11)
... Normal element mounting (7 frames)
#1162 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1169 _NestedHookElement.mount (package:nested/nested.dart:187:11)
#1170 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#1171 Element.updateChild (package:flutter/src/widgets/framework.dart:3500:18)
#1172 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4805:16)
#1173 _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:495:11)
#1174 Element.rebuild (package:flutter/src/widgets/framework.dart:4463:5)
#1175 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4757:5)
#1176 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4752:5)
#1177 _InheritedProviderScopeElement.mount (package:provider/src/inherited_provider.dart:395:11)
... Normal element mounting (7 frames)
#1184 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1191 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1198 _NestedHookElement.mount (package:nested/nested.dart:187:11)
#1199 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#1200 Element.updateChild (package:flutter/src/widgets/framework.dart:3500:18)
#1201 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4805:16)
#1202 _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:495:11)
#1203 Element.rebuild (package:flutter/src/widgets/framework.dart:4463:5)
#1204 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4757:5)
#1205 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4752:5)
#1206 _InheritedProviderScopeElement.mount (package:provider/src/inherited_provider.dart:395:11)
... Normal element mounting (7 frames)
#1213 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1220 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1227 _NestedHookElement.mount (package:nested/nested.dart:187:11)
#1228 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#1229 Element.updateChild (package:flutter/src/widgets/framework.dart:3500:18)
#1230 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4805:16)
#1231 _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:495:11)
#1232 Element.rebuild (package:flutter/src/widgets/framework.dart:4463:5)
#1233 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4757:5)
#1234 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4752:5)
#1235 _InheritedProviderScopeElement.mount (package:provider/src/inherited_provider.dart:395:11)
... Normal element mounting (7 frames)
#1242 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1249 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1256 _NestedHookElement.mount (package:nested/nested.dart:187:11)
#1257 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#1258 Element.updateChild (package:flutter/src/widgets/framework.dart:3500:18)
#1259 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4805:16)
#1260 _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:495:11)
#1261 Element.rebuild (package:flutter/src/widgets/framework.dart:4463:5)
#1262 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4757:5)
#1263 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4752:5)
#1264 _InheritedProviderScopeElement.mount (package:provider/src/inherited_provider.dart:395:11)
... Normal element mounting (7 frames)
#1271 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1278 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1285 _NestedHookElement.mount (package:nested/nested.dart:187:11)
#1286 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#1287 Element.updateChild (package:flutter/src/widgets/framework.dart:3500:18)
#1288 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4805:16)
#1289 _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:495:11)
#1290 Element.rebuild (package:flutter/src/widgets/framework.dart:4463:5)
#1291 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4757:5)
#1292 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4752:5)
#1293 _InheritedProviderScopeElement.mount (package:provider/src/inherited_provider.dart:395:11)
... Normal element mounting (7 frames)
#1300 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1307 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1314 _NestedHookElement.mount (package:nested/nested.dart:187:11)
... Normal element mounting (7 frames)
#1321 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#1328 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3756:14)
#1329 Element.updateChild (package:flutter/src/widgets/framework.dart:3500:18)
#1330 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1198:16)
#1331 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1167:5)
#1332 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1112:18)
#1333 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2604:19)
#1334 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1111:13)
#1335 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:944:7)
#1336 WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:924:7)
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
CodePudding user response:
You should use Flexible(), Expanded(), Flex() Widget
inside Rows And Columns
, please check if you have placed it in other than rows and columns.
Try Searching Flex, Flexible, Expanded in your screen.
CodePudding user response:
It's hard to answer questions without seeing the code. but I think you are using the Expanded widget inside the incorrect parent Widget. you have to use the Expanded widget only inside Row, Column or Flex widget. So that is can use the available space it the parent widget. u can also read the documentation
CodePudding user response:
Works fine on my machine on Flutter 2.12. Please provide the relevant code and output of Flutter doctor. Also check if you are using Expanded
as a child of Row
,Column
or Flex
.
Here's an example of how to use Expanded
widget in a Column
:
Column(
children: const <Widget>[
Expanded(
child: Center(
child: Text(
"This is an expanded box",
style: TextStyle(
fontSize: 28
),
),
)
),
]
),
)
Click here to see the output of above code
CodePudding user response:
Unfortunately, the last eight entries in that list are created by SingleChildScrollView
, so all you can really get from that error message is
Column ← Expanded ← SingleChildScrollView
To find exactly where the widget was created, you can set a breakpoint on the line in the Flutter framework that throws the exception. Once you reach that line, you can look at this._widget._location
and parentDataWidget._location
, which contain the same information that is used to display the relevant error-causing widget in other error messages.