Skip to content

Commit 9b65985

Browse files
authored
Add more error handling to unawaited callsites (#184526)
Part of flutter/flutter#181513
1 parent 589c16c commit 9b65985

2 files changed

Lines changed: 48 additions & 5 deletions

File tree

packages/flutter/lib/src/material/calendar_date_picker.dart

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
244244
// Auxiliary method for handling the difference between platforms
245245
void _announce(String message) {
246246
if (MediaQuery.maybeSupportsAnnounceOf(context) ?? false) {
247-
SemanticsService.sendAnnouncement(View.of(context), message, Directionality.of(context));
247+
SemanticsService.sendAnnouncement(
248+
View.of(context),
249+
message,
250+
Directionality.of(context),
251+
).catchError(_reportAnnouncementError);
248252
} else {
249253
// If SemanticsService.sendAnnouncement is not supported,
250254
// we use live region to achieve the announcement effect instead.
@@ -328,7 +332,7 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
328332
View.of(context),
329333
'${_localizations.selectedDateLabel} ${widget.calendarDelegate.formatFullDate(_selectedDate!, _localizations)}$semanticLabelSuffix',
330334
_textDirection,
331-
);
335+
).catchError(_reportAnnouncementError);
332336
case TargetPlatform.android:
333337
case TargetPlatform.iOS:
334338
case TargetPlatform.fuchsia:
@@ -675,7 +679,11 @@ class _MonthPickerState extends State<_MonthPicker> {
675679
// Auxiliary method for handling the difference between platforms
676680
void _announce(String message) {
677681
if (MediaQuery.maybeSupportsAnnounceOf(context) ?? false) {
678-
SemanticsService.sendAnnouncement(View.of(context), message, Directionality.of(context));
682+
SemanticsService.sendAnnouncement(
683+
View.of(context),
684+
message,
685+
Directionality.of(context),
686+
).catchError(_reportAnnouncementError);
679687
} else {
680688
// If SemanticsService.sendAnnouncement is not supported,
681689
// we use live region to achieve the announcement effect instead.
@@ -1635,3 +1643,14 @@ class _YearPickerGridDelegate extends SliverGridDelegate {
16351643
@override
16361644
bool shouldRelayout(_YearPickerGridDelegate oldDelegate) => false;
16371645
}
1646+
1647+
void _reportAnnouncementError(Object exception, StackTrace stack) {
1648+
FlutterError.reportError(
1649+
FlutterErrorDetails(
1650+
exception: exception,
1651+
stack: stack,
1652+
library: 'material library',
1653+
context: ErrorDescription('while sending semantics announcement'),
1654+
),
1655+
);
1656+
}

packages/flutter/lib/src/material/expansion_tile.dart

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,15 +557,39 @@ class _ExpansionTileState extends State<ExpansionTile> {
557557
// semantic announcements on iOS. https://github.com/flutter/flutter/issues/122101.
558558
_timer?.cancel();
559559
_timer = Timer(const Duration(seconds: 1), () {
560-
SemanticsService.sendAnnouncement(View.of(context), stateHint, textDirection);
560+
SemanticsService.sendAnnouncement(View.of(context), stateHint, textDirection).catchError((
561+
Object exception,
562+
StackTrace stack,
563+
) {
564+
FlutterError.reportError(
565+
FlutterErrorDetails(
566+
exception: exception,
567+
stack: stack,
568+
library: 'material library',
569+
context: ErrorDescription('while sending semantics announcement'),
570+
),
571+
);
572+
});
561573
_timer?.cancel();
562574
_timer = null;
563575
});
564576
}
565577
// SemanticsService.sendAnnouncement is deprecated on android.
566578
// We use live region to achieve the announcement effect instead.
567579
else if (defaultTargetPlatform != TargetPlatform.android) {
568-
SemanticsService.sendAnnouncement(View.of(context), stateHint, textDirection);
580+
SemanticsService.sendAnnouncement(View.of(context), stateHint, textDirection).catchError((
581+
Object exception,
582+
StackTrace stack,
583+
) {
584+
FlutterError.reportError(
585+
FlutterErrorDetails(
586+
exception: exception,
587+
stack: stack,
588+
library: 'material library',
589+
context: ErrorDescription('while sending semantics announcement'),
590+
),
591+
);
592+
});
569593
}
570594
widget.onExpansionChanged?.call(_tileController.isExpanded);
571595
}

0 commit comments

Comments
 (0)