import 'package:flutter/services.dart'; import 'dart:io' show Platform; /// 햅틱 피드백을 관리하는 헬퍼 클래스 class HapticFeedbackHelper { static bool _isEnabled = true; /// 햅틱 피드백 활성화 여부 설정 static void setEnabled(bool enabled) { _isEnabled = enabled; } /// 가벼운 햅틱 피드백 static Future lightImpact() async { if (!_isEnabled || !_isPlatformSupported()) return; await HapticFeedback.lightImpact(); } /// 중간 강도 햅틱 피드백 static Future mediumImpact() async { if (!_isEnabled || !_isPlatformSupported()) return; await HapticFeedback.mediumImpact(); } /// 강한 햅틱 피드백 static Future heavyImpact() async { if (!_isEnabled || !_isPlatformSupported()) return; await HapticFeedback.heavyImpact(); } /// 선택 햅틱 피드백 (iOS의 경우 Taptic Engine) static Future selectionClick() async { if (!_isEnabled || !_isPlatformSupported()) return; await HapticFeedback.selectionClick(); } /// 진동 패턴 (Android) static Future vibrate({int duration = 50}) async { if (!_isEnabled || !_isPlatformSupported()) return; await HapticFeedback.vibrate(); } /// 성공 피드백 패턴 static Future success() async { if (!_isEnabled || !_isPlatformSupported()) return; await HapticFeedback.mediumImpact(); await Future.delayed(const Duration(milliseconds: 100)); await HapticFeedback.lightImpact(); } /// 에러 피드백 패턴 static Future error() async { if (!_isEnabled || !_isPlatformSupported()) return; await HapticFeedback.heavyImpact(); await Future.delayed(const Duration(milliseconds: 100)); await HapticFeedback.heavyImpact(); } /// 경고 피드백 패턴 static Future warning() async { if (!_isEnabled || !_isPlatformSupported()) return; await HapticFeedback.mediumImpact(); } /// 플랫폼이 햅틱 피드백을 지원하는지 확인 static bool _isPlatformSupported() { try { return Platform.isIOS || Platform.isAndroid; } catch (e) { // 웹이나 데스크톱에서는 Platform을 사용할 수 없음 return false; } } }