This commit is contained in:
2026-03-21 09:51:02 +03:00
parent 6c5c9944ca
commit 65c31b4076
6 changed files with 146 additions and 3 deletions
+44
View File
@@ -0,0 +1,44 @@
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();
}
}