-
Notifications
You must be signed in to change notification settings - Fork 27.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling MultiChildLayoutDelegate.hasChild from MultiChildLayoutDelegate.getSize throws an exception because _idToChild is null #115898
Comments
Triage reportI can reproduce this issue on Code Sample (Same as OP)import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomMultiChildLayout(
delegate: _MultiChildLayoutDelegate(),
children: [
LayoutId(
id: 0,
child: const SizedBox(
width: 50,
height: 50,
),
),
LayoutId(
id: 1,
child: const SizedBox(
width: 50,
height: 50,
),
),
LayoutId(
id: 2,
child: const SizedBox(
width: 50,
height: 50,
),
)
],
),
);
}
}
class _MultiChildLayoutDelegate extends MultiChildLayoutDelegate {
_MultiChildLayoutDelegate();
@override
Size getSize(BoxConstraints constraints) {
hasChild(0);
return Size(constraints.maxWidth, constraints.maxHeight);
}
@override
void performLayout(Size size) {}
@override
bool shouldRelayout(covariant MultiChildLayoutDelegate oldDelegate) {
return true;
}
} Logs══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following _CastError was thrown during performLayout():
Null check operator used on a null value
The relevant error-causing widget was:
CustomMultiChildLayout
CustomMultiChildLayout:file:///home/exabyt3/dev/nevercode/issue_115898/lib/main.dart:28:13
When the exception was thrown, this was the stack:
#0 MultiChildLayoutDelegate.hasChild (package:flutter/src/rendering/custom_layout.dart:133:46)
#1 _MultiChildLayoutDelegate.getSize (package:issue_115898/main.dart:63:5)
#2 RenderCustomMultiChildLayoutBox._getSize (package:flutter/src/rendering/custom_layout.dart:359:44)
#3 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:409:12)
#4 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#5 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#6 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:171:12)
#7 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:1080:7)
#8 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:240:7)
#9 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:410:14)
#10 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#11 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#12 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#13 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#14 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#15 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#16 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1467:11)
#17 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#18 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#19 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#20 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#21 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#22 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#23 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#24 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#25 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#26 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#27 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#28 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#29 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#30 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#31 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#32 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#33 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#34 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#35 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#36 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#37 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#38 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#39 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#40 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#41 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#42 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#43 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#44 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#45 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#46 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#47 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3815:13)
#48 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#49 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#50 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#51 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#52 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#53 _RenderTheatre.performLayout (package:flutter/src/widgets/overlay.dart:856:15)
#54 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#55 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#56 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#57 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#58 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#59 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#60 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#61 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#62 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#63 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#64 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#65 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#66 RenderCustomPaint.performLayout (package:flutter/src/rendering/custom_paint.dart:552:11)
#67 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#68 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#69 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#70 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#71 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#72 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#73 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#74 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#75 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#76 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#77 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#78 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#79 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#80 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#81 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#82 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#83 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#84 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14)
#85 RenderObject.layout (package:flutter/src/rendering/object.dart:2189:7)
#86 RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
#87 RenderView.performLayout (package:flutter/src/rendering/view.dart:175:14)
#88 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2027:7)
#89 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1020:18)
#90 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:516:19)
#91 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:869:13)
#92 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:381:5)
#93 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1289:15)
#94 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1218:9)
#95 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:942:7)
#99 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
(elided 3 frames from class _Timer and dart:async-patch)
The following RenderObject was being processed when the exception was fired: RenderCustomMultiChildLayoutBox#71e82 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
creator: CustomMultiChildLayout ← KeyedSubtree-[GlobalKey#bdc5b] ← _BodyBuilder ← MediaQuery ←
LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← _ActionsMarker ← Actions ←
AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#ce008 ink
renderer] ← ⋯
parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
constraints: BoxConstraints(0.0<=w<=952.0, 0.0<=h<=1014.0)
size: MISSING
This RenderObject had the following descendants (showing up to depth 5):
child 1: RenderConstrainedBox#7ee0d NEEDS-LAYOUT NEEDS-PAINT
child 2: RenderConstrainedBox#2dd2d NEEDS-LAYOUT NEEDS-PAINT
child 3: RenderConstrainedBox#ed89d NEEDS-LAYOUT NEEDS-PAINT
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: RenderBox was not laid out: RenderCustomMultiChildLayoutBox#71e82 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
Another exception was thrown: Updated layout information required for RenderConstrainedBox#7ee0d NEEDS-LAYOUT NEEDS-PAINT to calculate semantics.
The Flutter DevTools debugger and profiler on Linux is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:35461/Le6dWbqzasA=/
Another exception was thrown: 'package:flutter/src/widgets/binding.dart': Failed assertion: line 842 pos 14: '!_firstFrameCompleter.isCompleted': is not true. |
It seems like a documentation issue. Looking into the source
As expected
|
fixes #115898 `hasChild` checks `_idToChild` map. `_idToChild` is not assigned until `_callPerformLayout` is called. So `hasChild` shouldn't be called in `getSize`. https://github.com/flutter/flutter/blob/df789c9e76098e82f80f2c5de8b5560f360afa40/packages/flutter/lib/src/rendering/custom_layout.dart#L400-L404 Updated docs and example class names.
fixes flutter#115898 `hasChild` checks `_idToChild` map. `_idToChild` is not assigned until `_callPerformLayout` is called. So `hasChild` shouldn't be called in `getSize`. https://github.com/flutter/flutter/blob/df789c9e76098e82f80f2c5de8b5560f360afa40/packages/flutter/lib/src/rendering/custom_layout.dart#L400-L404 Updated docs and example class names.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
flutter run
on the code sampleExpected results: Calling hasChild in getSize returns normally.
Actual results: Calling hasChild in getSize throws an exception.
Code sample
Logs
Not sure if I am not supposed to call hasChild during getSize. But since the documentation clearly states that this may be done
I assume this is either an issue with the documentation or with the framework.
The text was updated successfully, but these errors were encountered: