Unverified Commit 12659f2a authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `MultiChildLayoutDelegate.hasChild` doc (#126433)

fixes https://github.com/flutter/flutter/issues/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.
parent 42d9a2b3
...@@ -6,10 +6,10 @@ import 'package:flutter/material.dart'; ...@@ -6,10 +6,10 @@ import 'package:flutter/material.dart';
/// Flutter code sample for [CustomMultiChildLayout]. /// Flutter code sample for [CustomMultiChildLayout].
void main() => runApp(const ExampleApp()); void main() => runApp(const CustomMultiChildLayoutApp());
class ExampleApp extends StatelessWidget { class CustomMultiChildLayoutApp extends StatelessWidget {
const ExampleApp({super.key}); const CustomMultiChildLayoutApp({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -19,7 +19,7 @@ class ExampleApp extends StatelessWidget { ...@@ -19,7 +19,7 @@ class ExampleApp extends StatelessWidget {
// see the layout change. // see the layout change.
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Scaffold( child: Scaffold(
body: ExampleWidget(), body: CustomMultiChildLayoutExample(),
), ),
), ),
); );
...@@ -82,8 +82,8 @@ class _CascadeLayoutDelegate extends MultiChildLayoutDelegate { ...@@ -82,8 +82,8 @@ class _CascadeLayoutDelegate extends MultiChildLayoutDelegate {
} }
} }
class ExampleWidget extends StatelessWidget { class CustomMultiChildLayoutExample extends StatelessWidget {
const ExampleWidget({super.key}); const CustomMultiChildLayoutExample({super.key});
static const Map<String, Color> _colors = <String, Color>{ static const Map<String, Color> _colors = <String, Color>{
'Red': Colors.red, 'Red': Colors.red,
......
...@@ -12,7 +12,7 @@ void main() { ...@@ -12,7 +12,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Scaffold( home: Scaffold(
body: example.ExampleWidget(), body: example.CustomMultiChildLayoutApp(),
), ),
), ),
); );
...@@ -24,7 +24,7 @@ void main() { ...@@ -24,7 +24,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Scaffold( home: Scaffold(
body: example.ExampleWidget(), body: example.CustomMultiChildLayoutExample(),
), ),
), ),
); );
...@@ -40,7 +40,7 @@ void main() { ...@@ -40,7 +40,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Scaffold( home: Scaffold(
body: example.ExampleWidget(), body: example.CustomMultiChildLayoutExample(),
), ),
), ),
); );
......
...@@ -127,9 +127,11 @@ abstract class MultiChildLayoutDelegate { ...@@ -127,9 +127,11 @@ abstract class MultiChildLayoutDelegate {
/// True if a non-null LayoutChild was provided for the specified id. /// True if a non-null LayoutChild was provided for the specified id.
/// ///
/// Call this from the [performLayout] or [getSize] methods to /// Call this from the [performLayout] method to determine which children
/// determine which children are available, if the child list might /// are available, if the child list might vary.
/// vary. ///
/// This method cannot be called from [getSize] as the size is not allowed
/// to depend on the children.
bool hasChild(Object childId) => _idToChild![childId] != null; bool hasChild(Object childId) => _idToChild![childId] != null;
/// Ask the child to update its layout within the limits specified by /// Ask the child to update its layout within the limits specified by
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment