Enhancement

main_design2.0
zaid_daoud 2 years ago
parent a8a7b5a613
commit 05398a9f76

@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/controllers/api_routes/urls.dart';
import 'package:test_sa/models/user.dart'; import 'package:test_sa/models/user.dart';
import 'package:test_sa/new_views/app_style/app_themes.dart';
import '../settings/app_settings.dart'; import '../settings/app_settings.dart';
@ -49,10 +48,10 @@ class SettingProvider extends ChangeNotifier {
} }
String _theme; String _theme;
ThemeData get theme => _theme == "light" ? AppThemes.lightTheme : AppThemes.darkTheme; String get theme => _theme;
Future<void> setTheme(ThemeData themeData) async { Future<void> setDarkTheme(bool value) async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
_theme = themeData.brightness == Brightness.light ? "light" : "dark"; _theme = value ? "dark" : "light";
prefs.setString(ASettings.theme, _theme); prefs.setString(ASettings.theme, _theme);
notifyListeners(); notifyListeners();
} }

@ -11,5 +11,5 @@ extension BuildContextExtension on BuildContext {
return translationKey.name.i18n([Localizations.localeOf(this).toString()]); return translationKey.name.i18n([Localizations.localeOf(this).toString()]);
} }
bool get isDark => Provider.of<SettingProvider>(this).theme.brightness == Brightness.dark; bool get isDark => Provider.of<SettingProvider>(this).theme == "dark";
} }

@ -52,7 +52,7 @@ class MyApp extends StatelessWidget {
child: MaterialApp( child: MaterialApp(
title: 'ATOMS', title: 'ATOMS',
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
theme: settingProvider.theme ?? AppThemes.lightTheme, theme: settingProvider.theme == "dark" ? AppThemes.darkTheme : AppThemes.lightTheme,
localizationsDelegates: [ localizationsDelegates: [
LocalJsonLocalization.delegate, LocalJsonLocalization.delegate,
GlobalMaterialLocalizations.delegate, GlobalMaterialLocalizations.delegate,

@ -12,7 +12,7 @@ class AppThemes {
); );
static ThemeData darkTheme = ThemeData.dark().copyWith( static ThemeData darkTheme = ThemeData.dark().copyWith(
textTheme: ThemeData.light().textTheme.apply(fontFamily: "Poppins"), textTheme: ThemeData.dark().textTheme.apply(fontFamily: "Poppins"),
primaryColor: AppColor.primary50, primaryColor: AppColor.primary50,
indicatorColor: AppColor.primary50, indicatorColor: AppColor.primary50,
scaffoldBackgroundColor: AppColor.backgroundDark, scaffoldBackgroundColor: AppColor.backgroundDark,

@ -5,7 +5,6 @@ import 'package:test_sa/extensions/context_extension.dart';
import '../../controllers/providers/api/user_provider.dart'; import '../../controllers/providers/api/user_provider.dart';
import '../../controllers/providers/settings/setting_provider.dart'; import '../../controllers/providers/settings/setting_provider.dart';
import '../../models/enums/translation_keys.dart'; import '../../models/enums/translation_keys.dart';
import '../app_style/app_themes.dart';
import 'app_filled_button.dart'; import 'app_filled_button.dart';
class AppDrawer extends StatelessWidget { class AppDrawer extends StatelessWidget {
@ -33,12 +32,13 @@ class AppDrawer extends StatelessWidget {
settingProvider.resetSettings(); settingProvider.resetSettings();
userProvider.reset(); userProvider.reset();
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).pop();
} }
}), }),
Switch.adaptive( Switch.adaptive(
value: context.isDark, value: context.isDark,
onChanged: (dark) { onChanged: (value) {
Provider.of<SettingProvider>(context, listen: false).setTheme(dark ? AppThemes.darkTheme : AppThemes.lightTheme); Provider.of<SettingProvider>(context, listen: false).setDarkTheme(value);
}, },
), ),
], ],

@ -74,7 +74,7 @@ class _LandPageState extends State<LandPage> {
10.width, 10.width,
Text( Text(
"0$_currentPage/03", "0$_currentPage/03",
style: Theme.of(context).textTheme.labelMedium?.copyWith(fontWeight: FontWeight.w500, color: context.isDark ? AppColor.neutral40 : AppColor.neutral60), style: Theme.of(context).textTheme.labelMedium?.copyWith(fontWeight: FontWeight.w500),
), ),
], ],
), ),

Loading…
Cancel
Save