Skip to content

Commit 12659f2

Browse files
authored
Fix MultiChildLayoutDelegate.hasChild doc (#126433)
fixes flutter/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.
1 parent 42d9a2b commit 12659f2

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

examples/api/lib/widgets/basic/custom_multi_child_layout.0.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import 'package:flutter/material.dart';
66

77
/// Flutter code sample for [CustomMultiChildLayout].
88
9-
void main() => runApp(const ExampleApp());
9+
void main() => runApp(const CustomMultiChildLayoutApp());
1010

11-
class ExampleApp extends StatelessWidget {
12-
const ExampleApp({super.key});
11+
class CustomMultiChildLayoutApp extends StatelessWidget {
12+
const CustomMultiChildLayoutApp({super.key});
1313

1414
@override
1515
Widget build(BuildContext context) {
@@ -19,7 +19,7 @@ class ExampleApp extends StatelessWidget {
1919
// see the layout change.
2020
textDirection: TextDirection.ltr,
2121
child: Scaffold(
22-
body: ExampleWidget(),
22+
body: CustomMultiChildLayoutExample(),
2323
),
2424
),
2525
);
@@ -82,8 +82,8 @@ class _CascadeLayoutDelegate extends MultiChildLayoutDelegate {
8282
}
8383
}
8484

85-
class ExampleWidget extends StatelessWidget {
86-
const ExampleWidget({super.key});
85+
class CustomMultiChildLayoutExample extends StatelessWidget {
86+
const CustomMultiChildLayoutExample({super.key});
8787

8888
static const Map<String, Color> _colors = <String, Color>{
8989
'Red': Colors.red,

examples/api/test/widgets/basic/custom_multi_child_layout.0_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void main() {
1212
await tester.pumpWidget(
1313
const MaterialApp(
1414
home: Scaffold(
15-
body: example.ExampleWidget(),
15+
body: example.CustomMultiChildLayoutApp(),
1616
),
1717
),
1818
);
@@ -24,7 +24,7 @@ void main() {
2424
await tester.pumpWidget(
2525
const MaterialApp(
2626
home: Scaffold(
27-
body: example.ExampleWidget(),
27+
body: example.CustomMultiChildLayoutExample(),
2828
),
2929
),
3030
);
@@ -40,7 +40,7 @@ void main() {
4040
await tester.pumpWidget(
4141
const MaterialApp(
4242
home: Scaffold(
43-
body: example.ExampleWidget(),
43+
body: example.CustomMultiChildLayoutExample(),
4444
),
4545
),
4646
);

packages/flutter/lib/src/rendering/custom_layout.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ abstract class MultiChildLayoutDelegate {
127127

128128
/// True if a non-null LayoutChild was provided for the specified id.
129129
///
130-
/// Call this from the [performLayout] or [getSize] methods to
131-
/// determine which children are available, if the child list might
132-
/// vary.
130+
/// Call this from the [performLayout] method to determine which children
131+
/// are available, if the child list might vary.
132+
///
133+
/// This method cannot be called from [getSize] as the size is not allowed
134+
/// to depend on the children.
133135
bool hasChild(Object childId) => _idToChild![childId] != null;
134136

135137
/// Ask the child to update its layout within the limits specified by

0 commit comments

Comments
 (0)