| 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 | |
| 5 | import 'system_channels.dart'; |
| 6 | |
| 7 | /// A sound provided by the system. |
| 8 | /// |
| 9 | /// These sounds may be played with [SystemSound.play]. |
| 10 | enum SystemSoundType { |
| 11 | /// A short indication that a button was pressed. |
| 12 | click, |
| 13 | |
| 14 | /// A short indication that a picker value was changed. |
| 15 | /// |
| 16 | /// This is ignored on all platforms except iOS. |
| 17 | tick, |
| 18 | |
| 19 | /// A short system alert sound indicating the need for user attention. |
| 20 | /// |
| 21 | /// Desktop platforms are the only platforms that support a system alert |
| 22 | /// sound, so on mobile platforms (Android, iOS), this will be ignored. The |
| 23 | /// web platform does not support playing any sounds, so this will be |
| 24 | /// ignored on the web as well. |
| 25 | alert, |
| 26 | |
| 27 | // If you add new values here, you also need to update: |
| 28 | // - the `SoundType` Java enum in `PlatformChannel.java` (Android); |
| 29 | // - `FlutterPlatformPlugin.mm` (iOS); |
| 30 | // - `FlutterPlatformPlugin.mm` (macOS); |
| 31 | // - `fl_platform_handler.cc` (Linux); |
| 32 | // - `platform_handler.cc` (Windows); |
| 33 | } |
| 34 | |
| 35 | /// Provides access to the library of short system specific sounds for common |
| 36 | /// tasks. |
| 37 | abstract final class SystemSound { |
| 38 | /// Play the specified system sound. If that sound is not present on the |
| 39 | /// system, the call is ignored. |
| 40 | /// |
| 41 | /// The web platform currently does not support playing sounds, so this call |
| 42 | /// will yield no behavior on that platform. |
| 43 | static Future<void> play(SystemSoundType type) async { |
| 44 | await SystemChannels.platform.invokeMethod<void>('SystemSound.play' , type.toString()); |
| 45 | } |
| 46 | } |
| 47 | |