Skip to content

Commit

Permalink
chore: added riverpod observer
Browse files Browse the repository at this point in the history
  • Loading branch information
JideGuru committed Dec 25, 2023
1 parent 0e7378c commit 5d320a8
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 57 deletions.
7 changes: 6 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
LocalStorage();
await DatabaseConfig.init(StoreRef<dynamic, dynamic>.main());
runApp(ProviderScope(child: MyApp()));
runApp(
ProviderScope(
observers: [RiverpodObserver()],
child: MyApp(),
),
);
}
8 changes: 3 additions & 5 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ class MyApp extends ConsumerWidget {
debugShowCheckedModeBanner: false,
title: Strings.appName,
theme: themeData(
currentAppTheme.value == CurrentAppTheme.dark
? ThemeConfig.darkTheme
: ThemeConfig.lightTheme,
currentAppTheme.value == CurrentAppTheme.dark ? darkTheme : lightTheme,
),
darkTheme: themeData(ThemeConfig.darkTheme),
darkTheme: themeData(darkTheme),
themeMode: currentAppTheme.value?.themeMode,
routerConfig: _appRouter.config(
navigatorObservers: () => [
Expand All @@ -37,7 +35,7 @@ class MyApp extends ConsumerWidget {
theme.textTheme,
),
colorScheme: theme.colorScheme.copyWith(
secondary: ThemeConfig.lightAccent,
secondary: lightAccent,
),
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/common/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export 'domain/domain.dart';
export 'extensions/extensions.dart';
export 'presentation/presentation.dart';
export 'router/app_router.dart';
export 'utils/utils.dart';
114 changes: 63 additions & 51 deletions lib/src/common/presentation/theme/theme_config.dart
Original file line number Diff line number Diff line change
@@ -1,60 +1,72 @@
import 'package:flutter/material.dart';

class ThemeConfig {
static Color lightPrimary = const Color(0xffF5F5F5);
static Color darkPrimary = const Color(0xff1f1f1f);
static Color lightAccent = const Color(0xff2ca8e2);
static Color darkAccent = const Color(0xff2ca8e2);
static Color lightBG = Colors.white;
static Color darkBG = const Color(0xff121212);
static Color smokeWhite = const Color(0xffF5F5F5);
const Color lightPrimary = Color(0xffF5F5F5);
const Color darkPrimary = Color(0xff1f1f1f);
const Color lightAccent = Color(0xff2ca8e2);
const Color darkAccent = Color(0xff2ca8e2);
const Color lightBG = Colors.white;
const Color darkBG = Color(0xff121212);
const Color smokeWhite = Color(0xffF5F5F5);

static ThemeData lightTheme = ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(
secondary: lightBG,
brightness: Brightness.light,
),
primaryColor: lightPrimary,
scaffoldBackgroundColor: lightBG,
navigationRailTheme: NavigationRailThemeData(
backgroundColor: smokeWhite,
),
appBarTheme: AppBarTheme(
color: lightPrimary,
elevation: 0.0,
titleTextStyle: const TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.w800,
),
iconTheme: const IconThemeData(
color: Colors.black,
final ThemeData lightTheme = ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(
secondary: lightBG,
brightness: Brightness.light,
),
primaryColor: lightPrimary,
scaffoldBackgroundColor: lightBG,
navigationRailTheme: const NavigationRailThemeData(
backgroundColor: smokeWhite,
),
tabBarTheme: const TabBarTheme(
labelColor: Colors.black,
unselectedLabelColor: Colors.grey,
indicator: UnderlineTabIndicator(
borderSide: BorderSide(
color: lightAccent,
width: 2.0,
),
),
);
),
appBarTheme: const AppBarTheme(
color: lightPrimary,
elevation: 0.0,
titleTextStyle: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.w800,
),
iconTheme: IconThemeData(color: Colors.black),
),
);

static ThemeData darkTheme = ThemeData(
final ThemeData darkTheme = ThemeData(
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSwatch().copyWith(
secondary: darkBG,
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSwatch().copyWith(
secondary: darkBG,
brightness: Brightness.dark,
),
primaryColor: darkPrimary,
scaffoldBackgroundColor: darkBG,
navigationRailTheme: NavigationRailThemeData(
backgroundColor: darkPrimary,
),
appBarTheme: AppBarTheme(
color: darkPrimary,
elevation: 0.0,
titleTextStyle: const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w800,
),
iconTheme: const IconThemeData(
color: Colors.white,
),
primaryColor: darkPrimary,
scaffoldBackgroundColor: darkBG,
navigationRailTheme: const NavigationRailThemeData(
backgroundColor: darkPrimary,
),
tabBarTheme: const TabBarTheme(
indicator: UnderlineTabIndicator(
borderSide: BorderSide(
color: lightAccent,
width: 2.0,
),
),
);
}
),
appBarTheme: const AppBarTheme(
color: darkPrimary,
elevation: 0.0,
titleTextStyle: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w800,
),
iconTheme: IconThemeData(color: Colors.white),
),
);
45 changes: 45 additions & 0 deletions lib/src/common/utils/riverpod_observer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logman/logman.dart';

class RiverpodObserver extends ProviderObserver {
final logman = Logman.instance;

@override
void didAddProvider(
ProviderBase<Object?> provider,
Object? value,
ProviderContainer container,
) {
logman.recordSimpleLog('Provider $provider was initialized with $value');
}

@override
void didDisposeProvider(
ProviderBase<Object?> provider,
ProviderContainer container,
) {
logman.recordSimpleLog('Provider $provider was disposed');
}

@override
void didUpdateProvider(
ProviderBase<Object?> provider,
Object? previousValue,
Object? newValue,
ProviderContainer container,
) {
logman.recordSimpleLog(
'Provider $provider updated from $previousValue to $newValue',
);
}

@override
void providerDidFail(
ProviderBase<Object?> provider,
Object error,
StackTrace stackTrace,
ProviderContainer container,
) {
logman.recordSimpleLog('Provider $provider threw $error at $stackTrace');
}
}
1 change: 1 addition & 0 deletions lib/src/common/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'riverpod_observer.dart';

0 comments on commit 5d320a8

Please sign in to comment.