From 332480be3a9ff5e2b8f5c66d6311c173aaae751a Mon Sep 17 00:00:00 2001 From: Valeri Gokadze Date: Thu, 26 Jan 2023 00:07:41 +0400 Subject: [PATCH] changed modalbottombar with switch --- lib/customWidgets/setting_switch_bar.dart | 29 ++++++ lib/style/appTheme.dart | 6 ++ lib/ui/morePage.dart | 102 ++++------------------ 3 files changed, 53 insertions(+), 84 deletions(-) create mode 100644 lib/customWidgets/setting_switch_bar.dart diff --git a/lib/customWidgets/setting_switch_bar.dart b/lib/customWidgets/setting_switch_bar.dart new file mode 100644 index 000000000..121fa7795 --- /dev/null +++ b/lib/customWidgets/setting_switch_bar.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; +import 'package:musify/style/appTheme.dart'; + +class SettingSwitchBar extends StatelessWidget { + SettingSwitchBar(this.tileName, this.tileIcon, this.value, this.onChanged); + + final Function(bool) onChanged; + final bool value; + final String tileName; + final IconData tileIcon; + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.only(top: 8, left: 8, right: 8, bottom: 6), + child: Card( + child: SwitchListTile( + secondary: Icon(tileIcon, color: accent.primary), + title: Text( + tileName, + style: TextStyle(color: accent.primary), + ), + value: value, + onChanged: onChanged, + ), + ), + ); + } +} diff --git a/lib/style/appTheme.dart b/lib/style/appTheme.dart index d0b29211a..6e4becc0f 100644 --- a/lib/style/appTheme.dart +++ b/lib/style/appTheme.dart @@ -41,6 +41,9 @@ ThemeData getAppDarkTheme() { elevation: 2.3, ), listTileTheme: const ListTileThemeData(textColor: Colors.white), + switchTheme: SwitchThemeData( + trackColor: MaterialStateProperty.all(accent.primary), + ), iconTheme: const IconThemeData(color: Colors.white), hintColor: Colors.white, textTheme: const TextTheme( @@ -81,6 +84,9 @@ ThemeData getAppLightTheme() { listTileTheme: ListTileThemeData( selectedColor: accent.primary.withOpacity(0.4), ), + switchTheme: SwitchThemeData( + trackColor: MaterialStateProperty.all(accent.primary), + ), iconTheme: const IconThemeData(color: Color(0xFF151515)), hintColor: const Color(0xFF151515), ); diff --git a/lib/ui/morePage.dart b/lib/ui/morePage.dart index 1f26e1b06..64361a0ef 100644 --- a/lib/ui/morePage.dart +++ b/lib/ui/morePage.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:hive/hive.dart'; import 'package:musify/customWidgets/setting_bar.dart'; +import 'package:musify/customWidgets/setting_switch_bar.dart'; import 'package:musify/helper/flutter_toast.dart'; import 'package:musify/helper/url_launcher.dart'; import 'package:musify/helper/version.dart'; @@ -334,92 +335,25 @@ class SettingsCards extends StatelessWidget { ), }, ), - SettingBar( + SettingSwitchBar( AppLocalizations.of(context)!.useSystemColor, FluentIcons.toggle_left_24_filled, - () => { - showModalBottomSheet( - isDismissible: true, - backgroundColor: Colors.transparent, - context: context, - builder: (BuildContext context) { - return Center( - child: Container( - decoration: BoxDecoration( - border: Border.all( - color: accent.primary, - ), - borderRadius: const BorderRadius.all( - Radius.circular(20), - ), - ), - width: MediaQuery.of(context).copyWith().size.width * 0.90, - child: Column( - children: [ - Padding( - padding: const EdgeInsets.all(10), - child: Card( - child: ListTile( - title: Text( - AppLocalizations.of(context)!.trueMSG, - style: TextStyle(color: accent.primary), - ), - onTap: () { - addOrUpdateData( - 'settings', - 'useSystemColor', - true, - ); - useSystemColor.value = true; - MyApp.setAccentColor( - context, - accent.primary, - true, - ); - showToast( - AppLocalizations.of(context)! - .settingChangedMsg, - ); - Navigator.pop(context); - }, - ), - ), - ), - Padding( - padding: const EdgeInsets.all(10), - child: Card( - child: ListTile( - title: Text( - AppLocalizations.of(context)!.falseMSG, - style: TextStyle(color: accent.primary), - ), - onTap: () { - addOrUpdateData( - 'settings', - 'useSystemColor', - false, - ); - useSystemColor.value = false; - MyApp.setAccentColor( - context, - accent.primary, - false, - ); - showToast( - AppLocalizations.of(context)! - .settingChangedMsg, - ); - Navigator.pop(context); - }, - ), - ), - ) - ], - ), - ), - ); - }, - ), + useSystemColor.value, + (value) { + addOrUpdateData( + 'settings', + 'useSystemColor', + value, + ); + useSystemColor.value = value; + MyApp.setAccentColor( + context, + accent.primary, + value, + ); + showToast( + AppLocalizations.of(context)!.settingChangedMsg, + ); }, ),