Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add barrierColor property to showCupertinoDialog #166911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/flutter/lib/src/cupertino/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,7 @@ Future<T?> showCupertinoDialog<T>({
required BuildContext context,
required WidgetBuilder builder,
String? barrierLabel,
Color? barrierColor,
bool useRootNavigator = true,
bool barrierDismissible = false,
RouteSettings? routeSettings,
Expand All @@ -1422,7 +1423,7 @@ Future<T?> showCupertinoDialog<T>({
context: context,
barrierDismissible: barrierDismissible,
barrierLabel: barrierLabel,
barrierColor: CupertinoDynamicColor.resolve(kCupertinoModalBarrierColor, context),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should be barrierColor ?? CupertinoDynamicColor.resolve(kCupertinoModalBarrierColor, context)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be because CupertinoDialogRoute's barrierColor defaults to the same value.

Copy link
Contributor Author

@masal9pse masal9pse Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be because CupertinoDialogRoute's barrierColor defaults to the same value.

Yes, that’s the reason it was removed.

barrierColor: barrierColor,
settings: routeSettings,
anchorPoint: anchorPoint,
requestFocus: requestFocus,
Expand Down
54 changes: 54 additions & 0 deletions packages/flutter/test/cupertino/dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,60 @@ void main() {
semantics.dispose();
});

testWidgets('showCupertinoDialog - custom barrierColor', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
home: Builder(
builder: (BuildContext context) {
return Center(
child: Column(
children: <Widget>[
CupertinoButton(
child: const Text('Custom BarrierColor'),
onPressed: () {
showCupertinoDialog<void>(
context: context,
barrierColor: Colors.red,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: const Text('Title'),
content: const Text('Content'),
actions: <Widget>[
const CupertinoDialogAction(child: Text('Yes')),
CupertinoDialogAction(
child: const Text('No'),
onPressed: () {
Navigator.pop(context);
},
),
],
);
},
);
},
),
],
),
);
},
),
),
);

await tester.tap(find.text('Custom BarrierColor'));
await tester.pumpAndSettle();
expect(tester.widget<ModalBarrier>(find.byType(ModalBarrier).last).color, equals(Colors.red));

await tester.tap(find.text('No'));
await tester.pumpAndSettle();
expect(
find.byWidgetPredicate(
(Widget widget) => widget is ModalBarrier && widget.color == Colors.red,
),
findsNothing,
);
});

testWidgets('CupertinoDialogRoute is state restorable', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(restorationScopeId: 'app', home: _RestorableDialogTestWidget()),
Expand Down