diff --git a/android/gradle.properties b/android/gradle.properties index 24add27a90a4accaf6a1ee28ec651d0d6bda4f8e..eeed3ef5a3d04530f5624cce71b2a57976938aed 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.0.20 -app.versionCode=20 +app.versionName=0.0.21 +app.versionCode=21 diff --git a/assets/translations/en.json b/assets/translations/en.json index a170877f82723392a7e4c0b6e9d731166207600d..867a99439eb21af93fbddae51621e131d25c8aa5 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -10,6 +10,7 @@ "bottom_nav_settings": "Settings", "settings_title": "Settings", + "settings_label_theme": "Theme mode", "settings_title_game": "Game settings", "settings_label_game_timer_value": "Timer value: ", diff --git a/assets/translations/fr.json b/assets/translations/fr.json index 05bbe109fdb1c472c5c7387a974e3e8ed48d9bb3..c481788e703609e5007305c9051e498b7b15fef1 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -10,6 +10,7 @@ "bottom_nav_settings": "Réglages", "settings_title": "Réglages", + "settings_label_theme": "Thème de couleurs", "settings_title_game": "Paramètres du jeu", "settings_label_game_timer_value": "Durée du chrono : ", diff --git a/fastlane/metadata/android/en-US/changelogs/21.txt b/fastlane/metadata/android/en-US/changelogs/21.txt new file mode 100644 index 0000000000000000000000000000000000000000..e466561363a0fabd2043c6d7903c4280d6b7b3a8 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/21.txt @@ -0,0 +1 @@ +Add light/dark theme setting. diff --git a/fastlane/metadata/android/fr-FR/changelogs/21.txt b/fastlane/metadata/android/fr-FR/changelogs/21.txt new file mode 100644 index 0000000000000000000000000000000000000000..4a93af73582a415da90a3a845509c88ff0682057 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/21.txt @@ -0,0 +1 @@ +Ajout d'un réglage de thème clair/sombre. diff --git a/lib/cubit/theme_cubit.dart b/lib/cubit/theme_cubit.dart new file mode 100644 index 0000000000000000000000000000000000000000..b793e895dbb0c672d451cd403e0036c3d9ac9b42 --- /dev/null +++ b/lib/cubit/theme_cubit.dart @@ -0,0 +1,31 @@ +import 'package:equatable/equatable.dart'; +import 'package:flutter/material.dart'; +import 'package:hydrated_bloc/hydrated_bloc.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 new file mode 100644 index 0000000000000000000000000000000000000000..e479a50f12fe72a35a1fd1722ff72afbb692a136 --- /dev/null +++ b/lib/cubit/theme_state.dart @@ -0,0 +1,15 @@ +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 04f395244869b5cf92e405317da2b66c8d30f2c9..78da985f11b9c86e0ff45fae91b2aaec7eed261d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,6 +11,7 @@ import 'package:twister/config/theme.dart'; import 'package:twister/cubit/bottom_nav_cubit.dart'; import 'package:twister/cubit/game_cubit.dart'; import 'package:twister/cubit/settings_cubit.dart'; +import 'package:twister/cubit/theme_cubit.dart'; import 'package:twister/ui/skeleton.dart'; void main() async { @@ -47,18 +48,26 @@ class MyApp extends StatelessWidget { BlocProvider<BottomNavCubit>(create: (context) => BottomNavCubit()), BlocProvider<GameCubit>(create: (context) => GameCubit()), BlocProvider<SettingsCubit>(create: (context) => SettingsCubit()), + BlocProvider<ThemeCubit>(create: (context) => ThemeCubit()), ], - child: MaterialApp( - title: 'Twister', - theme: appTheme, - home: const SkeletonScreen(), + child: BlocBuilder<ThemeCubit, ThemeModeState>( + builder: (BuildContext context, ThemeModeState state) { + return MaterialApp( + title: 'Twister', + home: const SkeletonScreen(), - // Localization stuff - localizationsDelegates: context.localizationDelegates, - supportedLocales: context.supportedLocales, - locale: context.locale, - debugShowCheckedModeBanner: false, - ), + // Theme stuff + theme: lightTheme, + darkTheme: darkTheme, + themeMode: state.themeMode, + + // Localization stuff + localizationsDelegates: context.localizationDelegates, + supportedLocales: context.supportedLocales, + locale: context.locale, + debugShowCheckedModeBanner: false, + ); + }), ); } } diff --git a/lib/ui/widgets/settings_form.dart b/lib/ui/widgets/settings_form.dart index 3bc096c14ed9eb7dc63c7f04beb4eae16b315afb..81fac9e07e4174ad613b3d84e0047f6aaead6ba4 100644 --- a/lib/ui/widgets/settings_form.dart +++ b/lib/ui/widgets/settings_form.dart @@ -1,10 +1,12 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:unicons/unicons.dart'; import 'package:twister/config/default_settings.dart'; import 'package:twister/cubit/settings_cubit.dart'; import 'package:twister/ui/widgets/app_titles.dart'; +import 'package:twister/ui/widgets/theme_card.dart'; class SettingsForm extends StatefulWidget { const SettingsForm({super.key}); @@ -49,6 +51,36 @@ class _SettingsFormState extends State<SettingsForm> { mainAxisSize: MainAxisSize.max, children: <Widget>[ const SizedBox(height: 8), + + // Light/dark theme + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: <Widget>[ + const Text('settings_label_theme').tr(), + const Row( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + ThemeCard( + mode: ThemeMode.system, + icon: UniconsLine.cog, + ), + ThemeCard( + mode: ThemeMode.light, + icon: UniconsLine.sun, + ), + ThemeCard( + mode: ThemeMode.dark, + icon: UniconsLine.moon, + ) + ], + ), + ], + ), + + const SizedBox(height: 16), + AppTitle2(text: tr('settings_title_game')), // Timer value diff --git a/lib/ui/widgets/theme_card.dart b/lib/ui/widgets/theme_card.dart new file mode 100644 index 0000000000000000000000000000000000000000..bd935ab73dd26ff465d628f7fb82f3b1bdbad85c --- /dev/null +++ b/lib/ui/widgets/theme_card.dart @@ -0,0 +1,45 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +import 'package:twister/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.yaml b/pubspec.yaml index a7661d9cac5042925cee0c2ec1bdef92da8bc120..e6a8bc41e5a09e4432ab7c7e9a1dce819d52aef7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: twister game companion publish_to: 'none' -version: 0.0.20+20 +version: 0.0.21+21 environment: sdk: '^3.0.0'