import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:local_auth/local_auth.dart'; class SettingsController extends ChangeNotifier { bool _vibrationEnabled = true; bool get vibrationEnabled => _vibrationEnabled; bool _biometricEnabled = false; bool get biometricEnabled => _biometricEnabled; bool _adsEnabled = true; bool get adsEnabled => _adsEnabled; final LocalAuthentication auth = LocalAuthentication(); late Future initializationFuture; SettingsController() { initializationFuture = _loadSettings(); } Future _loadSettings() async { final prefs = await SharedPreferences.getInstance(); _vibrationEnabled = prefs.getBool('vibration_enabled') ?? true; _biometricEnabled = prefs.getBool('biometric_enabled') ?? false; _adsEnabled = prefs.getBool('ads_enabled') ?? true; notifyListeners(); } Future toggleVibration(bool value) async { _vibrationEnabled = value; final prefs = await SharedPreferences.getInstance(); await prefs.setBool('vibration_enabled', value); notifyListeners(); } Future toggleBiometric(bool value) async { _biometricEnabled = value; final prefs = await SharedPreferences.getInstance(); await prefs.setBool('biometric_enabled', value); notifyListeners(); } Future toggleAds(bool value) async { _adsEnabled = value; final prefs = await SharedPreferences.getInstance(); await prefs.setBool('ads_enabled', value); notifyListeners(); } Future checkSecurity() async { await initializationFuture; if (!_biometricEnabled) return true; bool canCheck = await auth.canCheckBiometrics; bool isSupported = await auth.isDeviceSupported(); if (!canCheck && !isSupported) return true; try { return await auth.authenticate( localizedReason: 'Unlock QuickSSH', biometricOnly: false, ); } catch (e) { return false; } } }