From fe47d3a756004b51cd57e01c4a2d160c41974ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Thu, 24 Oct 2024 12:10:22 +0200 Subject: [PATCH] Normalize Activity application architecture --- assets/translations/en.json | 1 + assets/translations/fr.json | 1 + .../metadata/android/en-US/changelogs/24.txt | 1 + .../metadata/android/fr-FR/changelogs/24.txt | 1 + lib/{ => common}/config/activity_page.dart | 40 +++++---- lib/{ => common}/config/screen.dart | 22 ++--- .../cubit/nav}/nav_cubit_pages.dart | 8 +- .../cubit/nav}/nav_cubit_screens.dart | 12 +-- lib/{ => common}/ui/nav/bottom_nav_bar.dart | 18 ++-- lib/common/ui/nav/global_app_bar.dart | 86 +++++++++++++++++++ lib/{ => common}/ui/pages/home.dart | 2 +- lib/{ => common}/ui/pages/player.dart | 2 +- lib/{ => common}/ui/pages/remote_control.dart | 2 +- lib/{ => common}/ui/screens/about.dart | 0 lib/{ => common}/ui/screens/activity.dart | 6 +- lib/{ => common}/ui/screens/settings.dart | 0 lib/config/application_config.dart | 3 + lib/config/default_activity_settings.dart | 32 +++++++ lib/cubit/{ => activity}/activity_cubit.dart | 0 lib/cubit/{ => activity}/activity_state.dart | 0 .../settings/settings_activity_cubit.dart | 62 +++++++++++++ .../settings/settings_activity_state.dart | 15 ++++ .../{ => settings}/settings_global_cubit.dart | 0 .../{ => settings}/settings_global_state.dart | 0 lib/main.dart | 36 +++++--- lib/models/settings/settings_activity.dart | 42 +++++++++ lib/ui/nav/global_app_bar.dart | 66 -------------- lib/ui/skeleton.dart | 12 +-- lib/ui/widgets/activity/activity_bottom.dart | 2 +- lib/ui/widgets/activity/activity_content.dart | 2 +- lib/ui/widgets/keyboard.dart | 2 +- lib/utils/api.dart | 2 +- pubspec.lock | 8 +- pubspec.yaml | 2 +- 34 files changed, 342 insertions(+), 146 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/24.txt create mode 100644 fastlane/metadata/android/fr-FR/changelogs/24.txt rename lib/{ => common}/config/activity_page.dart (57%) rename lib/{ => common}/config/screen.dart (67%) rename lib/{cubit => common/cubit/nav}/nav_cubit_pages.dart (72%) rename lib/{cubit => common/cubit/nav}/nav_cubit_screens.dart (71%) rename lib/{ => common}/ui/nav/bottom_nav_bar.dart (75%) create mode 100644 lib/common/ui/nav/global_app_bar.dart rename lib/{ => common}/ui/pages/home.dart (94%) rename lib/{ => common}/ui/pages/player.dart (94%) rename lib/{ => common}/ui/pages/remote_control.dart (94%) rename lib/{ => common}/ui/screens/about.dart (100%) rename lib/{ => common}/ui/screens/activity.dart (67%) rename lib/{ => common}/ui/screens/settings.dart (100%) create mode 100644 lib/config/application_config.dart create mode 100644 lib/config/default_activity_settings.dart rename lib/cubit/{ => activity}/activity_cubit.dart (100%) rename lib/cubit/{ => activity}/activity_state.dart (100%) create mode 100644 lib/cubit/settings/settings_activity_cubit.dart create mode 100644 lib/cubit/settings/settings_activity_state.dart rename lib/cubit/{ => settings}/settings_global_cubit.dart (100%) rename lib/cubit/{ => settings}/settings_global_state.dart (100%) create mode 100644 lib/models/settings/settings_activity.dart delete mode 100644 lib/ui/nav/global_app_bar.dart diff --git a/assets/translations/en.json b/assets/translations/en.json index b060f0b..e0fb8cf 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -10,6 +10,7 @@ "about_version": "Version: {version}", "page_home": "Home", + "page_player": "Player", "page_remote_control": "Control", "": "" diff --git a/assets/translations/fr.json b/assets/translations/fr.json index 7185156..26f3a4e 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -10,6 +10,7 @@ "about_version": "Version : {version}", "page_home": "Accueil", + "page_player": "Player", "page_remote_control": "Télécommande", "": "" diff --git a/fastlane/metadata/android/en-US/changelogs/24.txt b/fastlane/metadata/android/en-US/changelogs/24.txt new file mode 100644 index 0000000..ac2c90e --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/24.txt @@ -0,0 +1 @@ +Normalize Activity application architecture. diff --git a/fastlane/metadata/android/fr-FR/changelogs/24.txt b/fastlane/metadata/android/fr-FR/changelogs/24.txt new file mode 100644 index 0000000..1d6843d --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/24.txt @@ -0,0 +1 @@ +Harmonisation des applications en Activity. diff --git a/lib/config/activity_page.dart b/lib/common/config/activity_page.dart similarity index 57% rename from lib/config/activity_page.dart rename to lib/common/config/activity_page.dart index 9dbf249..5b8b165 100644 --- a/lib/config/activity_page.dart +++ b/lib/common/config/activity_page.dart @@ -1,53 +1,59 @@ import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/ui/pages/remote_control.dart'; -import 'package:plotter/ui/pages/home.dart'; +import 'package:plotter/common/ui/pages/home.dart'; +import 'package:plotter/common/ui/pages/player.dart'; +import 'package:plotter/common/ui/pages/remote_control.dart'; class ActivityPageItem { + final String code; final Icon icon; final Widget page; - final String code; const ActivityPageItem({ + required this.code, required this.icon, required this.page, - required this.code, }); } class ActivityPage { + static const bool displayBottomNavBar = true; + static const indexHome = 0; static const pageHome = ActivityPageItem( + code: 'page_home', icon: Icon(UniconsLine.home), page: PageHome(), - code: 'page_home', ); - static const indexRemoteControl = 1; + static const indexPlayer = 1; + static const pagePlayer = ActivityPageItem( + code: 'page_player', + icon: Icon(UniconsLine.star), + page: PagePlayer(), + ); + + static const indexRemoteControl = 2; static const pageRemoteControl = ActivityPageItem( - icon: Icon(UniconsLine.arrow), - page: PageRemoteControl(), code: 'page_remote_control', + icon: Icon(UniconsLine.star), + page: PageRemoteControl(), ); - static Map<int, ActivityPageItem> items = { + static const Map<int, ActivityPageItem> items = { indexHome: pageHome, + indexPlayer: pagePlayer, indexRemoteControl: pageRemoteControl, }; + static int defaultPageIndex = indexHome; + static bool isIndexAllowed(int pageIndex) { return items.keys.contains(pageIndex); } - static ActivityPageItem getPageItem(int pageIndex) { - return items[pageIndex] ?? pageHome; - } - - static Widget getPageWidget(int pageIndex) { + static Widget getWidget(int pageIndex) { return items[pageIndex]?.page ?? pageHome.page; } - - static int itemsCount = ActivityPage.items.length; } diff --git a/lib/config/screen.dart b/lib/common/config/screen.dart similarity index 67% rename from lib/config/screen.dart rename to lib/common/config/screen.dart index 5abef98..4d563ca 100644 --- a/lib/config/screen.dart +++ b/lib/common/config/screen.dart @@ -1,42 +1,42 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/ui/screens/about.dart'; -import 'package:plotter/ui/screens/activity.dart'; -import 'package:plotter/ui/screens/settings.dart'; +import 'package:plotter/common/ui/screens/about.dart'; +import 'package:plotter/common/ui/screens/activity.dart'; +import 'package:plotter/common/ui/screens/settings.dart'; class ScreenItem { + final String code; final Icon icon; final Widget screen; - final bool displayBottomNavBar; const ScreenItem({ + required this.code, required this.icon, required this.screen, - required this.displayBottomNavBar, }); } class Screen { static const indexActivity = 0; static const screenActivity = ScreenItem( + code: 'screen_activity', icon: Icon(UniconsLine.home), screen: ScreenActivity(), - displayBottomNavBar: true, ); static const indexSettings = 1; static const screenSettings = ScreenItem( + code: 'screen_settings', icon: Icon(UniconsLine.setting), screen: ScreenSettings(), - displayBottomNavBar: false, ); static const indexAbout = 2; static const screenAbout = ScreenItem( + code: 'screen_about', icon: Icon(UniconsLine.info_circle), screen: ScreenAbout(), - displayBottomNavBar: false, ); static Map<int, ScreenItem> items = { @@ -52,10 +52,4 @@ class Screen { static Widget getWidget(int screenIndex) { return items[screenIndex]?.screen ?? screenActivity.screen; } - - static bool displayBottomNavBar(int screenIndex) { - return items[screenIndex]?.displayBottomNavBar ?? screenActivity.displayBottomNavBar; - } - - static int itemsCount = Screen.items.length; } diff --git a/lib/cubit/nav_cubit_pages.dart b/lib/common/cubit/nav/nav_cubit_pages.dart similarity index 72% rename from lib/cubit/nav_cubit_pages.dart rename to lib/common/cubit/nav/nav_cubit_pages.dart index 59a601b..c8416f2 100644 --- a/lib/cubit/nav_cubit_pages.dart +++ b/lib/common/cubit/nav/nav_cubit_pages.dart @@ -1,6 +1,6 @@ import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/config/activity_page.dart'; +import 'package:plotter/common/config/activity_page.dart'; class NavCubitPage extends HydratedCubit<int> { NavCubitPage() : super(0); @@ -13,6 +13,10 @@ class NavCubitPage extends HydratedCubit<int> { } } + void goToPageHome() { + updateIndex(ActivityPage.indexHome); + } + @override int fromJson(Map<String, dynamic> json) { return ActivityPage.indexHome; @@ -20,6 +24,6 @@ class NavCubitPage extends HydratedCubit<int> { @override Map<String, dynamic>? toJson(int state) { - return <String, int>{'pageIndex': state}; + return <String, int>{'index': state}; } } diff --git a/lib/cubit/nav_cubit_screens.dart b/lib/common/cubit/nav/nav_cubit_screens.dart similarity index 71% rename from lib/cubit/nav_cubit_screens.dart rename to lib/common/cubit/nav/nav_cubit_screens.dart index 02e63d9..b19b206 100644 --- a/lib/cubit/nav_cubit_screens.dart +++ b/lib/common/cubit/nav/nav_cubit_screens.dart @@ -1,6 +1,6 @@ import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/config/screen.dart'; +import 'package:plotter/common/config/screen.dart'; class NavCubitScreen extends HydratedCubit<int> { NavCubitScreen() : super(0); @@ -9,19 +9,19 @@ class NavCubitScreen extends HydratedCubit<int> { if (Screen.isIndexAllowed(index)) { emit(index); } else { - goToActivityPage(); + goToScreenActivity(); } } - void goToActivityPage() { + void goToScreenActivity() { emit(Screen.indexActivity); } - void goToSettingsPage() { + void goToScreenSettings() { emit(Screen.indexSettings); } - void goToAboutPage() { + void goToScreenAbout() { emit(Screen.indexAbout); } @@ -32,6 +32,6 @@ class NavCubitScreen extends HydratedCubit<int> { @override Map<String, dynamic>? toJson(int state) { - return <String, int>{'screenIndex': state}; + return <String, int>{'index': state}; } } diff --git a/lib/ui/nav/bottom_nav_bar.dart b/lib/common/ui/nav/bottom_nav_bar.dart similarity index 75% rename from lib/ui/nav/bottom_nav_bar.dart rename to lib/common/ui/nav/bottom_nav_bar.dart index 2fd9720..9b11034 100644 --- a/lib/ui/nav/bottom_nav_bar.dart +++ b/lib/common/ui/nav/bottom_nav_bar.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/config/activity_page.dart'; -import 'package:plotter/cubit/nav_cubit_pages.dart'; +import 'package:plotter/common/config/activity_page.dart'; +import 'package:plotter/common/cubit/nav/nav_cubit_pages.dart'; class BottomNavBar extends StatelessWidget { const BottomNavBar({super.key}); @@ -21,16 +21,14 @@ class BottomNavBar extends StatelessWidget { ), ), child: BlocBuilder<NavCubitPage, int>(builder: (BuildContext context, int state) { - final List<ActivityPageItem> pageItems = [ - ActivityPage.pageHome, - ActivityPage.pageRemoteControl, - ]; - final List<BottomNavigationBarItem> items = pageItems.map((ActivityPageItem item) { - return BottomNavigationBarItem( + final List<BottomNavigationBarItem> items = []; + + ActivityPage.items.forEach((int pageIndex, ActivityPageItem item) { + items.add(BottomNavigationBarItem( icon: item.icon, label: tr(item.code), - ); - }).toList(); + )); + }); return BottomNavigationBar( currentIndex: state, diff --git a/lib/common/ui/nav/global_app_bar.dart b/lib/common/ui/nav/global_app_bar.dart new file mode 100644 index 0000000..839a28e --- /dev/null +++ b/lib/common/ui/nav/global_app_bar.dart @@ -0,0 +1,86 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; + +import 'package:plotter/common/config/screen.dart'; +import 'package:plotter/common/cubit/nav/nav_cubit_pages.dart'; +import 'package:plotter/common/cubit/nav/nav_cubit_screens.dart'; + +import 'package:plotter/cubit/activity/activity_cubit.dart'; +import 'package:plotter/models/activity/activity.dart'; + +class GlobalAppBar extends StatelessWidget implements PreferredSizeWidget { + const GlobalAppBar({super.key}); + + @override + Widget build(BuildContext context) { + return BlocBuilder<ActivityCubit, ActivityState>( + builder: (BuildContext context, ActivityState activityState) { + return BlocBuilder<NavCubitScreen, int>( + builder: (BuildContext context, int pageIndex) { + final Activity currentActivity = activityState.currentActivity; + + final List<Widget> menuActions = []; + + if (currentActivity.isRunning) { + menuActions.add(StyledButton( + color: Colors.red, + onPressed: () {}, + onLongPress: () { + BlocProvider.of<ActivityCubit>(context).quitActivity(); + BlocProvider.of<NavCubitPage>(context).goToPageHome(); + }, + child: const Image( + image: AssetImage('assets/ui/button_back.png'), + fit: BoxFit.fill, + ), + )); + } else { + if (pageIndex == Screen.indexActivity) { + // go to Settings page + menuActions.add(ElevatedButton( + onPressed: () { + BlocProvider.of<NavCubitScreen>(context).goToScreenSettings(); + }, + style: ElevatedButton.styleFrom( + shape: const CircleBorder(), + ), + child: Screen.screenSettings.icon, + )); + + // go to About page + menuActions.add(ElevatedButton( + onPressed: () { + BlocProvider.of<NavCubitScreen>(context).goToScreenAbout(); + }, + style: ElevatedButton.styleFrom( + shape: const CircleBorder(), + ), + child: Screen.screenAbout.icon, + )); + } else { + // back to Home page + menuActions.add(ElevatedButton( + onPressed: () { + BlocProvider.of<NavCubitScreen>(context).goToScreenActivity(); + }, + style: ElevatedButton.styleFrom( + shape: const CircleBorder(), + ), + child: Screen.screenActivity.icon, + )); + } + } + + return AppBar( + title: const AppHeader(text: 'app_name'), + actions: menuActions, + ); + }, + ); + }, + ); + } + + @override + Size get preferredSize => const Size.fromHeight(50); +} diff --git a/lib/ui/pages/home.dart b/lib/common/ui/pages/home.dart similarity index 94% rename from lib/ui/pages/home.dart rename to lib/common/ui/pages/home.dart index 410852b..a72ff7f 100644 --- a/lib/ui/pages/home.dart +++ b/lib/common/ui/pages/home.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/cubit/activity_cubit.dart'; +import 'package:plotter/cubit/activity/activity_cubit.dart'; import 'package:plotter/models/activity/activity.dart'; class PageHome extends StatelessWidget { diff --git a/lib/ui/pages/player.dart b/lib/common/ui/pages/player.dart similarity index 94% rename from lib/ui/pages/player.dart rename to lib/common/ui/pages/player.dart index 56acd81..5a74c8c 100644 --- a/lib/ui/pages/player.dart +++ b/lib/common/ui/pages/player.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/cubit/activity_cubit.dart'; +import 'package:plotter/cubit/activity/activity_cubit.dart'; import 'package:plotter/models/activity/activity.dart'; class PagePlayer extends StatelessWidget { diff --git a/lib/ui/pages/remote_control.dart b/lib/common/ui/pages/remote_control.dart similarity index 94% rename from lib/ui/pages/remote_control.dart rename to lib/common/ui/pages/remote_control.dart index 58ef59d..2038d02 100644 --- a/lib/ui/pages/remote_control.dart +++ b/lib/common/ui/pages/remote_control.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/cubit/activity_cubit.dart'; +import 'package:plotter/cubit/activity/activity_cubit.dart'; import 'package:plotter/models/activity/activity.dart'; import 'package:plotter/ui/widgets/keyboard.dart'; import 'package:plotter/utils/api.dart'; diff --git a/lib/ui/screens/about.dart b/lib/common/ui/screens/about.dart similarity index 100% rename from lib/ui/screens/about.dart rename to lib/common/ui/screens/about.dart diff --git a/lib/ui/screens/activity.dart b/lib/common/ui/screens/activity.dart similarity index 67% rename from lib/ui/screens/activity.dart rename to lib/common/ui/screens/activity.dart index 8263863..56427c1 100644 --- a/lib/ui/screens/activity.dart +++ b/lib/common/ui/screens/activity.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/config/activity_page.dart'; -import 'package:plotter/cubit/nav_cubit_pages.dart'; +import 'package:plotter/common/config/activity_page.dart'; +import 'package:plotter/common/cubit/nav/nav_cubit_pages.dart'; class ScreenActivity extends StatelessWidget { const ScreenActivity({super.key}); @@ -11,7 +11,7 @@ class ScreenActivity extends StatelessWidget { Widget build(BuildContext context) { return BlocBuilder<NavCubitPage, int>( builder: (BuildContext context, int pageIndex) { - return ActivityPage.getPageWidget(pageIndex); + return ActivityPage.getWidget(pageIndex); }, ); } diff --git a/lib/ui/screens/settings.dart b/lib/common/ui/screens/settings.dart similarity index 100% rename from lib/ui/screens/settings.dart rename to lib/common/ui/screens/settings.dart diff --git a/lib/config/application_config.dart b/lib/config/application_config.dart new file mode 100644 index 0000000..81de9d3 --- /dev/null +++ b/lib/config/application_config.dart @@ -0,0 +1,3 @@ +class ApplicationConfig { + static const String appTitle = 'Stepper plotter assistant'; +} diff --git a/lib/config/default_activity_settings.dart b/lib/config/default_activity_settings.dart new file mode 100644 index 0000000..3f4d852 --- /dev/null +++ b/lib/config/default_activity_settings.dart @@ -0,0 +1,32 @@ +import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; + +class DefaultActivitySettings { + // available game parameters codes + static const String parameterCodePlotterType = 'plotterType'; + static const List<String> availableParameters = [ + parameterCodePlotterType, + ]; + + // plotter type: available values + static const String plotterTypeNone = 'none'; + static const String plotterTypeRadial = 'radial'; + static const String plotterTypeAxial = 'axial'; + static const List<String> allowedPlotterTypeValues = [ + plotterTypeNone, + plotterTypeRadial, + plotterTypeAxial, + ]; + // items count: default value + static const String defaultPlotterTypeValue = plotterTypeNone; + + // available values from parameter code + static List<String> getAvailableValues(String parameterCode) { + switch (parameterCode) { + case parameterCodePlotterType: + return DefaultActivitySettings.allowedPlotterTypeValues; + } + + printlog('Did not find any available value for game parameter "$parameterCode".'); + return []; + } +} diff --git a/lib/cubit/activity_cubit.dart b/lib/cubit/activity/activity_cubit.dart similarity index 100% rename from lib/cubit/activity_cubit.dart rename to lib/cubit/activity/activity_cubit.dart diff --git a/lib/cubit/activity_state.dart b/lib/cubit/activity/activity_state.dart similarity index 100% rename from lib/cubit/activity_state.dart rename to lib/cubit/activity/activity_state.dart diff --git a/lib/cubit/settings/settings_activity_cubit.dart b/lib/cubit/settings/settings_activity_cubit.dart new file mode 100644 index 0000000..a3d1c72 --- /dev/null +++ b/lib/cubit/settings/settings_activity_cubit.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; + +import 'package:plotter/config/default_activity_settings.dart'; +import 'package:plotter/models/settings/settings_activity.dart'; + +part 'settings_activity_state.dart'; + +class ActivitySettingsCubit extends HydratedCubit<ActivitySettingsState> { + ActivitySettingsCubit() + : super(ActivitySettingsState(settings: ActivitySettings.createDefault())); + + void setValues({ + String? plotterType, + }) { + emit( + ActivitySettingsState( + settings: ActivitySettings( + plotterType: plotterType ?? state.settings.plotterType, + ), + ), + ); + } + + String getParameterValue(String code) { + switch (code) { + case DefaultActivitySettings.parameterCodePlotterType: + return ActivitySettings.getPlotterTypeValueFromUnsafe(state.settings.plotterType); + } + + return ''; + } + + void setParameterValue(String code, String value) { + final String plotterType = code == DefaultActivitySettings.parameterCodePlotterType + ? value + : getParameterValue(DefaultActivitySettings.parameterCodePlotterType); + + setValues( + plotterType: plotterType, + ); + } + + @override + ActivitySettingsState? fromJson(Map<String, dynamic> json) { + final String plotterType = + json[DefaultActivitySettings.parameterCodePlotterType] as String; + + return ActivitySettingsState( + settings: ActivitySettings( + plotterType: plotterType, + ), + ); + } + + @override + Map<String, dynamic>? toJson(ActivitySettingsState state) { + return <String, dynamic>{ + DefaultActivitySettings.parameterCodePlotterType: state.settings.plotterType, + }; + } +} diff --git a/lib/cubit/settings/settings_activity_state.dart b/lib/cubit/settings/settings_activity_state.dart new file mode 100644 index 0000000..2b2de42 --- /dev/null +++ b/lib/cubit/settings/settings_activity_state.dart @@ -0,0 +1,15 @@ +part of 'settings_activity_cubit.dart'; + +@immutable +class ActivitySettingsState extends Equatable { + const ActivitySettingsState({ + required this.settings, + }); + + final ActivitySettings settings; + + @override + List<dynamic> get props => <dynamic>[ + settings, + ]; +} diff --git a/lib/cubit/settings_global_cubit.dart b/lib/cubit/settings/settings_global_cubit.dart similarity index 100% rename from lib/cubit/settings_global_cubit.dart rename to lib/cubit/settings/settings_global_cubit.dart diff --git a/lib/cubit/settings_global_state.dart b/lib/cubit/settings/settings_global_state.dart similarity index 100% rename from lib/cubit/settings_global_state.dart rename to lib/cubit/settings/settings_global_state.dart diff --git a/lib/main.dart b/lib/main.dart index 4a18a15..3fb2ddd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,10 +4,13 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/cubit/activity_cubit.dart'; -import 'package:plotter/cubit/nav_cubit_pages.dart'; -import 'package:plotter/cubit/nav_cubit_screens.dart'; -import 'package:plotter/cubit/settings_global_cubit.dart'; +import 'package:plotter/common/cubit/nav/nav_cubit_pages.dart'; +import 'package:plotter/common/cubit/nav/nav_cubit_screens.dart'; + +import 'package:plotter/config/application_config.dart'; +import 'package:plotter/cubit/activity/activity_cubit.dart'; +import 'package:plotter/cubit/settings/settings_activity_cubit.dart'; +import 'package:plotter/cubit/settings/settings_global_cubit.dart'; import 'package:plotter/ui/skeleton.dart'; void main() async { @@ -40,17 +43,30 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ - BlocProvider<NavCubitPage>(create: (context) => NavCubitPage()), - BlocProvider<NavCubitScreen>(create: (context) => NavCubitScreen()), + // default providers + BlocProvider<NavCubitPage>( + create: (context) => NavCubitPage(), + ), + BlocProvider<NavCubitScreen>( + create: (context) => NavCubitScreen(), + ), BlocProvider<ApplicationThemeModeCubit>( - create: (context) => ApplicationThemeModeCubit()), - BlocProvider<ActivityCubit>(create: (context) => ActivityCubit()), - BlocProvider<GlobalSettingsCubit>(create: (context) => GlobalSettingsCubit()), + create: (context) => ApplicationThemeModeCubit(), + ), + BlocProvider<ActivityCubit>( + create: (context) => ActivityCubit(), + ), + BlocProvider<GlobalSettingsCubit>( + create: (context) => GlobalSettingsCubit(), + ), + BlocProvider<ActivitySettingsCubit>( + create: (context) => ActivitySettingsCubit(), + ), ], child: BlocBuilder<ApplicationThemeModeCubit, ApplicationThemeModeState>( builder: (BuildContext context, ApplicationThemeModeState state) { return MaterialApp( - title: 'Stepper plotter assistant', + title: ApplicationConfig.appTitle, home: const SkeletonScreen(), // Theme stuff diff --git a/lib/models/settings/settings_activity.dart b/lib/models/settings/settings_activity.dart new file mode 100644 index 0000000..4b85637 --- /dev/null +++ b/lib/models/settings/settings_activity.dart @@ -0,0 +1,42 @@ +import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; + +import 'package:plotter/config/default_activity_settings.dart'; + +class ActivitySettings { + final String plotterType; + + ActivitySettings({ + required this.plotterType, + }); + + static String getPlotterTypeValueFromUnsafe(String plotterType) { + if (DefaultActivitySettings.allowedPlotterTypeValues.contains(plotterType)) { + return plotterType; + } + + return DefaultActivitySettings.defaultPlotterTypeValue; + } + + factory ActivitySettings.createDefault() { + return ActivitySettings( + plotterType: DefaultActivitySettings.defaultPlotterTypeValue, + ); + } + + void dump() { + printlog('$ActivitySettings:'); + printlog(' ${DefaultActivitySettings.parameterCodePlotterType}: $plotterType'); + printlog(''); + } + + @override + String toString() { + return '$ActivitySettings(${toJson()})'; + } + + Map<String, dynamic>? toJson() { + return <String, dynamic>{ + DefaultActivitySettings.parameterCodePlotterType: plotterType, + }; + } +} diff --git a/lib/ui/nav/global_app_bar.dart b/lib/ui/nav/global_app_bar.dart deleted file mode 100644 index 7b988c0..0000000 --- a/lib/ui/nav/global_app_bar.dart +++ /dev/null @@ -1,66 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; - -import 'package:plotter/config/screen.dart'; -import 'package:plotter/cubit/activity_cubit.dart'; -import 'package:plotter/cubit/nav_cubit_screens.dart'; - -class GlobalAppBar extends StatelessWidget implements PreferredSizeWidget { - const GlobalAppBar({super.key}); - - @override - Widget build(BuildContext context) { - return BlocBuilder<ActivityCubit, ActivityState>( - builder: (BuildContext context, ActivityState activityState) { - return BlocBuilder<NavCubitScreen, int>( - builder: (BuildContext context, int screenIndex) { - final List<Widget> menuActions = []; - - if (screenIndex == Screen.indexActivity) { - // go to Settings page - menuActions.add(ElevatedButton( - onPressed: () { - BlocProvider.of<NavCubitScreen>(context).goToSettingsPage(); - }, - style: ElevatedButton.styleFrom( - shape: const CircleBorder(), - ), - child: Screen.screenSettings.icon, - )); - - // go to About page - menuActions.add(ElevatedButton( - onPressed: () { - BlocProvider.of<NavCubitScreen>(context).goToAboutPage(); - }, - style: ElevatedButton.styleFrom( - shape: const CircleBorder(), - ), - child: Screen.screenAbout.icon, - )); - } else { - // back to Home page - menuActions.add(ElevatedButton( - onPressed: () { - BlocProvider.of<NavCubitScreen>(context).goToActivityPage(); - }, - style: ElevatedButton.styleFrom( - shape: const CircleBorder(), - ), - child: Screen.screenActivity.icon, - )); - } - - return AppBar( - title: const AppHeader(text: 'app_name'), - actions: menuActions, - ); - }, - ); - }, - ); - } - - @override - Size get preferredSize => const Size.fromHeight(50); -} diff --git a/lib/ui/skeleton.dart b/lib/ui/skeleton.dart index 105be41..0463121 100644 --- a/lib/ui/skeleton.dart +++ b/lib/ui/skeleton.dart @@ -1,10 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/config/screen.dart'; -import 'package:plotter/cubit/nav_cubit_screens.dart'; -import 'package:plotter/ui/nav/bottom_nav_bar.dart'; -import 'package:plotter/ui/nav/global_app_bar.dart'; +import 'package:plotter/common/config/activity_page.dart'; +import 'package:plotter/common/config/screen.dart'; +import 'package:plotter/common/cubit/nav/nav_cubit_screens.dart'; +import 'package:plotter/common/ui/nav/global_app_bar.dart'; +import 'package:plotter/common/ui/nav/bottom_nav_bar.dart'; class SkeletonScreen extends StatelessWidget { const SkeletonScreen({super.key}); @@ -28,8 +29,7 @@ class SkeletonScreen extends StatelessWidget { ), ), backgroundColor: Theme.of(context).colorScheme.surface, - bottomNavigationBar: - Screen.displayBottomNavBar(screenIndex) ? const BottomNavBar() : null, + bottomNavigationBar: ActivityPage.displayBottomNavBar ? const BottomNavBar() : null, ); }, ); diff --git a/lib/ui/widgets/activity/activity_bottom.dart b/lib/ui/widgets/activity/activity_bottom.dart index e5c7f81..5c5c0bb 100644 --- a/lib/ui/widgets/activity/activity_bottom.dart +++ b/lib/ui/widgets/activity/activity_bottom.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/cubit/activity_cubit.dart'; +import 'package:plotter/cubit/activity/activity_cubit.dart'; import 'package:plotter/models/activity/activity.dart'; class ActivityBottomWidget extends StatelessWidget { diff --git a/lib/ui/widgets/activity/activity_content.dart b/lib/ui/widgets/activity/activity_content.dart index 998a4d0..ca7268b 100644 --- a/lib/ui/widgets/activity/activity_content.dart +++ b/lib/ui/widgets/activity/activity_content.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/cubit/activity_cubit.dart'; +import 'package:plotter/cubit/activity/activity_cubit.dart'; import 'package:plotter/models/activity/activity.dart'; class ActivityContentWidget extends StatelessWidget { diff --git a/lib/ui/widgets/keyboard.dart b/lib/ui/widgets/keyboard.dart index a7dcef1..c9981f2 100644 --- a/lib/ui/widgets/keyboard.dart +++ b/lib/ui/widgets/keyboard.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; -import 'package:plotter/cubit/activity_cubit.dart'; +import 'package:plotter/cubit/activity/activity_cubit.dart'; import 'package:plotter/utils/api.dart'; class Keyboard extends StatelessWidget { diff --git a/lib/utils/api.dart b/lib/utils/api.dart index 3767284..7c4ca6c 100644 --- a/lib/utils/api.dart +++ b/lib/utils/api.dart @@ -1,6 +1,6 @@ import 'dart:convert'; import 'package:http/http.dart' as http; -import 'package:plotter/cubit/activity_cubit.dart'; +import 'package:plotter/cubit/activity/activity_cubit.dart'; import 'package:plotter/models/activity/activity.dart'; class Api { diff --git a/pubspec.lock b/pubspec.lock index 1ec777c..8ca9509 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -245,10 +245,10 @@ packages: dependency: transitive description: name: path_provider - sha256: fec0d61223fba3154d87759e3cc27fe2c8dc498f6386c6d6fc80d1afdd1bf378 + sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd" url: "https://pub.dev" source: hosted - version: "2.1.4" + version: "2.1.5" path_provider_android: dependency: transitive description: @@ -442,10 +442,10 @@ packages: dependency: transitive description: name: win32 - sha256: "2735daae5150e8b1dfeb3eb0544b4d3af0061e9e82cef063adcd583bdae4306a" + sha256: "10169d3934549017f0ae278ccb07f828f9d6ea21573bab0fb77b0e1ef0fce454" url: "https://pub.dev" source: hosted - version: "5.7.0" + version: "5.7.2" xdg_directories: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index bb9ac33..4a04155 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A plotter helper application. publish_to: "none" -version: 0.2.1+23 +version: 0.3.0+24 environment: sdk: "^3.0.0" -- GitLab