From 42e40918c54cf07717014c0fda09f715af8e50b3 Mon Sep 17 00:00:00 2001 From: Saptarshi Adhikari <66560136+Mastermind-sap@users.noreply.github.com> Date: Tue, 18 Jun 2024 03:09:20 +0530 Subject: [PATCH] fixed theme bug --- .gradle/8.0.2/checksums/checksums.lock | Bin 0 -> 17 bytes .gradle/8.0.2/fileChanges/last-build.bin | Bin 0 -> 1 bytes .gradle/8.0.2/fileHashes/fileHashes.lock | Bin 0 -> 17 bytes .gradle/8.0.2/gc.properties | 0 lib/home_page.dart | 26 +++-------------------- lib/main.dart | 8 ++++--- 6 files changed, 8 insertions(+), 26 deletions(-) create mode 100644 .gradle/8.0.2/checksums/checksums.lock create mode 100644 .gradle/8.0.2/fileChanges/last-build.bin create mode 100644 .gradle/8.0.2/fileHashes/fileHashes.lock create mode 100644 .gradle/8.0.2/gc.properties diff --git a/.gradle/8.0.2/checksums/checksums.lock b/.gradle/8.0.2/checksums/checksums.lock new file mode 100644 index 0000000000000000000000000000000000000000..c90f709898d7165c8e169cc1a71a93cde299f0ac GIT binary patch literal 17 TcmZSf`FeAH&7;-d7@z { void initState() { // showNotification(); super.initState(); - _getInitialThemeMode(); - } - - int _initialLabelIndex = 0; - void _getInitialThemeMode() async { - final savedThemeMode = await AdaptiveTheme.getThemeMode(); - setState(() { - if (savedThemeMode == AdaptiveThemeMode.light) { - _initialLabelIndex = 0; - } else if (savedThemeMode == AdaptiveThemeMode.dark) { - _initialLabelIndex = 1; - } else { - _initialLabelIndex = 0; - } - }); } //show various notification from here @@ -191,20 +176,15 @@ class _HomePageState extends State { onTap: () {}, child: ListTile( leading: Icon( - _initialLabelIndex == 0 + AdaptiveTheme.of(context).mode.isDark ? FontAwesomeIcons.solidSun : FontAwesomeIcons.solidMoon, ), title: const Text('Switch Theme'), onTap: () { setState(() { - if (_initialLabelIndex == 0) { - _initialLabelIndex = 1; - AdaptiveTheme.of(context).setDark(); - } else { - _initialLabelIndex = 0; - AdaptiveTheme.of(context).setLight(); - } + AdaptiveTheme.of(context) + .toggleThemeMode(useSystem: false); }); }, ), diff --git a/lib/main.dart b/lib/main.dart index 87e2cd7..23f9527 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,12 +16,14 @@ import 'splash_screen.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); + final savedThemeMode = await AdaptiveTheme.getThemeMode(); await NotificationService.initialNotification(); - runApp(const OpSoApp()); + runApp(OpSoApp(savedThemeMode: savedThemeMode)); } class OpSoApp extends StatelessWidget { - const OpSoApp({super.key}); + final AdaptiveThemeMode? savedThemeMode; + const OpSoApp({super.key, this.savedThemeMode}); @override Widget build(BuildContext context) { @@ -33,7 +35,7 @@ class OpSoApp extends StatelessWidget { return AdaptiveTheme( light: ThemeData.light(), dark: ThemeData.dark(), - initial: AdaptiveThemeMode.system, + initial: savedThemeMode ?? AdaptiveThemeMode.light, builder: (theme, darkTheme) => MaterialApp( initialRoute: '/splash_screen', routes: {