added animation toggle
This commit is contained in:
		| @@ -20,15 +20,41 @@ class Settings with ChangeNotifier { | ||||
|  | ||||
|   bool get autoStart => _autoStart; | ||||
|   bool get enableAnimations => _enableAnimations; | ||||
|   set enableAnimations(bool enable) { | ||||
|     _enableAnimations = enable; | ||||
|     notifyListeners(); | ||||
|   } | ||||
|  | ||||
|   void _reset() { | ||||
|     _autoStart = false; | ||||
|   } | ||||
|  | ||||
|   Future<void> setEnableAnimations(bool value) async { | ||||
|     try { | ||||
|       final auth = await _auth.createAuth(); | ||||
|       final response = await http.put( | ||||
|         Uri.parse( | ||||
|           Uri.encodeFull( | ||||
|             '${getBaseUri()}/api/v1/setting?auth=$auth&name=Animations&value=$value', | ||||
|           ), | ||||
|         ), | ||||
|       ); | ||||
|  | ||||
|       if (response.statusCode == 401) { | ||||
|         _auth.logoff(); | ||||
|         _reset(); | ||||
|         return; | ||||
|       } | ||||
|  | ||||
|       if (response.statusCode != 200) { | ||||
|         _reset(); | ||||
|         return; | ||||
|       } | ||||
|  | ||||
|       _enableAnimations = value; | ||||
|       notifyListeners(); | ||||
|     } catch (e) { | ||||
|       debugPrint('$e'); | ||||
|       _reset(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   Future<void> setAutoStart(bool value) async { | ||||
|     try { | ||||
|       final auth = await _auth.createAuth(); | ||||
| @@ -77,7 +103,10 @@ class Settings with ChangeNotifier { | ||||
|         return; | ||||
|       } | ||||
|  | ||||
|       _autoStart = jsonDecode(response.body)["AutoStart"] as bool; | ||||
|       final jsonData = jsonDecode(response.body); | ||||
|       _enableAnimations = jsonData["Animations"] as bool; | ||||
|       _autoStart = jsonData["AutoStart"] as bool; | ||||
|  | ||||
|       notifyListeners(); | ||||
|     } catch (e) { | ||||
|       debugPrint('$e'); | ||||
|   | ||||
| @@ -134,22 +134,36 @@ class AppScaffold extends StatelessWidget { | ||||
|                       ), | ||||
|                       const SizedBox(width: constants.padding), | ||||
|                       if (!showBack) ...[ | ||||
|                         const Text("Animations"), | ||||
|                         Consumer<Settings>( | ||||
|                           builder: (context, settings, _) => IconButton( | ||||
|                             icon: Icon( | ||||
|                               settings.enableAnimations | ||||
|                                   ? Icons.toggle_on | ||||
|                                   : Icons.toggle_off, | ||||
|                             ), | ||||
|                             color: settings.enableAnimations | ||||
|                                 ? scheme.primary | ||||
|                                 : scheme.onSurface, | ||||
|                             onPressed: () => settings.setEnableAnimations( | ||||
|                               !settings.enableAnimations, | ||||
|                             ), | ||||
|                           ), | ||||
|                         ), | ||||
|                         const Text("Auto-start"), | ||||
|                         Consumer<Settings>( | ||||
|                           builder: (context, settings, _) { | ||||
|                             return IconButton( | ||||
|                               icon: Icon( | ||||
|                                 settings.autoStart | ||||
|                                     ? Icons.toggle_on | ||||
|                                     : Icons.toggle_off, | ||||
|                               ), | ||||
|                               color: settings.autoStart | ||||
|                                   ? scheme.primary | ||||
|                                   : scheme.onSurface, | ||||
|                               onPressed: () => | ||||
|                                   settings.setAutoStart(!settings.autoStart), | ||||
|                             ); | ||||
|                           }, | ||||
|                           builder: (context, settings, _) => IconButton( | ||||
|                             icon: Icon( | ||||
|                               settings.autoStart | ||||
|                                   ? Icons.toggle_on | ||||
|                                   : Icons.toggle_off, | ||||
|                             ), | ||||
|                             color: settings.autoStart | ||||
|                                 ? scheme.primary | ||||
|                                 : scheme.onSurface, | ||||
|                             onPressed: () => | ||||
|                                 settings.setAutoStart(!settings.autoStart), | ||||
|                           ), | ||||
|                         ), | ||||
|                         IconButton( | ||||
|                           tooltip: 'Settings', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user