From da0ce266ed65926dd63f66e5d78406d5613b544a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Tue, 22 Oct 2024 09:35:02 +0200
Subject: [PATCH] Use ApplicationSettings widgets from flutter_custom_toolbox

---
 lib/cubit/theme_cubit.dart     | 30 ------------------------------
 lib/cubit/theme_state.dart     | 15 ---------------
 lib/main.dart                  |  8 ++++----
 lib/ui/widgets/theme_card.dart | 10 ++++------
 pubspec.lock                   |  6 +++---
 pubspec.yaml                   |  4 ++--
 6 files changed, 13 insertions(+), 60 deletions(-)
 delete mode 100644 lib/cubit/theme_cubit.dart
 delete mode 100644 lib/cubit/theme_state.dart

diff --git a/lib/cubit/theme_cubit.dart b/lib/cubit/theme_cubit.dart
deleted file mode 100644
index f6c84b0..0000000
--- a/lib/cubit/theme_cubit.dart
+++ /dev/null
@@ -1,30 +0,0 @@
-import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
-import 'package:flutter/material.dart';
-
-part 'theme_state.dart';
-
-class ThemeCubit extends HydratedCubit<ThemeModeState> {
-  ThemeCubit() : super(const ThemeModeState());
-
-  void getTheme(ThemeModeState state) {
-    emit(state);
-  }
-
-  @override
-  ThemeModeState? fromJson(Map<String, dynamic> json) {
-    switch (json['themeMode']) {
-      case 'ThemeMode.dark':
-        return const ThemeModeState(themeMode: ThemeMode.dark);
-      case 'ThemeMode.light':
-        return const ThemeModeState(themeMode: ThemeMode.light);
-      case 'ThemeMode.system':
-      default:
-        return const ThemeModeState(themeMode: ThemeMode.system);
-    }
-  }
-
-  @override
-  Map<String, String>? toJson(ThemeModeState state) {
-    return <String, String>{'themeMode': state.themeMode.toString()};
-  }
-}
diff --git a/lib/cubit/theme_state.dart b/lib/cubit/theme_state.dart
deleted file mode 100644
index e479a50..0000000
--- a/lib/cubit/theme_state.dart
+++ /dev/null
@@ -1,15 +0,0 @@
-part of 'theme_cubit.dart';
-
-@immutable
-class ThemeModeState extends Equatable {
-  const ThemeModeState({
-    this.themeMode,
-  });
-
-  final ThemeMode? themeMode;
-
-  @override
-  List<Object?> get props => <Object?>[
-        themeMode,
-      ];
-}
diff --git a/lib/main.dart b/lib/main.dart
index b774645..1437a56 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -8,7 +8,6 @@ import 'package:random/cubit/bottom_nav_cubit.dart';
 import 'package:random/cubit/data_cubit.dart';
 import 'package:random/cubit/game_cubit.dart';
 import 'package:random/cubit/settings_cubit.dart';
-import 'package:random/cubit/theme_cubit.dart';
 import 'package:random/repository/api.dart';
 import 'package:random/network/api.dart';
 import 'package:random/ui/skeleton.dart';
@@ -55,10 +54,11 @@ class MyApp extends StatelessWidget {
         BlocProvider<DataCubit>(create: (context) => DataCubit()),
         BlocProvider<GameCubit>(create: (context) => GameCubit()),
         BlocProvider<SettingsCubit>(create: (context) => SettingsCubit()),
-        BlocProvider<ThemeCubit>(create: (context) => ThemeCubit()),
+        BlocProvider<ApplicationThemeModeCubit>(
+            create: (context) => ApplicationThemeModeCubit()),
       ],
-      child: BlocBuilder<ThemeCubit, ThemeModeState>(
-          builder: (BuildContext context, ThemeModeState state) {
+      child: BlocBuilder<ApplicationThemeModeCubit, ApplicationThemeModeState>(
+          builder: (BuildContext context, ApplicationThemeModeState state) {
         return MaterialApp(
           title: 'Random application',
           theme: lightTheme,
diff --git a/lib/ui/widgets/theme_card.dart b/lib/ui/widgets/theme_card.dart
index fefb525..18fffe0 100644
--- a/lib/ui/widgets/theme_card.dart
+++ b/lib/ui/widgets/theme_card.dart
@@ -1,8 +1,6 @@
 import 'package:flutter/material.dart';
 import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
 
-import 'package:random/cubit/theme_cubit.dart';
-
 class ThemeCard extends StatelessWidget {
   const ThemeCard({
     super.key,
@@ -15,8 +13,8 @@ class ThemeCard extends StatelessWidget {
 
   @override
   Widget build(BuildContext context) {
-    return BlocBuilder<ThemeCubit, ThemeModeState>(
-        builder: (BuildContext context, ThemeModeState state) {
+    return BlocBuilder<ApplicationThemeModeCubit, ApplicationThemeModeState>(
+        builder: (BuildContext context, ApplicationThemeModeState state) {
       return Card(
         elevation: 2,
         shadowColor: Theme.of(context).colorScheme.shadow,
@@ -28,8 +26,8 @@ class ThemeCard extends StatelessWidget {
         ),
         margin: const EdgeInsets.all(5),
         child: InkWell(
-          onTap: () => BlocProvider.of<ThemeCubit>(context).getTheme(
-            ThemeModeState(themeMode: mode),
+          onTap: () => BlocProvider.of<ApplicationThemeModeCubit>(context).getTheme(
+            ApplicationThemeModeState(themeMode: mode),
           ),
           borderRadius: const BorderRadius.all(Radius.circular(12)),
           child: Icon(
diff --git a/pubspec.lock b/pubspec.lock
index 077816a..f45210b 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -194,11 +194,11 @@ packages:
     dependency: "direct main"
     description:
       path: "."
-      ref: "0.1.1"
-      resolved-ref: ba7137ca9edec7e503ed3dbfe7f6ede7e9cfbf4d
+      ref: "0.2.0"
+      resolved-ref: bbf0abd5457d42678882384216af9e83c38549bc
       url: "https://git.harrault.fr/android/flutter-toolbox.git"
     source: git
-    version: "0.1.1"
+    version: "0.2.0"
   flutter_lints:
     dependency: "direct dev"
     description:
diff --git a/pubspec.yaml b/pubspec.yaml
index b76981b..e7063fc 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -3,7 +3,7 @@ description: A random application, for testing purpose only.
 
 publish_to: "none"
 
-version: 1.2.0+69
+version: 1.2.1+70
 
 environment:
   sdk: "^3.0.0"
@@ -16,7 +16,7 @@ dependencies:
   flutter_custom_toolbox:
     git:
       url: https://git.harrault.fr/android/flutter-toolbox.git
-      ref: 0.1.1
+      ref: 0.2.0
 
   # specific
   camera: ^0.11.0+2
-- 
GitLab