Skip to content

Commit

Permalink
Allow hot reload when changing theme colors
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedLSayed9 committed Aug 10, 2023
1 parent 3418f1a commit 730910d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
5 changes: 3 additions & 2 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'core/core_features/locale/presentation/providers/current_app_locale_provider.dart';
import 'core/core_features/theme/presentation/providers/current_app_theme_provider.dart';
import 'core/core_features/theme/presentation/utils/app_theme.dart';
import 'core/presentation/routing/app_router.dart';
import 'core/presentation/routing/navigation_service.dart';
import 'core/presentation/utils/riverpod_framework.dart';
Expand All @@ -18,7 +19,7 @@ class MyApp extends HookConsumerWidget {
useOnPlatformBrightnessChange((previous, current) {
ref.read(platformBrightnessProvider.notifier).update((_) => current);
});
final theme = ref.watch(currentAppThemeProvider);
final themeMode = ref.watch(currentAppThemeModeProvider);
final locale = ref.watch(currentAppLocaleProvider);

return MaterialApp.router(
Expand All @@ -35,7 +36,7 @@ class MyApp extends HookConsumerWidget {
title: 'Deliverzler',
debugShowCheckedModeBanner: false,
color: Theme.of(context).colorScheme.primary,
theme: theme,
theme: themeMode.getThemeData(locale.fontFamily),
locale: Locale(locale.code),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import '../../../../presentation/helpers/theme_helper.dart';
import '../../../../presentation/providers/provider_utils.dart';
import '../../../../presentation/utils/riverpod_framework.dart';
import '../../../locale/presentation/providers/current_app_locale_provider.dart';
import '../utils/app_theme.dart';
import 'app_theme_provider.dart';

Expand All @@ -22,10 +21,3 @@ AppThemeMode currentAppThemeMode(CurrentAppThemeModeRef ref) {
final platformBrightness = ref.watch(platformBrightnessProvider);
return theme ?? getSystemTheme(platformBrightness);
}

@Riverpod(keepAlive: true)
ThemeData currentAppTheme(CurrentAppThemeRef ref) {
final themeMode = ref.watch(currentAppThemeModeProvider);
final locale = ref.watch(currentAppLocaleProvider);
return AppTheme(themeMode: themeMode).getThemeData(locale.fontFamily);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ enum AppThemeMode {
}

extension AppThemeModeX on AppThemeMode {
ThemeData getThemeData(String fontFamily) {
return AppTheme(themeMode: this).getThemeData(fontFamily);
}

ThemeData get _baseTheme {
return switch (this) {
AppThemeMode.light => ThemeData.light(),
Expand Down

0 comments on commit 730910d

Please sign in to comment.