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

---
 .../metadata/android/en-US/changelogs/65.txt  |  1 +
 .../metadata/android/fr-FR/changelogs/65.txt  |  1 +
 lib/cubit/theme_cubit.dart                    | 30 -------------
 lib/cubit/theme_state.dart                    | 15 -------
 lib/main.dart                                 |  8 ++--
 lib/ui/settings/settings_form.dart            |  7 ++-
 lib/ui/settings/theme_card.dart               | 45 -------------------
 pubspec.lock                                  |  6 +--
 pubspec.yaml                                  |  4 +-
 9 files changed, 14 insertions(+), 103 deletions(-)
 create mode 100644 fastlane/metadata/android/en-US/changelogs/65.txt
 create mode 100644 fastlane/metadata/android/fr-FR/changelogs/65.txt
 delete mode 100644 lib/cubit/theme_cubit.dart
 delete mode 100644 lib/cubit/theme_state.dart
 delete mode 100644 lib/ui/settings/theme_card.dart

diff --git a/fastlane/metadata/android/en-US/changelogs/65.txt b/fastlane/metadata/android/en-US/changelogs/65.txt
new file mode 100644
index 0000000..32ed6ee
--- /dev/null
+++ b/fastlane/metadata/android/en-US/changelogs/65.txt
@@ -0,0 +1 @@
+Use ApplicationSettings widgets from flutter_custom_toolbox.
diff --git a/fastlane/metadata/android/fr-FR/changelogs/65.txt b/fastlane/metadata/android/fr-FR/changelogs/65.txt
new file mode 100644
index 0000000..6d5f7c8
--- /dev/null
+++ b/fastlane/metadata/android/fr-FR/changelogs/65.txt
@@ -0,0 +1 @@
+Utilisation des widgets ApplicationSettings depuis flutter_custom_toolbox.
diff --git a/lib/cubit/theme_cubit.dart b/lib/cubit/theme_cubit.dart
deleted file mode 100644
index 1ecab60..0000000
--- a/lib/cubit/theme_cubit.dart
+++ /dev/null
@@ -1,30 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:flutter_custom_toolbox/flutter_toolbox.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 4b23560..3dbb8d6 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -17,7 +17,6 @@ import 'package:scrobbles/cubit/data_statistics_recent_cubit.dart';
 import 'package:scrobbles/cubit/data_timeline_cubit.dart';
 import 'package:scrobbles/cubit/data_top_artists_cubit.dart';
 import 'package:scrobbles/cubit/settings_global_cubit.dart';
-import 'package:scrobbles/cubit/theme_cubit.dart';
 import 'package:scrobbles/ui/skeleton.dart';
 
 void main() async {
@@ -52,7 +51,8 @@ class MyApp extends StatelessWidget {
       providers: [
         BlocProvider<NavCubitPage>(create: (context) => NavCubitPage()),
         BlocProvider<NavCubitScreen>(create: (context) => NavCubitScreen()),
-        BlocProvider<ThemeCubit>(create: (context) => ThemeCubit()),
+        BlocProvider<ApplicationThemeModeCubit>(
+            create: (context) => ApplicationThemeModeCubit()),
         BlocProvider<GlobalSettingsCubit>(create: (context) => GlobalSettingsCubit()),
         BlocProvider<DataCountsByDayCubit>(create: (context) => DataCountsByDayCubit()),
         BlocProvider<DataCountsByHourCubit>(create: (context) => DataCountsByHourCubit()),
@@ -67,8 +67,8 @@ class MyApp extends StatelessWidget {
         BlocProvider<DataTimelineCubit>(create: (context) => DataTimelineCubit()),
         BlocProvider<DataTopArtistsCubit>(create: (context) => DataTopArtistsCubit()),
       ],
-      child: BlocBuilder<ThemeCubit, ThemeModeState>(
-        builder: (BuildContext context, ThemeModeState state) {
+      child: BlocBuilder<ApplicationThemeModeCubit, ApplicationThemeModeState>(
+        builder: (BuildContext context, ApplicationThemeModeState state) {
           return MaterialApp(
             title: 'Scrobbles',
             home: const SkeletonScreen(),
diff --git a/lib/ui/settings/settings_form.dart b/lib/ui/settings/settings_form.dart
index 1ef9da0..97372a0 100644
--- a/lib/ui/settings/settings_form.dart
+++ b/lib/ui/settings/settings_form.dart
@@ -3,7 +3,6 @@ import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
 
 import 'package:scrobbles/config/default_global_settings.dart';
 import 'package:scrobbles/cubit/settings_global_cubit.dart';
-import 'package:scrobbles/ui/settings/theme_card.dart';
 
 class SettingsForm extends StatefulWidget {
   const SettingsForm({super.key});
@@ -110,15 +109,15 @@ class _SettingsFormState extends State<SettingsForm> {
               mainAxisAlignment: MainAxisAlignment.end,
               crossAxisAlignment: CrossAxisAlignment.center,
               children: [
-                ThemeCard(
+                ApplicationSettingsThemeModeCard(
                   mode: ThemeMode.system,
                   icon: UniconsLine.cog,
                 ),
-                ThemeCard(
+                ApplicationSettingsThemeModeCard(
                   mode: ThemeMode.light,
                   icon: UniconsLine.sun,
                 ),
-                ThemeCard(
+                ApplicationSettingsThemeModeCard(
                   mode: ThemeMode.dark,
                   icon: UniconsLine.moon,
                 )
diff --git a/lib/ui/settings/theme_card.dart b/lib/ui/settings/theme_card.dart
deleted file mode 100644
index 20d56d4..0000000
--- a/lib/ui/settings/theme_card.dart
+++ /dev/null
@@ -1,45 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
-
-import 'package:scrobbles/cubit/theme_cubit.dart';
-
-class ThemeCard extends StatelessWidget {
-  const ThemeCard({
-    super.key,
-    required this.mode,
-    required this.icon,
-  });
-
-  final IconData icon;
-  final ThemeMode mode;
-
-  @override
-  Widget build(BuildContext context) {
-    return BlocBuilder<ThemeCubit, ThemeModeState>(
-        builder: (BuildContext context, ThemeModeState state) {
-      return Card(
-        elevation: 2,
-        shadowColor: Theme.of(context).colorScheme.shadow,
-        color: state.themeMode == mode
-            ? Theme.of(context).colorScheme.primary
-            : Theme.of(context).colorScheme.surface,
-        shape: const RoundedRectangleBorder(
-          borderRadius: BorderRadius.all(Radius.circular(12)),
-        ),
-        margin: const EdgeInsets.all(5),
-        child: InkWell(
-          onTap: () => BlocProvider.of<ThemeCubit>(context).getTheme(
-            ThemeModeState(themeMode: mode),
-          ),
-          borderRadius: const BorderRadius.all(Radius.circular(12)),
-          child: Icon(
-            icon,
-            size: 32,
-            color:
-                state.themeMode != mode ? Theme.of(context).colorScheme.primary : Colors.white,
-          ),
-        ),
-      );
-    });
-  }
-}
diff --git a/pubspec.lock b/pubspec.lock
index d78deab..abad950 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -130,11 +130,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 7122fae..715fc23 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -3,7 +3,7 @@ description: Display scrobbles data and charts
 
 publish_to: "none"
 
-version: 0.3.0+64
+version: 0.3.1+65
 
 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
   fl_chart: ^0.69.0
-- 
GitLab