mirror of
https://github.com/block/buzz.git
synced 2026-11-02 07:22:55 +00:00
Updates mobile toast animations and styling. | Sign in | Retry | Copied | | --- | --- | --- | |  |  |  | --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
30 lines
969 B
Dart
30 lines
969 B
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
/// The outcome communicated by a notice, independent of its wording.
|
|
enum ToastKind { generic, success, error }
|
|
|
|
/// Plays outcome-specific feedback without blocking the notice.
|
|
Future<void> toastHaptic(ToastKind kind) async {
|
|
try {
|
|
if (kind != ToastKind.generic &&
|
|
!kIsWeb &&
|
|
defaultTargetPlatform == TargetPlatform.iOS) {
|
|
await const MethodChannel('buzz/haptics').invokeMethod<void>(kind.name);
|
|
return;
|
|
}
|
|
switch (kind) {
|
|
case ToastKind.generic:
|
|
await HapticFeedback.lightImpact();
|
|
case ToastKind.success:
|
|
await HapticFeedback.mediumImpact();
|
|
case ToastKind.error:
|
|
await HapticFeedback.heavyImpact();
|
|
}
|
|
} on PlatformException {
|
|
// Haptics are optional; feedback must still be displayed.
|
|
} on MissingPluginException {
|
|
// Some platforms and test embedders do not provide haptics.
|
|
}
|
|
}
|