From a75079165f4a92bcc6d837bdccb886e4ab2d2446 Mon Sep 17 00:00:00 2001 From: Jaivardhan Shukla <93859359+jaivsh@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:10:04 +0530 Subject: [PATCH 1/4] Update themes.dart --- lib/screens/themes.dart | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/screens/themes.dart b/lib/screens/themes.dart index 678482e840..389a2629ec 100644 --- a/lib/screens/themes.dart +++ b/lib/screens/themes.dart @@ -1,9 +1,17 @@ import 'package:flutter/material.dart'; -final lightTheme = ThemeData( +final darkTheme = ThemeData( brightness: Brightness.light, + visualDensity: VisualDensity.adaptivePlatformDensity, + colorScheme: ColorScheme.fromSwatch() + .copyWith(secondary: Colors.black), + ); -final darkTheme = ThemeData( - brightness: Brightness.dark, +final lightTheme = ThemeData( + primaryColor: Color(0xFF202328), + visualDensity: VisualDensity.adaptivePlatformDensity, + colorScheme: ColorScheme.fromSwatch() + .copyWith(secondary: Color(0xFF651FFF)) + .copyWith(background: Color(0xFF12171D)), ); From 3527c8afd3a8f27f739cb8ff4e558daf4fb00568 Mon Sep 17 00:00:00 2001 From: Jaivardhan Shukla <93859359+jaivsh@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:10:51 +0530 Subject: [PATCH 2/4] Update settings_screen.dart --- lib/screens/settings_screen.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index 67d261c84c..1bbf62ced0 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -8,6 +8,7 @@ import 'package:open_url/open_url.dart'; import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import '../models/users.dart'; +import '../services/theme_provider.dart'; import '../services/user_info_services.dart'; import 'package:settings_ui/settings_ui.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; @@ -22,6 +23,7 @@ class SettingsScreen extends StatefulWidget { class _SettingsScreenState extends State { get visibilityName => null; bool modeval = false; + late bool? notification; ThemeData? _currentTheme; @@ -131,18 +133,20 @@ class _SettingsScreenState extends State { title: Text(AppLocalizations.of(context).language), value: Text('English'), ), - SettingsTile.switchTile(initialValue: ThemeMode.system == ThemeMode.light ? !modeval : modeval, onToggle: (s) { + SettingsTile.switchTile(initialValue: modeval, onToggle: (s) { + final themeProvider = + Provider.of(context, listen: false); setState(() { modeval = s; }); if(modeval) { setState(() { - _setTheme(lightTheme); + themeProvider.setLightMode(); }); } else { setState(() { - _setTheme(darkTheme); + themeProvider.setDarkmode(); }); } @@ -230,4 +234,4 @@ class _SettingsScreenState extends State { ), ); } -} \ No newline at end of file +} From a64a3ddd072cf34ef7b554bb0b35df27b23e2de7 Mon Sep 17 00:00:00 2001 From: Jaivardhan Shukla <93859359+jaivsh@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:11:27 +0530 Subject: [PATCH 3/4] Create theme_provider.dart --- lib/services/theme_provider.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/services/theme_provider.dart diff --git a/lib/services/theme_provider.dart b/lib/services/theme_provider.dart new file mode 100644 index 0000000000..367731c8b2 --- /dev/null +++ b/lib/services/theme_provider.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +import '../screens/themes.dart'; + +class ThemeProvider extends ChangeNotifier { + ThemeData? currentTheme; + + setLightMode() { + currentTheme = lightTheme; + notifyListeners(); + } + + setDarkmode() { + currentTheme = darkTheme; + notifyListeners(); + } +} From 9c150336d3f5d8f343ff3db1af2f02d53bfb6030 Mon Sep 17 00:00:00 2001 From: Jaivardhan Shukla <93859359+jaivsh@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:12:05 +0530 Subject: [PATCH 4/4] Update main.dart --- lib/main.dart | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 5a99d741fa..c78f1cbadf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,6 +12,7 @@ import 'package:flutter/material.dart'; import 'package:friday/feedback.dart'; import 'package:friday/screens/theme_screen.dart'; import 'package:friday/services/phone_number_verification_db.dart'; +import 'package:friday/services/theme_provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:friday/screens/phone_verification_screen.dart'; import 'package:friday/screens/verify_code_screen.dart'; @@ -38,7 +39,14 @@ void main() async { NotificationService().initNotification(); NotificationService().showNotification(title: 'olalalaaa', body: 'it works'); await Firebase.initializeApp(); - runApp(MyApp()); + runApp(MultiProvider( // create the provider + providers: [ + ChangeNotifierProvider( + create: (_) => ThemeProvider(), + ) + ], + child: MyApp(), + ),); } class MyApp extends StatefulWidget { @@ -126,6 +134,7 @@ class _MyAppState extends State { child: WillPopScope( onWillPop:onWillPop, child: MaterialApp( + theme: Provider.of(context).currentTheme, localizationsDelegates: [ AppLocalizations.delegate, GlobalMaterialLocalizations.delegate, @@ -142,13 +151,7 @@ class _MyAppState extends State { ], debugShowCheckedModeBanner: false, title: 'Friday', - theme: ThemeData( - primaryColor: Color(0xFF202328), - visualDensity: VisualDensity.adaptivePlatformDensity, - colorScheme: ColorScheme.fromSwatch() - .copyWith(secondary: Color(0xFF651FFF)) - .copyWith(background: Color(0xFF12171D)), - ), + home: FutureBuilder( future: Future.delayed(Duration(seconds: 3)), builder: (context, snapshot) {