From 5944d992ac403612c599d44b9a5eea62ce7ebc8a Mon Sep 17 00:00:00 2001 From: dev-lup Date: Thu, 6 Feb 2025 10:14:19 -0800 Subject: [PATCH] Fix: Ensure CupertinoAlertDialog divider spans full width and resolve (#161490) Fix: Ensure CupertinoAlertDialog divider spans full width and resolves divider color (#158522) The `_Divider` in CupertinoAlertDialog did not span the full width and the `dividerColor` was not resolved correctly. This fix uses a `SizedBox` with `double.infinity` as the width for the divider and ensures that the `dividerColor` is properly applied. Fixes #158522 *Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Harshit Sharma Co-authored-by: Tong Mu Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com> --- .../flutter/lib/src/cupertino/dialog.dart | 11 ++++- .../flutter/test/cupertino/dialog_test.dart | 44 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/dialog.dart b/packages/flutter/lib/src/cupertino/dialog.dart index 1d71ebeaab..c2deec75e8 100644 --- a/packages/flutter/lib/src/cupertino/dialog.dart +++ b/packages/flutter/lib/src/cupertino/dialog.dart @@ -372,7 +372,7 @@ class _CupertinoAlertDialogState extends State { Widget _buildBody(BuildContext context) { final Color backgroundColor = CupertinoDynamicColor.resolve(_kDialogColor, context); - const Color dividerColor = CupertinoColors.separator; + final Color dividerColor = CupertinoDynamicColor.resolve(CupertinoColors.separator, context); // Remove view padding here because the `Scrollbar` widget uses the view // padding as padding, which is unwanted. // https://github.com/flutter/flutter/issues/150544 @@ -407,7 +407,14 @@ class _CupertinoAlertDialogState extends State { top: contentSection, bottom: Column( children: [ - _Divider(dividerColor: dividerColor, hiddenColor: backgroundColor, hidden: false), + SizedBox( + width: double.infinity, + child: _Divider( + dividerColor: dividerColor, + hiddenColor: backgroundColor, + hidden: false, + ), + ), Flexible(child: scrolledActionsSection), ], ), diff --git a/packages/flutter/test/cupertino/dialog_test.dart b/packages/flutter/test/cupertino/dialog_test.dart index 3046d85a44..96bbcc16e9 100644 --- a/packages/flutter/test/cupertino/dialog_test.dart +++ b/packages/flutter/test/cupertino/dialog_test.dart @@ -1988,6 +1988,50 @@ void main() { kIsWeb ? SystemMouseCursors.click : SystemMouseCursors.basic, ); }); + + testWidgets('CupertinoAlertDialog divider spans full width and applies color', ( + WidgetTester tester, + ) async { + const double kCupertinoDialogWidth = 270.0; + const double kDividerThickness = 0.3; + const Size expectedSize = Size(kCupertinoDialogWidth, kDividerThickness); + + await tester.pumpWidget( + CupertinoApp( + home: MediaQuery( + data: const MediaQueryData(platformBrightness: Brightness.dark), + child: CupertinoAlertDialog( + title: const Text('The Title'), + content: const Text('Content'), + actions: [ + CupertinoDialogAction( + isDefaultAction: true, + onPressed: () {}, + child: const Text('Cancel'), + ), + const CupertinoDialogAction(child: Text('OK')), + ], + ), + ), + ), + ); + + final Finder decoratedBoxFinder = find.byType(DecoratedBox); + + expect(decoratedBoxFinder, findsAny, reason: 'There should exist at least one DecoratedBox'); + + final Iterable elements = decoratedBoxFinder.evaluate().where(( + Element decoratedBoxElement, + ) { + final DecoratedBox decoratedBox = decoratedBoxElement.widget as DecoratedBox; + return (decoratedBox.decoration is BoxDecoration?) && + (decoratedBox.decoration as BoxDecoration?)?.color == + CupertinoDynamicColor.resolve(CupertinoColors.separator, decoratedBoxElement) && + tester.getSize(find.byWidget(decoratedBox)) == expectedSize; + }); + + expect(elements.length, 1, reason: 'No DecoratedBox matches the specified criteria.'); + }); } RenderBox findActionButtonRenderBoxByTitle(WidgetTester tester, String title) {