diff --git a/packages/flutter/lib/fix_data.yaml b/packages/flutter/lib/fix_data.yaml index 65b821ce28..55fe739e63 100644 --- a/packages/flutter/lib/fix_data.yaml +++ b/packages/flutter/lib/fix_data.yaml @@ -11,6 +11,26 @@ version: 1 transforms: + # Changes made in https://github.com/flutter/flutter/pull/15303 + - title: 'Replace child with builder' + date: 2020-12-17 + element: + uris: [ 'material.dart' ] + function: 'showDialog' + changes: + - kind: 'addParameter' + index: 0 + name: 'builder' + style: optional_named + argumentValue: + expression: '(context) => {% widget %}' + requiredIf: "widget != ''" + variables: + widget: + kind: fragment + value: 'arguments[child]' + - kind: 'removeParameter' + name: 'child' # Changes made in https://github.com/flutter/flutter/pull/28602 - title: 'Rename to fromMouseEvent' date: 2020-12-15 @@ -33,7 +53,6 @@ transforms: - kind: 'rename' newName: 'fromMouseEvent' - # Changes made in https://github.com/flutter/flutter/pull/41859 - title: 'Remove brightness' date: 2020-12-10 diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index c9d406a832..2f931a564f 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -967,16 +967,8 @@ Future showDialog({ bool useSafeArea = true, bool useRootNavigator = true, RouteSettings? routeSettings, - @Deprecated( - 'Instead of using the "child" argument, return the child from a closure ' - 'provided to the "builder" argument. This will ensure that the BuildContext ' - 'is appropriate for widgets built in the dialog. ' - 'This feature was deprecated after v0.2.3.' - ) - Widget? child, }) { - assert(child == null || builder == null); - assert(child != null || builder != null); + assert(builder != null); assert(barrierDismissible != null); assert(useSafeArea != null); assert(useRootNavigator != null); @@ -986,7 +978,7 @@ Future showDialog({ return showGeneralDialog( context: context, pageBuilder: (BuildContext buildContext, Animation animation, Animation secondaryAnimation) { - final Widget pageChild = child ?? Builder(builder: builder!); + final Widget pageChild = Builder(builder: builder!); Widget dialog = themes.wrap(pageChild); if (useSafeArea) { dialog = SafeArea(child: dialog); diff --git a/packages/flutter/test/material/dialog_test.dart b/packages/flutter/test/material/dialog_test.dart index 2e29042af5..fdf64ecb81 100644 --- a/packages/flutter/test/material/dialog_test.dart +++ b/packages/flutter/test/material/dialog_test.dart @@ -217,35 +217,7 @@ void main() { expect(materialWidget.shape, customBorder); }); - testWidgets('showDialog child and builder cannot be simultaneously defined', (WidgetTester tester) async { - late BuildContext currentBuildContext; - await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: Center( - child: Builder( - builder: (BuildContext context) { - currentBuildContext = context; - return Container(); - } - ), - ), - ), - ), - ); - - expect(() async { - showDialog( - context: currentBuildContext, - child: const Text('Child'), - builder: (BuildContext context) { - return const Text('Builder'); - }, - ); - }, throwsAssertionError); - }); - - testWidgets('showDialog child or builder must be defined', (WidgetTester tester) async { + testWidgets('showDialog builder must be defined', (WidgetTester tester) async { late BuildContext currentBuildContext; await tester.pumpWidget( MaterialApp( diff --git a/packages/flutter/test_fixes/material.dart b/packages/flutter/test_fixes/material.dart new file mode 100644 index 0000000000..eb7868cd23 --- /dev/null +++ b/packages/flutter/test_fixes/material.dart @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; + +void main() { + // Change made in https://github.com/flutter/flutter/pull/15303 + showDialog(child: Text('Fix me.')); +} diff --git a/packages/flutter/test_fixes/material.dart.expect b/packages/flutter/test_fixes/material.dart.expect new file mode 100644 index 0000000000..d21d0db8de --- /dev/null +++ b/packages/flutter/test_fixes/material.dart.expect @@ -0,0 +1,10 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; + +void main() { + // Change made in https://github.com/flutter/flutter/pull/15303 + showDialog(builder: (context) => Text('Fix me.')); +}