Skip to content
Snippets Groups Projects
Commit 30c1729c authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Use ApplicationSettings widgets from flutter_custom_toolbox

parent b2acf8cc
No related branches found
No related tags found
1 merge request!15Resolve "Use ApplicationSettings widgets from flutter_custom_toolbox"
Pipeline #6568 passed
This commit is part of merge request !15. Comments created here will be created in the context of that merge request.
Use ApplicationSettings widgets from flutter_custom_toolbox.
Utilisation des widgets ApplicationSettings depuis flutter_custom_toolbox.
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()};
}
}
part of 'theme_cubit.dart';
@immutable
class ThemeModeState extends Equatable {
const ThemeModeState({
this.themeMode,
});
final ThemeMode? themeMode;
@override
List<Object?> get props => <Object?>[
themeMode,
];
}
...@@ -9,7 +9,6 @@ import 'package:midisynth/cubit/settings_activity_cubit.dart'; ...@@ -9,7 +9,6 @@ import 'package:midisynth/cubit/settings_activity_cubit.dart';
import 'package:midisynth/cubit/nav_cubit_pages.dart'; import 'package:midisynth/cubit/nav_cubit_pages.dart';
import 'package:midisynth/cubit/nav_cubit_screens.dart'; import 'package:midisynth/cubit/nav_cubit_screens.dart';
import 'package:midisynth/cubit/settings_global_cubit.dart'; import 'package:midisynth/cubit/settings_global_cubit.dart';
import 'package:midisynth/cubit/theme_cubit.dart';
import 'package:midisynth/ui/skeleton.dart'; import 'package:midisynth/ui/skeleton.dart';
void main() async { void main() async {
...@@ -44,13 +43,14 @@ class MyApp extends StatelessWidget { ...@@ -44,13 +43,14 @@ class MyApp extends StatelessWidget {
providers: [ providers: [
BlocProvider<NavCubitPage>(create: (context) => NavCubitPage()), BlocProvider<NavCubitPage>(create: (context) => NavCubitPage()),
BlocProvider<NavCubitScreen>(create: (context) => NavCubitScreen()), BlocProvider<NavCubitScreen>(create: (context) => NavCubitScreen()),
BlocProvider<ThemeCubit>(create: (context) => ThemeCubit()), BlocProvider<ApplicationThemeModeCubit>(
create: (context) => ApplicationThemeModeCubit()),
BlocProvider<ActivityCubit>(create: (context) => ActivityCubit()), BlocProvider<ActivityCubit>(create: (context) => ActivityCubit()),
BlocProvider<GlobalSettingsCubit>(create: (context) => GlobalSettingsCubit()), BlocProvider<GlobalSettingsCubit>(create: (context) => GlobalSettingsCubit()),
BlocProvider<ActivitySettingsCubit>(create: (context) => ActivitySettingsCubit()), BlocProvider<ActivitySettingsCubit>(create: (context) => ActivitySettingsCubit()),
], ],
child: BlocBuilder<ThemeCubit, ThemeModeState>( child: BlocBuilder<ApplicationThemeModeCubit, ApplicationThemeModeState>(
builder: (BuildContext context, ThemeModeState state) { builder: (BuildContext context, ApplicationThemeModeState state) {
return MaterialApp( return MaterialApp(
title: 'MIDI Synth', title: 'MIDI Synth',
home: const SkeletonScreen(), home: const SkeletonScreen(),
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
import 'package:midisynth/ui/settings/settings_form.dart';
class ScreenSettings extends StatelessWidget { class ScreenSettings extends StatelessWidget {
const ScreenSettings({super.key}); const ScreenSettings({super.key});
...@@ -18,7 +16,7 @@ class ScreenSettings extends StatelessWidget { ...@@ -18,7 +16,7 @@ class ScreenSettings extends StatelessWidget {
SizedBox(height: 8), SizedBox(height: 8),
AppTitle(text: 'settings_title'), AppTitle(text: 'settings_title'),
SizedBox(height: 8), SizedBox(height: 8),
SettingsForm(), ApplicationSettingsForm(),
], ],
), ),
); );
......
import 'package:flutter/material.dart';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
import 'package:midisynth/ui/settings/theme_card.dart';
class SettingsForm extends StatefulWidget {
const SettingsForm({super.key});
@override
State<SettingsForm> createState() => _SettingsFormState();
}
class _SettingsFormState extends State<SettingsForm> {
@override
void dispose() {
super.dispose();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
// 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),
],
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
import 'package:midisynth/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,
),
),
);
},
);
}
}
...@@ -122,11 +122,11 @@ packages: ...@@ -122,11 +122,11 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: "0.1.1" ref: "0.2.0"
resolved-ref: ba7137ca9edec7e503ed3dbfe7f6ede7e9cfbf4d resolved-ref: bbf0abd5457d42678882384216af9e83c38549bc
url: "https://git.harrault.fr/android/flutter-toolbox.git" url: "https://git.harrault.fr/android/flutter-toolbox.git"
source: git source: git
version: "0.1.1" version: "0.2.0"
flutter_lints: flutter_lints:
dependency: "direct dev" dependency: "direct dev"
description: description:
......
...@@ -3,7 +3,7 @@ description: MIDI Synth ...@@ -3,7 +3,7 @@ description: MIDI Synth
publish_to: "none" publish_to: "none"
version: 0.2.0+14 version: 0.2.1+15
environment: environment:
sdk: "^3.0.0" sdk: "^3.0.0"
...@@ -16,7 +16,7 @@ dependencies: ...@@ -16,7 +16,7 @@ dependencies:
flutter_custom_toolbox: flutter_custom_toolbox:
git: git:
url: https://git.harrault.fr/android/flutter-toolbox.git url: https://git.harrault.fr/android/flutter-toolbox.git
ref: 0.1.1 ref: 0.2.0
# specific # specific
# (none) # (none)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment