File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 7
7
8
8
import 'dart:ui' show TextDirection;
9
9
10
+ import 'package:flutter/foundation.dart' ;
10
11
import 'package:flutter/services.dart' show SystemChannels;
11
12
12
13
import 'semantics_event.dart' show AnnounceSemanticsEvent, Assertiveness, TooltipSemanticsEvent;
@@ -33,6 +34,9 @@ abstract final class SemanticsService {
33
34
/// Currently, this is only supported by the web engine and has no effect on
34
35
/// other platforms. The default mode is [Assertiveness.polite] .
35
36
///
37
+ /// Not all platforms support announcements. Check to see if
38
+ /// [isAnnounceSupported] before calling this method.
39
+ ///
36
40
/// ### Android
37
41
/// Android has [deprecated announcement events][1] due to its disruptive
38
42
/// behavior with TalkBack forcing it to clear its speech queue and speak the
@@ -62,4 +66,12 @@ abstract final class SemanticsService {
62
66
final TooltipSemanticsEvent event = TooltipSemanticsEvent (message);
63
67
await SystemChannels .accessibility.send (event.toMap ());
64
68
}
69
+
70
+ /// Checks if announce is supported on the given platform.
71
+ ///
72
+ /// On Android the announce method is deprecated, therefore will return false.
73
+ /// On other platforms, this will return true.
74
+ static bool isAnnounceSupported () {
75
+ return defaultTargetPlatform != TargetPlatform .android;
76
+ }
65
77
}
Original file line number Diff line number Diff line change 2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ import 'package:flutter/foundation.dart' ;
5
6
import 'package:flutter/semantics.dart' ;
6
- import 'package:flutter/services.dart' show SystemChannels;
7
+ import 'package:flutter/services.dart' show SystemChannels, TargetPlatform ;
7
8
import 'package:flutter_test/flutter_test.dart' ;
8
9
9
10
void main () {
@@ -44,4 +45,12 @@ void main() {
44
45
]),
45
46
);
46
47
});
48
+
49
+ for (final TargetPlatform platform in TargetPlatform .values) {
50
+ test ('Announce not supported on Android. (platform=$platform )' , () {
51
+ debugDefaultTargetPlatformOverride = platform;
52
+ expect (SemanticsService .isAnnounceSupported (), platform != TargetPlatform .android);
53
+ debugDefaultTargetPlatformOverride = null ;
54
+ });
55
+ }
47
56
}
You can’t perform that action at this time.
0 commit comments