showDialog assertion for non-null builder or child property (#71838)
This commit is contained in:
parent
995aa138cd
commit
2cb652600c
@ -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() {
|
|||||||
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(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user