Skip to content

Commit 254a37e

Browse files
[cupertino_ui] Localize CupertinoActionSheet semantics label (flutter#13377)
`CupertinoActionSheet` wraps its content in a `Semantics` node that names and scopes the route, labelled with the hardcoded string `'Alert'`. Because this node names the route, apps can't override the label, so VoiceOver announces "Alert" in English whatever the app's locale. This PR uses `CupertinoLocalizations.of(context).alertDialogLabel` instead. `CupertinoAlertDialog` in the same file already does this, and every `cupertino_*.arb` file already translates the key (e.g. `"Alerta"` for `pt`). The English default is still `'Alert'`, so the existing semantics test is unchanged. Note: `CupertinoActionSheet` now looks up `CupertinoLocalizations`, so it needs a localizations ancestor, which `CupertinoApp` provides. `CupertinoAlertDialog` already has this requirement. Changes: - `lib/src/dialog.dart`: use the localized `alertDialogLabel` for the action sheet's semantics label. - `test/action_sheet_test.dart`: add a regression test that shows an action sheet under the `pt` locale and checks that the dialog semantics node is labelled "Alerta". The test fails before this change and passes after it. - `pending_changelogs/localize_action_sheet_semantics_label.yaml`: patch-level changelog entry, following the package's batch release process. Fixes flutter/flutter#195019 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 0f29291 commit 254a37e

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎packages/cupertino_ui/lib/src/dialog.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ class _CupertinoActionSheetState extends State<CupertinoActionSheet> {
13721372
scopesRoute: true,
13731373
explicitChildNodes: true,
13741374
role: SemanticsRole.dialog,
1375-
label: 'Alert',
1375+
label: CupertinoLocalizations.of(context).alertDialogLabel,
13761376
child: CupertinoUserInterfaceLevel(
13771377
data: CupertinoUserInterfaceLevelData.elevated,
13781378
child: Padding(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Fixes `CupertinoActionSheet` semantics label not being localized.
3+
version: patch

‎packages/cupertino_ui/test/action_sheet_test.dart‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,47 @@ void main() {
17861786
);
17871787
});
17881788

1789+
testWidgets('Action sheet semantics label is localized', (WidgetTester tester) async {
1790+
// Regression test for https://github.com/flutter/flutter/issues/195019
1791+
await tester.pumpWidget(
1792+
CupertinoApp(
1793+
locale: const Locale('pt'),
1794+
localizationsDelegates: GlobalCupertinoLocalizations.delegates,
1795+
supportedLocales: const <Locale>[Locale('pt')],
1796+
home: Center(
1797+
child: Builder(
1798+
builder: (BuildContext context) {
1799+
return CupertinoButton(
1800+
onPressed: () {
1801+
showCupertinoModalPopup<void>(
1802+
context: context,
1803+
builder: (BuildContext context) {
1804+
return CupertinoActionSheet(
1805+
title: const Text('The title'),
1806+
actions: <Widget>[
1807+
CupertinoActionSheetAction(child: const Text('One'), onPressed: () {}),
1808+
],
1809+
);
1810+
},
1811+
);
1812+
},
1813+
child: const Text('Go'),
1814+
);
1815+
},
1816+
),
1817+
),
1818+
),
1819+
);
1820+
1821+
await tester.tap(find.text('Go'));
1822+
await tester.pumpAndSettle();
1823+
1824+
expect(find.bySemanticsLabel('Alert'), findsNothing);
1825+
final SemanticsNode sheet = tester.semantics.find(find.bySemanticsLabel('Alerta'));
1826+
expect(sheet.role, SemanticsRole.dialog);
1827+
expect(sheet, isSemantics(label: 'Alerta', namesRoute: true, scopesRoute: true));
1828+
});
1829+
17891830
testWidgets('Conflicting scrollbars are not applied by ScrollBehavior to CupertinoActionSheet', (
17901831
WidgetTester tester,
17911832
) async {

0 commit comments

Comments
 (0)