Files
Casha/lib/core/services/haptic_service.dart
T
2026-03-21 09:51:02 +03:00

45 lines
1.1 KiB
Dart

import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
class HapticService {
static const _key = 'haptic_enabled';
static bool _enabled = true; // runtime cache
static Future<void> init() async {
final prefs = await SharedPreferences.getInstance();
_enabled = prefs.getBool(_key) ?? true;
}
static bool get isEnabled => _enabled;
static Future<void> setEnabled(bool value) async {
_enabled = value;
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_key, value);
}
// Light tap — filter chips, toggles, small interactions
static void light() {
if (!_enabled) return;
HapticFeedback.lightImpact();
}
// Medium — confirm button, apply, save
static void medium() {
if (!_enabled) return;
HapticFeedback.mediumImpact();
}
// Heavy — long press on balance card
static void heavy() {
if (!_enabled) return;
HapticFeedback.heavyImpact();
}
// Selection click — switching tabs, filter chips
static void selection() {
if (!_enabled) return;
HapticFeedback.selectionClick();
}
}