From eed999d2ab7b69616dad3bcf8e40528ffefc29d7 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Feb 2026 16:42:40 +0100 Subject: [PATCH] fixed vibration switch --- lib/main.dart | 1 - lib/screens/settings.dart | 188 +++++++++--------- lib/services/settings_controller.dart | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 56 ++++++ pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 8 files changed, 162 insertions(+), 91 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 60ba752..2f3ef60 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'screens/home_screen.dart'; import 'package:QuickSSH/classes/theme_provider.dart'; import 'package:QuickSSH/services/theme_controller.dart'; -import 'package:QuickSSH/services/settings_controller.dart'; final themeController = ThemeController(); final settingsController = SettingsController(); diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 9ea9838..d84b621 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -13,105 +13,113 @@ class _SettingsState extends State { @override Widget build(BuildContext context) { final theme = Theme.of(context).colorScheme; - return Scaffold( - appBar: AppBar( - backgroundColor: theme.surface, - title: Text("Settings", style: TextStyle(color: theme.onSurface)), - leading: Builder( - builder: (context) { - return IconButton( - icon: Icon(Icons.arrow_back_ios_rounded, color: theme.onSurface), - onPressed: () { - Navigator.pop(context); + return ListenableBuilder( + listenable: settingsController, + builder: (context, child) { + return Scaffold( + appBar: AppBar( + backgroundColor: theme.surface, + title: Text("Settings", style: TextStyle(color: theme.onSurface)), + leading: Builder( + builder: (context) { + return IconButton( + icon: Icon( + Icons.arrow_back_ios_rounded, + color: theme.onSurface, + ), + onPressed: () { + Navigator.pop(context); + }, + ); }, - ); - }, - ), - ), - body: Padding( - padding: const EdgeInsets.symmetric(horizontal: 20.0), - child: Column( - children: [ - Row( + ), + ), + body: Padding( + padding: const EdgeInsets.symmetric(horizontal: 20.0), + child: Column( children: [ - Expanded( - child: Text( - "Appearance", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20, - color: theme.onSurface, + Row( + children: [ + Expanded( + child: Text( + "Appearance", + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 20, + color: theme.onSurface, + ), + ), ), - ), + Expanded( + child: Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, + vertical: 4, + ), + decoration: BoxDecoration( + color: theme.primaryContainer, + borderRadius: BorderRadius.circular(16), + ), + child: DropdownButton( + value: themeController.themeMode, + underline: Container(), + items: const [ + DropdownMenuItem( + value: ThemeMode.system, + child: Text("System Default"), + ), + DropdownMenuItem( + value: ThemeMode.dark, + child: Text("Dark"), + ), + DropdownMenuItem( + value: ThemeMode.light, + child: Text("Light"), + ), + ], + onChanged: (ThemeMode? newMode) { + themeController.updateTheme(newMode); + setState(() {}); + }, + ), + ), + ), + ], ), - Expanded( - child: Container( - padding: const EdgeInsets.symmetric( - horizontal: 12, - vertical: 4, - ), - decoration: BoxDecoration( - color: theme.primaryContainer, - borderRadius: BorderRadius.circular(16), - ), - child: DropdownButton( - value: themeController.themeMode, - underline: Container(), - items: const [ - DropdownMenuItem( - value: ThemeMode.system, - child: Text("System Default"), + SizedBox(height: 20), + Row( + children: [ + Expanded( + child: Text( + "Vibrations", + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 20, + color: theme.onSurface, ), - DropdownMenuItem( - value: ThemeMode.dark, - child: Text("Dark"), - ), - DropdownMenuItem( - value: ThemeMode.light, - child: Text("Light"), - ), - ], - onChanged: (ThemeMode? newMode) { - themeController.updateTheme(newMode); - setState(() {}); - }, + ), ), - ), + Expanded( + child: Switch( + activeTrackColor: theme.primary, + activeThumbColor: theme.onPrimary, + inactiveThumbColor: theme.onSurface, + inactiveTrackColor: theme.surface, + value: settingsController.vibrationEnabled, + onChanged: (bool value) { + settingsController.toggleVibration(value); + if (value) HapticFeedback.mediumImpact(); + setState(() {}); + }, + ), + ), + ], ), ], ), - SizedBox(height: 20), - Row( - children: [ - Expanded( - child: Text( - "Vibrations", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20, - color: theme.onSurface, - ), - ), - ), - Expanded( - child: Switch( - activeTrackColor: theme.primary, - activeThumbColor: theme.onPrimary, - inactiveThumbColor: theme.onSurface, - inactiveTrackColor: theme.surface, - value: settingsController.vibrationEnabled, - onChanged: (bool value) { - settingsController.toggleVibration(value); - if (value) HapticFeedback.mediumImpact(); - setState(() {}); - }, - ), - ), - ], - ), - ], - ), - ), + ), + ); + }, ); } } diff --git a/lib/services/settings_controller.dart b/lib/services/settings_controller.dart index b73f232..3d2a9af 100644 --- a/lib/services/settings_controller.dart +++ b/lib/services/settings_controller.dart @@ -16,6 +16,7 @@ class SettingsController extends ChangeNotifier { } Future toggleVibration(bool value) async { + print("Toggling vibration to: $value"); _vibrationEnabled = value; final prefs = await SharedPreferences.getInstance(); await prefs.setBool('vibration_enabled', value); diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 37af1fe..37cc413 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -6,11 +6,13 @@ import FlutterMacOS import Foundation import flutter_secure_storage_macos +import local_auth_darwin import path_provider_foundation import shared_preferences_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin")) + LocalAuthPlugin.register(with: registry.registrar(forPlugin: "LocalAuthPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index d3470dc..9433154 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -158,6 +158,14 @@ packages: url: "https://pub.dev" source: hosted version: "5.0.0" + flutter_plugin_android_lifecycle: + dependency: transitive + description: + name: flutter_plugin_android_lifecycle + sha256: ee8068e0e1cd16c4a82714119918efdeed33b3ba7772c54b5d094ab53f9b7fd1 + url: "https://pub.dev" + source: hosted + version: "2.0.33" flutter_secure_storage: dependency: "direct main" description: @@ -224,6 +232,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.7.2" + intl: + dependency: transitive + description: + name: intl + sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5" + url: "https://pub.dev" + source: hosted + version: "0.20.2" js: dependency: transitive description: @@ -272,6 +288,46 @@ packages: url: "https://pub.dev" source: hosted version: "5.1.1" + local_auth: + dependency: "direct main" + description: + name: local_auth + sha256: "434d854cf478f17f12ab29a76a02b3067f86a63a6d6c4eb8fbfdcfe4879c1b7b" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + local_auth_android: + dependency: transitive + description: + name: local_auth_android + sha256: a0bdfcc0607050a26ef5b31d6b4b254581c3d3ce3c1816ab4d4f4a9173e84467 + url: "https://pub.dev" + source: hosted + version: "1.0.56" + local_auth_darwin: + dependency: transitive + description: + name: local_auth_darwin + sha256: "699873970067a40ef2f2c09b4c72eb1cfef64224ef041b3df9fdc5c4c1f91f49" + url: "https://pub.dev" + source: hosted + version: "1.6.1" + local_auth_platform_interface: + dependency: transitive + description: + name: local_auth_platform_interface + sha256: f98b8e388588583d3f781f6806e4f4c9f9e189d898d27f0c249b93a1973dd122 + url: "https://pub.dev" + source: hosted + version: "1.1.0" + local_auth_windows: + dependency: transitive + description: + name: local_auth_windows + sha256: bc4e66a29b0fdf751aafbec923b5bed7ad6ed3614875d8151afe2578520b2ab5 + url: "https://pub.dev" + source: hosted + version: "1.0.11" matcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5317cf3..f417d4e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,6 +33,7 @@ dependencies: shared_preferences: ^2.5.0 dartssh2: ^2.0.0 flutter_secure_storage: ^9.2.2 + local_auth: ^2.3.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 0c50753..011734d 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -7,8 +7,11 @@ #include "generated_plugin_registrant.h" #include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { FlutterSecureStorageWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); + LocalAuthPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("LocalAuthPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 4fc759c..11485fc 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST flutter_secure_storage_windows + local_auth_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST