1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:ui' show TextDirection;
6
7import 'package:flutter/services.dart' show SystemChannels;
8
9import 'semantics_event.dart' show AnnounceSemanticsEvent, Assertiveness, TooltipSemanticsEvent;
10
11export 'dart:ui' show TextDirection;
12
13/// Allows access to the platform's accessibility services.
14///
15/// Events sent by this service are handled by the platform-specific
16/// accessibility bridge in Flutter's engine.
17///
18/// When possible, prefer using mechanisms like [Semantics] to implicitly
19/// trigger announcements over using this event.
20abstract final class SemanticsService {
21 /// Sends a semantic announcement.
22 ///
23 /// This should be used for announcement that are not seamlessly announced by
24 /// the system as a result of a UI state change.
25 ///
26 /// For example a camera application can use this method to make accessibility
27 /// announcements regarding objects in the viewfinder.
28 ///
29 /// The assertiveness level of the announcement is determined by [assertiveness].
30 /// Currently, this is only supported by the web engine and has no effect on
31 /// other platforms. The default mode is [Assertiveness.polite].
32 static Future<void> announce(String message, TextDirection textDirection, {Assertiveness assertiveness = Assertiveness.polite}) async {
33 final AnnounceSemanticsEvent event = AnnounceSemanticsEvent(message, textDirection, assertiveness: assertiveness);
34 await SystemChannels.accessibility.send(event.toMap());
35 }
36
37 /// Sends a semantic announcement of a tooltip.
38 ///
39 /// Currently only honored on Android. The contents of [message] will be
40 /// read by TalkBack.
41 static Future<void> tooltip(String message) async {
42 final TooltipSemanticsEvent event = TooltipSemanticsEvent(message);
43 await SystemChannels.accessibility.send(event.toMap());
44 }
45}
46