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

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

*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].

<!-- Links -->
[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 <krishnatrea@gmail.com>
Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
This commit is contained in:
dev-lup 2025-02-06 10:14:19 -08:00 committed by GitHub
parent 0e59f0f64c
commit 5944d992ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 2 deletions

View File

@ -372,7 +372,7 @@ class _CupertinoAlertDialogState extends State<CupertinoAlertDialog> {
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<CupertinoAlertDialog> {
top: contentSection,
bottom: Column(
children: <Widget>[
_Divider(dividerColor: dividerColor, hiddenColor: backgroundColor, hidden: false),
SizedBox(
width: double.infinity,
child: _Divider(
dividerColor: dividerColor,
hiddenColor: backgroundColor,
hidden: false,
),
),
Flexible(child: scrolledActionsSection),
],
),

View File

@ -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: <Widget>[
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<Element> 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) {