Unverified Commit 2cb65260 authored by Amit Patil's avatar Amit Patil Committed by GitHub

showDialog assertion for non-null builder or child property (#71838)

parent 995aa138
...@@ -973,6 +973,7 @@ Future<T?> showDialog<T>({ ...@@ -973,6 +973,7 @@ Future<T?> showDialog<T>({
Widget? child, Widget? child,
}) { }) {
assert(child == null || builder == null); assert(child == null || builder == null);
assert(child != null || builder != null);
assert(barrierDismissible != null); assert(barrierDismissible != null);
assert(useSafeArea != null); assert(useSafeArea != null);
assert(useRootNavigator != null); assert(useRootNavigator != null);
......
...@@ -217,6 +217,57 @@ void main() { ...@@ -217,6 +217,57 @@ void main() {
expect(materialWidget.shape, customBorder); 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<void>(
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 {
late BuildContext currentBuildContext;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: Builder(
builder: (BuildContext context) {
currentBuildContext = context;
return Container();
}
),
),
),
),
);
expect(
() => showDialog<void>(context: currentBuildContext),
throwsAssertionError,
);
});
testWidgets('Simple dialog control test', (WidgetTester tester) async { testWidgets('Simple dialog control test', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
......
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