From 1d0df66718c45e186732f5d75c109ea05f467289 Mon Sep 17 00:00:00 2001 From: Gennady Terekhov Date: Tue, 5 Sep 2023 19:35:39 +0300 Subject: [PATCH 1/2] issue-105 --- .gitignore | 2 + integration_test/full_test.dart | 25 +-- lib/app.dart | 96 ++++++++++ lib/di_container.dart | 20 +++ .../business_logic}/exception/not_found.dart | 0 .../business_logic}/exception/wrong_game.dart | 0 .../business_logic}/models/effect.dart | 0 .../business_logic}/models/ingredient.dart | 0 .../business_logic/models/settings.dart | 20 +++ .../services/settings_manager.dart | 10 ++ .../data/resources}/constant.dart | 2 +- .../data/resources}/custom_localization.dart | 9 +- .../data/resources/data_resource.dart} | 18 +- .../data/resources}/effect_resource.dart | 22 +-- .../data/resources}/ingredient_resource.dart | 22 +-- .../data/storage}/l10n/morrowind.dart | 0 .../data/storage}/l10n/oblivion.dart | 0 .../data/storage}/l10n/search_indices.dart | 4 +- .../data/storage}/l10n/skyrim.dart | 0 .../data/storage}/morrowind.dart | 0 .../data/storage}/oblivion.dart | 0 lib/{data => layers/data/storage}/skyrim.dart | 0 lib/{data => layers/data/storage}/teso.dart | 0 .../presentation/widgets/app_widget.dart | 85 +++++++++ .../widgets/components/app_bar.dart | 6 +- .../components/cards/effect/effect_big.dart | 8 +- .../components/cards/effect/effect_long.dart | 6 +- .../components/cards/effect/effect_micro.dart | 6 +- .../components/cards/effect/effect_small.dart | 8 +- .../cards/ingredient/ingredient_big.dart | 8 +- .../cards/ingredient/ingredient_long.dart | 10 +- .../cards/ingredient/ingredient_micro.dart | 4 +- .../cards/ingredient/ingredient_small.dart | 6 +- .../widgets/components/cards_grid.dart | 0 .../widgets/components/divider_text.dart | 0 .../widgets/components/links/image_link.dart | 0 .../widgets/components/links/web_link.dart | 0 .../lists/common_ingredients_by_column.dart | 12 +- .../lists/effects_by_ingredient.dart | 8 +- .../lists/ingredients_by_effect.dart | 8 +- .../widgets/components/search_field.dart | 0 .../navigation/bottom_panel_navigation.dart | 2 +- .../navigation/left_panel_navigation.dart | 2 +- .../widgets/navigation/navigation.dart | 0 .../widgets/pages/effects/effect.dart | 4 +- .../widgets/pages/effects/effects.dart | 21 +-- .../widgets/pages/home/home.dart | 17 +- .../widgets/pages/ingredients/ingredient.dart | 4 +- .../pages/ingredients/ingredients.dart | 15 +- .../widgets/pages/potions/potions.dart | 0 .../widgets/pages/search/search.dart | 12 +- .../widgets/screens/custom_screen.dart | 8 +- .../widgets/screens/effect_screen.dart | 21 +++ .../widgets/screens/effects_screen.dart | 4 +- .../widgets/screens/error_screen.dart | 2 +- .../widgets/screens/home_screen.dart | 4 +- .../widgets/screens/ingredient_screen.dart | 10 +- .../widgets/screens/ingredients_screen.dart | 4 +- .../widgets/screens/search_screen.dart | 4 +- .../state/search_field_toggle.dart | 0 lib/main.dart | 166 +----------------- lib/router.dart | 24 +-- lib/widgets/screens/effect_screen.dart | 21 --- pubspec.lock | 7 + pubspec.yaml | 1 + test/data/data_source_test.dart | 12 +- .../components/cards/effect_big_test.dart | 10 +- .../components/cards/effect_small_test.dart | 10 +- .../components/cards/ingredient_big_test.dart | 16 +- 69 files changed, 461 insertions(+), 365 deletions(-) create mode 100644 lib/app.dart create mode 100644 lib/di_container.dart rename lib/{ => layers/business_logic}/exception/not_found.dart (100%) rename lib/{ => layers/business_logic}/exception/wrong_game.dart (100%) rename lib/{ => layers/business_logic}/models/effect.dart (100%) rename lib/{ => layers/business_logic}/models/ingredient.dart (100%) create mode 100644 lib/layers/business_logic/models/settings.dart create mode 100644 lib/layers/business_logic/services/settings_manager.dart rename lib/{data => layers/data/resources}/constant.dart (94%) rename lib/{data/l10n => layers/data/resources}/custom_localization.dart (59%) rename lib/{data/data_source.dart => layers/data/resources/data_resource.dart} (60%) rename lib/{data => layers/data/resources}/effect_resource.dart (73%) rename lib/{data => layers/data/resources}/ingredient_resource.dart (75%) rename lib/{data => layers/data/storage}/l10n/morrowind.dart (100%) rename lib/{data => layers/data/storage}/l10n/oblivion.dart (100%) rename lib/{data => layers/data/storage}/l10n/search_indices.dart (99%) rename lib/{data => layers/data/storage}/l10n/skyrim.dart (100%) rename lib/{data => layers/data/storage}/morrowind.dart (100%) rename lib/{data => layers/data/storage}/oblivion.dart (100%) rename lib/{data => layers/data/storage}/skyrim.dart (100%) rename lib/{data => layers/data/storage}/teso.dart (100%) create mode 100644 lib/layers/presentation/widgets/app_widget.dart rename lib/{ => layers/presentation}/widgets/components/app_bar.dart (84%) rename lib/{ => layers/presentation}/widgets/components/cards/effect/effect_big.dart (68%) rename lib/{ => layers/presentation}/widgets/components/cards/effect/effect_long.dart (87%) rename lib/{ => layers/presentation}/widgets/components/cards/effect/effect_micro.dart (85%) rename lib/{ => layers/presentation}/widgets/components/cards/effect/effect_small.dart (84%) rename lib/{ => layers/presentation}/widgets/components/cards/ingredient/ingredient_big.dart (75%) rename lib/{ => layers/presentation}/widgets/components/cards/ingredient/ingredient_long.dart (86%) rename lib/{ => layers/presentation}/widgets/components/cards/ingredient/ingredient_micro.dart (84%) rename lib/{ => layers/presentation}/widgets/components/cards/ingredient/ingredient_small.dart (85%) rename lib/{ => layers/presentation}/widgets/components/cards_grid.dart (100%) rename lib/{ => layers/presentation}/widgets/components/divider_text.dart (100%) rename lib/{ => layers/presentation}/widgets/components/links/image_link.dart (100%) rename lib/{ => layers/presentation}/widgets/components/links/web_link.dart (100%) rename lib/{ => layers/presentation}/widgets/components/lists/common_ingredients_by_column.dart (83%) rename lib/{ => layers/presentation}/widgets/components/lists/effects_by_ingredient.dart (86%) rename lib/{ => layers/presentation}/widgets/components/lists/ingredients_by_effect.dart (87%) rename lib/{ => layers/presentation}/widgets/components/search_field.dart (100%) rename lib/{ => layers/presentation}/widgets/navigation/bottom_panel_navigation.dart (93%) rename lib/{ => layers/presentation}/widgets/navigation/left_panel_navigation.dart (93%) rename lib/{ => layers/presentation}/widgets/navigation/navigation.dart (100%) rename lib/{ => layers/presentation}/widgets/pages/effects/effect.dart (69%) rename lib/{ => layers/presentation}/widgets/pages/effects/effects.dart (63%) rename lib/{ => layers/presentation}/widgets/pages/home/home.dart (86%) rename lib/{ => layers/presentation}/widgets/pages/ingredients/ingredient.dart (70%) rename lib/{ => layers/presentation}/widgets/pages/ingredients/ingredients.dart (72%) rename lib/{ => layers/presentation}/widgets/pages/potions/potions.dart (100%) rename lib/{ => layers/presentation}/widgets/pages/search/search.dart (73%) rename lib/{ => layers/presentation}/widgets/screens/custom_screen.dart (79%) create mode 100644 lib/layers/presentation/widgets/screens/effect_screen.dart rename lib/{ => layers/presentation}/widgets/screens/effects_screen.dart (64%) rename lib/{ => layers/presentation}/widgets/screens/error_screen.dart (95%) rename lib/{ => layers/presentation}/widgets/screens/home_screen.dart (62%) rename lib/{ => layers/presentation}/widgets/screens/ingredient_screen.dart (53%) rename lib/{ => layers/presentation}/widgets/screens/ingredients_screen.dart (64%) rename lib/{ => layers/presentation}/widgets/screens/search_screen.dart (61%) rename lib/{ => layers/state_management}/state/search_field_toggle.dart (100%) delete mode 100644 lib/widgets/screens/effect_screen.dart diff --git a/.gitignore b/.gitignore index 6ec924e..bc2fa5a 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,5 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +README.local.md \ No newline at end of file diff --git a/integration_test/full_test.dart b/integration_test/full_test.dart index 4bc661c..57ce204 100644 --- a/integration_test/full_test.dart +++ b/integration_test/full_test.dart @@ -1,22 +1,27 @@ import 'package:flutter/material.dart'; +import 'package:flutter_simple_dependency_injection/injector.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; +import 'package:the_elder_scrolls_alchemy_client/app.dart'; +import 'package:the_elder_scrolls_alchemy_client/di_container.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_big.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_small.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/ingredient/ingredient_big.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/search_field.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_big.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_small.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/ingredient/ingredient_big.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/search_field.dart'; void main() { + final dependencyInjectionContainer = DependencyInjectionContainer().initialise(Injector()); + final app = dependencyInjectionContainer.get(); group('general', () { final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding; binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive; testWidgets('Scrolling test', (tester) async { - await tester.pumpWidget(MyApp()); + await tester.pumpWidget(app); await tester.tap(find.text('Effects')); await tester.pump(); @@ -33,7 +38,7 @@ void main() { }); testWidgets('Test inkwell works as a link', (tester) async { - await tester.pumpWidget(MyApp()); + await tester.pumpWidget(app); await tester.tap(find.text('Effects')); await tester.pump(); @@ -54,7 +59,7 @@ void main() { group('home page', () { testWidgets('Change game', (tester) async { - await tester.pumpWidget(MyApp()); + await tester.pumpWidget(app); expect(find.text('Skyrim Alchemy'), findsOneWidget); await tester.tap(find.text('Effects')); @@ -76,7 +81,7 @@ void main() { group('search', () { testWidgets('search', (tester) async { - await tester.pumpWidget(MyApp()); + await tester.pumpWidget(app); await tester.tap(find.text('Effects')); await tester.pump(); diff --git a/lib/app.dart b/lib/app.dart new file mode 100644 index 0000000..92b9e29 --- /dev/null +++ b/lib/app.dart @@ -0,0 +1,96 @@ +import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/services/settings_manager.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/app_widget.dart'; + +class TheElderScrollsAlchemyClientApp extends StatefulWidget { + TheElderScrollsAlchemyClientApp({ + Key? key, + required this.settingsManager, + }) : super(key: key); + + SettingsManager settingsManager; + + @deprecated + static Future getSavedGameName() async { + String? gameNameFromPreferences = await getGameNameFromPreferences(); + if (gameNameFromPreferences == null) { + return Constant.fallbackGameName; + } + return gameNameFromPreferences; + } + + @deprecated + static String getLocaleLanguageCode(BuildContext context) { + return Localizations.localeOf(context).languageCode; + } + + @deprecated + static Future getSafeLanguageCode() async { + String? languageCodeFromPreferences = await getLanguageCodeFromPreferences(); + if (languageCodeFromPreferences == null) { + return Constant.fallbackLanguage; + } + return languageCodeFromPreferences; + } + + @deprecated + static Future getLanguageCodeFromPreferences() async { + final prefs = await SharedPreferences.getInstance(); + final String? languageCode = prefs.getString('languageCode'); + + return languageCode; + } + + @deprecated + static Future getGameNameFromPreferences() async { + final prefs = await SharedPreferences.getInstance(); + final String? gameName = prefs.getString('gameName'); + + return gameName; + } + + @deprecated + static void setLocaleLanguageCode(BuildContext context, String languageCode) async { + _TheElderScrollsAlchemyClientAppState state = + context.findAncestorStateOfType<_TheElderScrollsAlchemyClientAppState>()!; + state.setLocaleLanguageCode(languageCode); + final prefs = await SharedPreferences.getInstance(); + await prefs.setString('languageCode', languageCode); + } + + @deprecated + static void setGameName(BuildContext context, String gameName) async { + _TheElderScrollsAlchemyClientAppState state = + context.findAncestorStateOfType<_TheElderScrollsAlchemyClientAppState>()!; + state.setGameName(gameName); + final prefs = await SharedPreferences.getInstance(); + await prefs.setString('gameName', gameName); + } + + @override + _TheElderScrollsAlchemyClientAppState createState() => _TheElderScrollsAlchemyClientAppState(); +} + +class _TheElderScrollsAlchemyClientAppState extends State { + setLocaleLanguageCode(String languageCode) { + setState(() { + // widget.languageCode = languageCode; + }); + } + + setGameName(String gameName) { + setState(() { + // widget.gameName = gameName; + }); + } + + @override + Widget build(BuildContext context) { + return AppWidget( + languageCode: widget.settingsManager.settings.gameName, + gameName: widget.settingsManager.settings.language, + ); + } +} diff --git a/lib/di_container.dart b/lib/di_container.dart new file mode 100644 index 0000000..52edefc --- /dev/null +++ b/lib/di_container.dart @@ -0,0 +1,20 @@ +import 'package:flutter_simple_dependency_injection/injector.dart'; + +class DependencyInjectionContainer { + + Injector initialise(Injector injector) { + // injector.map((i) => Logger(), isSingleton: true); + // injector.map((i) => "https://api.com/", key: "apiUrl"); + // injector.map( + // (i) => SomeService(i.get(), i.get(key: "apiUrl"))); + + // // note that you can configure mapping in a fluent programming style too + // injector.map((injector) => SomeType("0")) + // ..map((injector) => SomeType("1"), key: "One") + // ..map((injector) => SomeType("2"), key: "Two"); + + // injector.mapWithParams((i, p) => SomeOtherType(p["id"])); + + return injector; + } +} \ No newline at end of file diff --git a/lib/exception/not_found.dart b/lib/layers/business_logic/exception/not_found.dart similarity index 100% rename from lib/exception/not_found.dart rename to lib/layers/business_logic/exception/not_found.dart diff --git a/lib/exception/wrong_game.dart b/lib/layers/business_logic/exception/wrong_game.dart similarity index 100% rename from lib/exception/wrong_game.dart rename to lib/layers/business_logic/exception/wrong_game.dart diff --git a/lib/models/effect.dart b/lib/layers/business_logic/models/effect.dart similarity index 100% rename from lib/models/effect.dart rename to lib/layers/business_logic/models/effect.dart diff --git a/lib/models/ingredient.dart b/lib/layers/business_logic/models/ingredient.dart similarity index 100% rename from lib/models/ingredient.dart rename to lib/layers/business_logic/models/ingredient.dart diff --git a/lib/layers/business_logic/models/settings.dart b/lib/layers/business_logic/models/settings.dart new file mode 100644 index 0000000..e722d46 --- /dev/null +++ b/lib/layers/business_logic/models/settings.dart @@ -0,0 +1,20 @@ +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; + +class Settings { + Settings({ + required this.gameName, + required this.language, + }); + final String gameName; + final String language; + + factory Settings.fromMap(Map data) { + final gameName = data.containsKey('gameName') ? data['gameName'] as String : Constant.fallbackGameName; + final language = data.containsKey('language') ? data['language'] as String : Constant.fallbackLanguage; + + return Settings( + gameName: gameName, + language: language, + ); + } +} diff --git a/lib/layers/business_logic/services/settings_manager.dart b/lib/layers/business_logic/services/settings_manager.dart new file mode 100644 index 0000000..8c10ff4 --- /dev/null +++ b/lib/layers/business_logic/services/settings_manager.dart @@ -0,0 +1,10 @@ +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/settings.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; + +class SettingsManager { + late Settings settings; + + SettingsManager() { + this.settings = Settings(gameName: Constant.fallbackGameName, language: Constant.fallbackLanguage); + } +} diff --git a/lib/data/constant.dart b/lib/layers/data/resources/constant.dart similarity index 94% rename from lib/data/constant.dart rename to lib/layers/data/resources/constant.dart index 7f34749..502a3e4 100644 --- a/lib/data/constant.dart +++ b/lib/layers/data/resources/constant.dart @@ -1,4 +1,4 @@ -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; import 'package:the_elder_scrolls_alchemy_client/extensions/capitalize.dart'; class Constant { diff --git a/lib/data/l10n/custom_localization.dart b/lib/layers/data/resources/custom_localization.dart similarity index 59% rename from lib/data/l10n/custom_localization.dart rename to lib/layers/data/resources/custom_localization.dart index 34fa0e1..9f89a79 100644 --- a/lib/data/l10n/custom_localization.dart +++ b/lib/layers/data/resources/custom_localization.dart @@ -1,5 +1,6 @@ import 'package:flutter/widgets.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; +import 'package:the_elder_scrolls_alchemy_client/app.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; class CustomLocalization { @@ -9,7 +10,7 @@ class CustomLocalization { required BuildContext context, }) { String? localizedEffectName = - DataSource.getLocalizedMap()[gameName]!['effects']?[englishEffectName]?[MyApp.getLocaleLanguageCode(context)]; + DataResource.getLocalizedMap()[gameName]!['effects']?[englishEffectName]?[TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context)]; return ((localizedEffectName != null) && (localizedEffectName != '')) ? localizedEffectName : englishEffectName; } @@ -19,8 +20,8 @@ class CustomLocalization { required String englishIngredientName, required BuildContext context, }) { - String? localizedIngredientName = DataSource.getLocalizedMap()[gameName]!['ingredients']?[englishIngredientName] - ?[MyApp.getLocaleLanguageCode(context)]; + String? localizedIngredientName = DataResource.getLocalizedMap()[gameName]!['ingredients']?[englishIngredientName] + ?[TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context)]; return ((localizedIngredientName != null) && (localizedIngredientName != '')) ? localizedIngredientName diff --git a/lib/data/data_source.dart b/lib/layers/data/resources/data_resource.dart similarity index 60% rename from lib/data/data_source.dart rename to lib/layers/data/resources/data_resource.dart index 369a2fb..79eb839 100644 --- a/lib/data/data_source.dart +++ b/lib/layers/data/resources/data_resource.dart @@ -1,13 +1,13 @@ -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/morrowind.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/oblivion.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/skyrim.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/morrowind.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/oblivion.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/skyrim.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/teso.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/morrowind.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/oblivion.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/skyrim.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/morrowind.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/oblivion.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/skyrim.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/teso.dart'; -class DataSource { +class DataResource { static Map getMap() { return _globalMap; } diff --git a/lib/data/effect_resource.dart b/lib/layers/data/resources/effect_resource.dart similarity index 73% rename from lib/data/effect_resource.dart rename to lib/layers/data/resources/effect_resource.dart index c5ad81f..77ada85 100644 --- a/lib/data/effect_resource.dart +++ b/lib/layers/data/resources/effect_resource.dart @@ -1,9 +1,9 @@ -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/search_indices.dart'; -import 'package:the_elder_scrolls_alchemy_client/exception/not_found.dart'; -import 'package:the_elder_scrolls_alchemy_client/exception/wrong_game.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/search_indices.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/exception/not_found.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/exception/wrong_game.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; class EffectResource { late String gameName; @@ -12,7 +12,7 @@ class EffectResource { Map currentMap = {}; EffectResource({this.gameName = 'skyrim'}) { - currentMap = DataSource.getMap()[gameName]['effects']; + currentMap = DataResource.getMap()[gameName]['effects']; } factory EffectResource.fromGameName(name) { @@ -52,14 +52,14 @@ class EffectResource { } static String getGameOfEffect(String effectName) { - for (int i = 0; i < DataSource.gameNames.length; i += 1) { - Map map = DataSource.getMap()[DataSource.gameNames[i]]['effects']; + for (int i = 0; i < DataResource.gameNames.length; i += 1) { + Map map = DataResource.getMap()[DataResource.gameNames[i]]['effects']; if (map.containsKey(effectName)) { // may return wrong game if effect has same name.... - return DataSource.gameNames[i]; // on burden, will return oblivion even if morrowind also has burden + return DataResource.gameNames[i]; // on burden, will return oblivion even if morrowind also has burden } } - throw Exception('Effect $effectName not found across all these games: ${DataSource.gameNames}'); + throw Exception('Effect $effectName not found across all these games: ${DataResource.gameNames}'); } List searchEffectsByName(String nameFromQuery, String languageCode) { diff --git a/lib/data/ingredient_resource.dart b/lib/layers/data/resources/ingredient_resource.dart similarity index 75% rename from lib/data/ingredient_resource.dart rename to lib/layers/data/resources/ingredient_resource.dart index bf387d4..dcda46e 100644 --- a/lib/data/ingredient_resource.dart +++ b/lib/layers/data/resources/ingredient_resource.dart @@ -1,16 +1,16 @@ -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/search_indices.dart'; -import 'package:the_elder_scrolls_alchemy_client/exception/not_found.dart'; -import 'package:the_elder_scrolls_alchemy_client/exception/wrong_game.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/search_indices.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/exception/not_found.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/exception/wrong_game.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; class IngredientResource { String gameName; Map currentMap = {}; static const int _searchQueryLengthThreshold = 2; IngredientResource({this.gameName = 'skyrim'}) { - currentMap = DataSource.getMap()[gameName]['ingredients']; + currentMap = DataResource.getMap()[gameName]['ingredients']; } factory IngredientResource.fromGameName(name) { @@ -85,12 +85,12 @@ class IngredientResource { } static String getGameOfIngredient(String ingredientName) { - for (int i = 0; i < DataSource.gameNames.length; i += 1) { - Map map = DataSource.getMap()[DataSource.gameNames[i]]['ingredients']; + for (int i = 0; i < DataResource.gameNames.length; i += 1) { + Map map = DataResource.getMap()[DataResource.gameNames[i]]['ingredients']; if (map.containsKey(ingredientName)) { - return DataSource.gameNames[i]; + return DataResource.gameNames[i]; } } - throw Exception('Ingredient $ingredientName not found across all these games: ${DataSource.gameNames}'); + throw Exception('Ingredient $ingredientName not found across all these games: ${DataResource.gameNames}'); } } diff --git a/lib/data/l10n/morrowind.dart b/lib/layers/data/storage/l10n/morrowind.dart similarity index 100% rename from lib/data/l10n/morrowind.dart rename to lib/layers/data/storage/l10n/morrowind.dart diff --git a/lib/data/l10n/oblivion.dart b/lib/layers/data/storage/l10n/oblivion.dart similarity index 100% rename from lib/data/l10n/oblivion.dart rename to lib/layers/data/storage/l10n/oblivion.dart diff --git a/lib/data/l10n/search_indices.dart b/lib/layers/data/storage/l10n/search_indices.dart similarity index 99% rename from lib/data/l10n/search_indices.dart rename to lib/layers/data/storage/l10n/search_indices.dart index d64e1dc..b2578c8 100644 --- a/lib/data/l10n/search_indices.dart +++ b/lib/layers/data/storage/l10n/search_indices.dart @@ -1,5 +1,5 @@ -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; /// only for russian right now.... /// maybe I will parse more translations data later and expand the index diff --git a/lib/data/l10n/skyrim.dart b/lib/layers/data/storage/l10n/skyrim.dart similarity index 100% rename from lib/data/l10n/skyrim.dart rename to lib/layers/data/storage/l10n/skyrim.dart diff --git a/lib/data/morrowind.dart b/lib/layers/data/storage/morrowind.dart similarity index 100% rename from lib/data/morrowind.dart rename to lib/layers/data/storage/morrowind.dart diff --git a/lib/data/oblivion.dart b/lib/layers/data/storage/oblivion.dart similarity index 100% rename from lib/data/oblivion.dart rename to lib/layers/data/storage/oblivion.dart diff --git a/lib/data/skyrim.dart b/lib/layers/data/storage/skyrim.dart similarity index 100% rename from lib/data/skyrim.dart rename to lib/layers/data/storage/skyrim.dart diff --git a/lib/data/teso.dart b/lib/layers/data/storage/teso.dart similarity index 100% rename from lib/data/teso.dart rename to lib/layers/data/storage/teso.dart diff --git a/lib/layers/presentation/widgets/app_widget.dart b/lib/layers/presentation/widgets/app_widget.dart new file mode 100644 index 0000000..1d317c4 --- /dev/null +++ b/lib/layers/presentation/widgets/app_widget.dart @@ -0,0 +1,85 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/router.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/state_management/state/search_field_toggle.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/error_screen.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +class AppWidget extends StatefulWidget { + AppWidget({Key? key, required this.languageCode, required this.gameName}) + : super(key: key); + + String languageCode; + String gameName; + + @override + _AppWidgetState createState() => _AppWidgetState(); +} + +class _AppWidgetState extends State { + MaterialColor getPrimarySwatch() { + const hash = 0xffa5d6a7; + const greenShade200 = Color(hash); + Map swatch = { + 50: greenShade200.withOpacity(.1), + 100: greenShade200.withOpacity(.2), + 200: greenShade200.withOpacity(.3), + 300: greenShade200.withOpacity(.4), + 400: greenShade200.withOpacity(.5), + 500: greenShade200.withOpacity(.6), + 600: greenShade200.withOpacity(.7), + 700: greenShade200.withOpacity(.8), + 800: greenShade200.withOpacity(.9), + 900: greenShade200.withOpacity(1), + }; + MaterialColor colorCustom = MaterialColor(hash, swatch); + return colorCustom; + } + + Widget tryChangeNotifier() { + final router = MaterialApp.router( + localizationsDelegates: const [ + AppLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + supportedLocales: Constant.supportedLanguageCodesToLanguageNamesMap.keys.map((e) => Locale(e)), + title: 'TES Alchemy', + routerConfig: AlchemyRouter.getRouter(gameName: widget.gameName), + locale: Locale(widget.languageCode), + theme: ThemeData( + primarySwatch: getPrimarySwatch(), + pageTransitionsTheme: const PageTransitionsTheme( + builders: { + TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(), + TargetPlatform.iOS: CupertinoPageTransitionsBuilder(), + TargetPlatform.linux: FadeUpwardsPageTransitionsBuilder(), + TargetPlatform.macOS: CupertinoPageTransitionsBuilder(), + TargetPlatform.windows: FadeUpwardsPageTransitionsBuilder(), + }, + ), + ), + ); + + final correctWidget = ChangeNotifierProvider( + create: (BuildContext context) { + return SearchFieldToggle(); + }, + child: router, + ); + + return correctWidget; + } + + @override + Widget build(BuildContext context) { + try { + return tryChangeNotifier(); + } catch (exception) { + return ErrorScreen(error: exception); + } + } +} diff --git a/lib/widgets/components/app_bar.dart b/lib/layers/presentation/widgets/components/app_bar.dart similarity index 84% rename from lib/widgets/components/app_bar.dart rename to lib/layers/presentation/widgets/components/app_bar.dart index f84ffcd..4f3a7e3 100644 --- a/lib/widgets/components/app_bar.dart +++ b/lib/layers/presentation/widgets/components/app_bar.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:provider/provider.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; import 'package:the_elder_scrolls_alchemy_client/extensions/capitalize.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/state/search_field_toggle.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/state_management/state/search_field_toggle.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class AlchemyAppBar extends StatelessWidget implements PreferredSizeWidget { diff --git a/lib/widgets/components/cards/effect/effect_big.dart b/lib/layers/presentation/widgets/components/cards/effect/effect_big.dart similarity index 68% rename from lib/widgets/components/cards/effect/effect_big.dart rename to lib/layers/presentation/widgets/components/cards/effect/effect_big.dart index 176adfd..ce05d50 100644 --- a/lib/widgets/components/cards/effect/effect_big.dart +++ b/lib/layers/presentation/widgets/components/cards/effect/effect_big.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_long.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/divider_text.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/lists/ingredients_by_effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_long.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/divider_text.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/lists/ingredients_by_effect.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class EffectCardBig extends StatelessWidget { diff --git a/lib/widgets/components/cards/effect/effect_long.dart b/lib/layers/presentation/widgets/components/cards/effect/effect_long.dart similarity index 87% rename from lib/widgets/components/cards/effect/effect_long.dart rename to lib/layers/presentation/widgets/components/cards/effect/effect_long.dart index f6d4a0f..6d62d00 100644 --- a/lib/widgets/components/cards/effect/effect_long.dart +++ b/lib/layers/presentation/widgets/components/cards/effect/effect_long.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/custom_localization.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/links/web_link.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/links/web_link.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class EffectCardLong extends StatelessWidget { diff --git a/lib/widgets/components/cards/effect/effect_micro.dart b/lib/layers/presentation/widgets/components/cards/effect/effect_micro.dart similarity index 85% rename from lib/widgets/components/cards/effect/effect_micro.dart rename to lib/layers/presentation/widgets/components/cards/effect/effect_micro.dart index de752de..6004cb4 100644 --- a/lib/widgets/components/cards/effect/effect_micro.dart +++ b/lib/layers/presentation/widgets/components/cards/effect/effect_micro.dart @@ -2,10 +2,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:go_router/go_router.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/custom_localization.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; class EffectCardMicro extends StatefulWidget { const EffectCardMicro({Key? key, required this.gameName, required this.effect, this.fontSize = 30.0}) diff --git a/lib/widgets/components/cards/effect/effect_small.dart b/lib/layers/presentation/widgets/components/cards/effect/effect_small.dart similarity index 84% rename from lib/widgets/components/cards/effect/effect_small.dart rename to lib/layers/presentation/widgets/components/cards/effect/effect_small.dart index a128f19..6130bee 100644 --- a/lib/widgets/components/cards/effect/effect_small.dart +++ b/lib/layers/presentation/widgets/components/cards/effect/effect_small.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/custom_localization.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class EffectCardSmall extends StatefulWidget { diff --git a/lib/widgets/components/cards/ingredient/ingredient_big.dart b/lib/layers/presentation/widgets/components/cards/ingredient/ingredient_big.dart similarity index 75% rename from lib/widgets/components/cards/ingredient/ingredient_big.dart rename to lib/layers/presentation/widgets/components/cards/ingredient/ingredient_big.dart index ae3a9f7..33ee3b3 100644 --- a/lib/widgets/components/cards/ingredient/ingredient_big.dart +++ b/lib/layers/presentation/widgets/components/cards/ingredient/ingredient_big.dart @@ -2,10 +2,10 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/ingredient/ingredient_long.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/lists/common_ingredients_by_column.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/divider_text.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/ingredient/ingredient_long.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/lists/common_ingredients_by_column.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/divider_text.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class IngredientCardBig extends StatefulWidget { diff --git a/lib/widgets/components/cards/ingredient/ingredient_long.dart b/lib/layers/presentation/widgets/components/cards/ingredient/ingredient_long.dart similarity index 86% rename from lib/widgets/components/cards/ingredient/ingredient_long.dart rename to lib/layers/presentation/widgets/components/cards/ingredient/ingredient_long.dart index 0fb1644..56eaa19 100644 --- a/lib/widgets/components/cards/ingredient/ingredient_long.dart +++ b/lib/layers/presentation/widgets/components/cards/ingredient/ingredient_long.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/custom_localization.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/divider_text.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/lists/effects_by_ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/links/web_link.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/divider_text.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/lists/effects_by_ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/links/web_link.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class IngredientCardLong extends StatefulWidget { diff --git a/lib/widgets/components/cards/ingredient/ingredient_micro.dart b/lib/layers/presentation/widgets/components/cards/ingredient/ingredient_micro.dart similarity index 84% rename from lib/widgets/components/cards/ingredient/ingredient_micro.dart rename to lib/layers/presentation/widgets/components/cards/ingredient/ingredient_micro.dart index 5947073..d20ed55 100644 --- a/lib/widgets/components/cards/ingredient/ingredient_micro.dart +++ b/lib/layers/presentation/widgets/components/cards/ingredient/ingredient_micro.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:go_router/go_router.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/custom_localization.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; class IngredientCardMicro extends StatefulWidget { const IngredientCardMicro({Key? key, required this.gameName, required this.ingredient}) : super(key: key); diff --git a/lib/widgets/components/cards/ingredient/ingredient_small.dart b/lib/layers/presentation/widgets/components/cards/ingredient/ingredient_small.dart similarity index 85% rename from lib/widgets/components/cards/ingredient/ingredient_small.dart rename to lib/layers/presentation/widgets/components/cards/ingredient/ingredient_small.dart index 05163b1..756a518 100644 --- a/lib/widgets/components/cards/ingredient/ingredient_small.dart +++ b/lib/layers/presentation/widgets/components/cards/ingredient/ingredient_small.dart @@ -2,10 +2,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:go_router/go_router.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/custom_localization.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; class IngredientCardSmall extends StatefulWidget { const IngredientCardSmall({Key? key, required this.gameName, required this.ingredient}) : super(key: key); diff --git a/lib/widgets/components/cards_grid.dart b/lib/layers/presentation/widgets/components/cards_grid.dart similarity index 100% rename from lib/widgets/components/cards_grid.dart rename to lib/layers/presentation/widgets/components/cards_grid.dart diff --git a/lib/widgets/components/divider_text.dart b/lib/layers/presentation/widgets/components/divider_text.dart similarity index 100% rename from lib/widgets/components/divider_text.dart rename to lib/layers/presentation/widgets/components/divider_text.dart diff --git a/lib/widgets/components/links/image_link.dart b/lib/layers/presentation/widgets/components/links/image_link.dart similarity index 100% rename from lib/widgets/components/links/image_link.dart rename to lib/layers/presentation/widgets/components/links/image_link.dart diff --git a/lib/widgets/components/links/web_link.dart b/lib/layers/presentation/widgets/components/links/web_link.dart similarity index 100% rename from lib/widgets/components/links/web_link.dart rename to lib/layers/presentation/widgets/components/links/web_link.dart diff --git a/lib/widgets/components/lists/common_ingredients_by_column.dart b/lib/layers/presentation/widgets/components/lists/common_ingredients_by_column.dart similarity index 83% rename from lib/widgets/components/lists/common_ingredients_by_column.dart rename to lib/layers/presentation/widgets/components/lists/common_ingredients_by_column.dart index 730b4ec..45e3d35 100644 --- a/lib/widgets/components/lists/common_ingredients_by_column.dart +++ b/lib/layers/presentation/widgets/components/lists/common_ingredients_by_column.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/custom_localization.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/custom_localization.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/effect_resource.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/ingredient_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/effect_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/ingredient_resource.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/ingredient/ingredient_micro.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/ingredient/ingredient_micro.dart'; class CommonIngredientsByColumn extends StatefulWidget { const CommonIngredientsByColumn({Key? key, required this.gameName, required this.ingredient}) : super(key: key); diff --git a/lib/widgets/components/lists/effects_by_ingredient.dart b/lib/layers/presentation/widgets/components/lists/effects_by_ingredient.dart similarity index 86% rename from lib/widgets/components/lists/effects_by_ingredient.dart rename to lib/layers/presentation/widgets/components/lists/effects_by_ingredient.dart index b5601b0..f155837 100644 --- a/lib/widgets/components/lists/effects_by_ingredient.dart +++ b/lib/layers/presentation/widgets/components/lists/effects_by_ingredient.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/effect_resource.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_micro.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/effect_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_micro.dart'; class EffectsByIngredient extends StatefulWidget { const EffectsByIngredient({Key? key, required this.gameName, required this.ingredient}) : super(key: key); diff --git a/lib/widgets/components/lists/ingredients_by_effect.dart b/lib/layers/presentation/widgets/components/lists/ingredients_by_effect.dart similarity index 87% rename from lib/widgets/components/lists/ingredients_by_effect.dart rename to lib/layers/presentation/widgets/components/lists/ingredients_by_effect.dart index 53b0f76..4a84923 100644 --- a/lib/widgets/components/lists/ingredients_by_effect.dart +++ b/lib/layers/presentation/widgets/components/lists/ingredients_by_effect.dart @@ -2,11 +2,11 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/ingredient_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/ingredient_resource.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/ingredient/ingredient_micro.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/ingredient/ingredient_micro.dart'; class IngredientsByEffect extends StatefulWidget { const IngredientsByEffect({Key? key, required this.gameName, required this.effect}) : super(key: key); diff --git a/lib/widgets/components/search_field.dart b/lib/layers/presentation/widgets/components/search_field.dart similarity index 100% rename from lib/widgets/components/search_field.dart rename to lib/layers/presentation/widgets/components/search_field.dart diff --git a/lib/widgets/navigation/bottom_panel_navigation.dart b/lib/layers/presentation/widgets/navigation/bottom_panel_navigation.dart similarity index 93% rename from lib/widgets/navigation/bottom_panel_navigation.dart rename to lib/layers/presentation/widgets/navigation/bottom_panel_navigation.dart index c42c6b4..3268e22 100644 --- a/lib/widgets/navigation/bottom_panel_navigation.dart +++ b/lib/layers/presentation/widgets/navigation/bottom_panel_navigation.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:the_elder_scrolls_alchemy_client/router.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/navigation/navigation.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/navigation/navigation.dart'; class BottomPanelNavigation extends StatefulWidget { const BottomPanelNavigation({Key? key, required this.gameName, required this.notifyParent}) : super(key: key); diff --git a/lib/widgets/navigation/left_panel_navigation.dart b/lib/layers/presentation/widgets/navigation/left_panel_navigation.dart similarity index 93% rename from lib/widgets/navigation/left_panel_navigation.dart rename to lib/layers/presentation/widgets/navigation/left_panel_navigation.dart index 07083b3..0005659 100644 --- a/lib/widgets/navigation/left_panel_navigation.dart +++ b/lib/layers/presentation/widgets/navigation/left_panel_navigation.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:the_elder_scrolls_alchemy_client/router.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/navigation/navigation.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/navigation/navigation.dart'; class LeftPanelNavigation extends StatefulWidget { const LeftPanelNavigation({Key? key, required this.gameName, required this.notifyParent}) : super(key: key); diff --git a/lib/widgets/navigation/navigation.dart b/lib/layers/presentation/widgets/navigation/navigation.dart similarity index 100% rename from lib/widgets/navigation/navigation.dart rename to lib/layers/presentation/widgets/navigation/navigation.dart diff --git a/lib/widgets/pages/effects/effect.dart b/lib/layers/presentation/widgets/pages/effects/effect.dart similarity index 69% rename from lib/widgets/pages/effects/effect.dart rename to lib/layers/presentation/widgets/pages/effects/effect.dart index 476bc34..e011548 100644 --- a/lib/widgets/pages/effects/effect.dart +++ b/lib/layers/presentation/widgets/pages/effects/effect.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_big.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_big.dart'; class EffectPage extends StatefulWidget { const EffectPage({Key? key, required this.gameName, required this.effect}) : super(key: key); diff --git a/lib/widgets/pages/effects/effects.dart b/lib/layers/presentation/widgets/pages/effects/effects.dart similarity index 63% rename from lib/widgets/pages/effects/effects.dart rename to lib/layers/presentation/widgets/pages/effects/effects.dart index f152aef..cb99de6 100644 --- a/lib/widgets/pages/effects/effects.dart +++ b/lib/layers/presentation/widgets/pages/effects/effects.dart @@ -1,16 +1,17 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/effect_resource.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/l10n/search_indices.dart'; +import 'package:the_elder_scrolls_alchemy_client/app.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/effect_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/storage/l10n/search_indices.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/state/search_field_toggle.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_small.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards_grid.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/search_field.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/state_management/state/search_field_toggle.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_small.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards_grid.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/search_field.dart'; class EffectsPage extends StatefulWidget { const EffectsPage({Key? key, required this.gameName}) : super(key: key); @@ -59,7 +60,7 @@ class _EffectsPageState extends State { final searchFieldToggle = Provider.of(context); final bool isSearchVisible = searchFieldToggle.isSearchFieldShown; - final String languageCode = MyApp.getLocaleLanguageCode(context); + final String languageCode = TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context); final List effects = EffectResource(gameName: widget.gameName).searchEffectsByName(_searchQuery, languageCode); diff --git a/lib/widgets/pages/home/home.dart b/lib/layers/presentation/widgets/pages/home/home.dart similarity index 86% rename from lib/widgets/pages/home/home.dart rename to lib/layers/presentation/widgets/pages/home/home.dart index e9f1600..1fc9c85 100644 --- a/lib/widgets/pages/home/home.dart +++ b/lib/layers/presentation/widgets/pages/home/home.dart @@ -1,11 +1,12 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; +import 'package:the_elder_scrolls_alchemy_client/app.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/links/image_link.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/links/web_link.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/links/image_link.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/links/web_link.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class HomePage extends StatefulWidget { @@ -34,7 +35,7 @@ List> getLocaleButtonsDropdown(context) { List> getGameButtonsDropdown(context) { List> popupMenuItems = []; - for (var gameName in DataSource.gameNames) { + for (var gameName in DataResource.gameNames) { popupMenuItems.add( DropdownMenuItem( value: gameName, @@ -64,7 +65,7 @@ class _HomePageState extends State with RestorationMixin { } Widget getLanguagePicker(context) { - final currentLanguageCode = MyApp.getLocaleLanguageCode(context); + final currentLanguageCode = TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context); final languagePicker = DropdownButtonFormField( decoration: InputDecoration( @@ -76,7 +77,7 @@ class _HomePageState extends State with RestorationMixin { items: getLocaleButtonsDropdown(context), onChanged: (String? value) { if (value is String) { - MyApp.setLocaleLanguageCode(context, value); + TheElderScrollsAlchemyClientApp.setLocaleLanguageCode(context, value); } }, ); @@ -95,7 +96,7 @@ class _HomePageState extends State with RestorationMixin { items: getGameButtonsDropdown(context), onChanged: (String? gameName) { if (gameName is String) { - MyApp.setGameName(context, gameName); + TheElderScrollsAlchemyClientApp.setGameName(context, gameName); } }, ); diff --git a/lib/widgets/pages/ingredients/ingredient.dart b/lib/layers/presentation/widgets/pages/ingredients/ingredient.dart similarity index 70% rename from lib/widgets/pages/ingredients/ingredient.dart rename to lib/layers/presentation/widgets/pages/ingredients/ingredient.dart index d7953a2..5fba01c 100644 --- a/lib/widgets/pages/ingredients/ingredient.dart +++ b/lib/layers/presentation/widgets/pages/ingredients/ingredient.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/ingredient/ingredient_big.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/ingredient/ingredient_big.dart'; class IngredientPage extends StatefulWidget { const IngredientPage({Key? key, required this.gameName, required this.ingredient}) : super(key: key); diff --git a/lib/widgets/pages/ingredients/ingredients.dart b/lib/layers/presentation/widgets/pages/ingredients/ingredients.dart similarity index 72% rename from lib/widgets/pages/ingredients/ingredients.dart rename to lib/layers/presentation/widgets/pages/ingredients/ingredients.dart index d7b85ac..232178f 100644 --- a/lib/widgets/pages/ingredients/ingredients.dart +++ b/lib/layers/presentation/widgets/pages/ingredients/ingredients.dart @@ -1,13 +1,14 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/ingredient_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/app.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/ingredient_resource.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/state/search_field_toggle.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/ingredient/ingredient_small.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards_grid.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/search_field.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/state_management/state/search_field_toggle.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/ingredient/ingredient_small.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards_grid.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/search_field.dart'; class IngredientsPage extends StatefulWidget { IngredientsPage({Key? key, required this.gameName}) : super(key: key); @@ -62,7 +63,7 @@ class _IngredientsPageState extends State { final isSearchVisible = searchFieldToggle.isSearchFieldShown; final gameName = widget.gameName; - final String languageCode = MyApp.getLocaleLanguageCode(context); + final String languageCode = TheElderScrollsAlchemyClientApp.getLocaleLanguageCode(context); final List ingredients = IngredientResource(gameName: gameName).searchIngredientsByName(_searchQuery, languageCode); diff --git a/lib/widgets/pages/potions/potions.dart b/lib/layers/presentation/widgets/pages/potions/potions.dart similarity index 100% rename from lib/widgets/pages/potions/potions.dart rename to lib/layers/presentation/widgets/pages/potions/potions.dart diff --git a/lib/widgets/pages/search/search.dart b/lib/layers/presentation/widgets/pages/search/search.dart similarity index 73% rename from lib/widgets/pages/search/search.dart rename to lib/layers/presentation/widgets/pages/search/search.dart index 95a9122..cf35b35 100644 --- a/lib/widgets/pages/search/search.dart +++ b/lib/layers/presentation/widgets/pages/search/search.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_small.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/ingredient/ingredient_small.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards_grid.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/search_field.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_small.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/ingredient/ingredient_small.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards_grid.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/search_field.dart'; class SearchPage extends StatefulWidget { const SearchPage({Key? key}) : super(key: key); diff --git a/lib/widgets/screens/custom_screen.dart b/lib/layers/presentation/widgets/screens/custom_screen.dart similarity index 79% rename from lib/widgets/screens/custom_screen.dart rename to lib/layers/presentation/widgets/screens/custom_screen.dart index 3771f5f..96198af 100644 --- a/lib/widgets/screens/custom_screen.dart +++ b/lib/layers/presentation/widgets/screens/custom_screen.dart @@ -1,10 +1,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:the_elder_scrolls_alchemy_client/state/search_field_toggle.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/app_bar.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/navigation/bottom_panel_navigation.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/navigation/left_panel_navigation.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/state_management/state/search_field_toggle.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/app_bar.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/navigation/bottom_panel_navigation.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/navigation/left_panel_navigation.dart'; class CustomScreen extends StatefulWidget { const CustomScreen({Key? key, required this.gameName, required this.pageWidget}) : super(key: key); diff --git a/lib/layers/presentation/widgets/screens/effect_screen.dart b/lib/layers/presentation/widgets/screens/effect_screen.dart new file mode 100644 index 0000000..41b8a5b --- /dev/null +++ b/lib/layers/presentation/widgets/screens/effect_screen.dart @@ -0,0 +1,21 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/effect_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/pages/effects/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/custom_screen.dart'; + +class EffectScreen extends StatelessWidget { + const EffectScreen({Key? key, required this.gameName, required this.effectName}) : super(key: key); + final String effectName; + final String gameName; + + @override + Widget build(BuildContext context) { + final effect = Effect.fromMap(DataResource.getMap()[this.gameName]['effects'][effectName]); + + return CustomScreen(gameName: this.gameName, pageWidget: EffectPage(gameName: this.gameName, effect: effect)); + } +} diff --git a/lib/widgets/screens/effects_screen.dart b/lib/layers/presentation/widgets/screens/effects_screen.dart similarity index 64% rename from lib/widgets/screens/effects_screen.dart rename to lib/layers/presentation/widgets/screens/effects_screen.dart index a3b30c3..3cf6d21 100644 --- a/lib/widgets/screens/effects_screen.dart +++ b/lib/layers/presentation/widgets/screens/effects_screen.dart @@ -1,7 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/custom_screen.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/pages/effects/effects.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/custom_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/pages/effects/effects.dart'; class EffectsScreen extends StatelessWidget { const EffectsScreen({Key? key, required this.gameName}) : super(key: key); diff --git a/lib/widgets/screens/error_screen.dart b/lib/layers/presentation/widgets/screens/error_screen.dart similarity index 95% rename from lib/widgets/screens/error_screen.dart rename to lib/layers/presentation/widgets/screens/error_screen.dart index a363de8..28bffd1 100644 --- a/lib/widgets/screens/error_screen.dart +++ b/lib/layers/presentation/widgets/screens/error_screen.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; diff --git a/lib/widgets/screens/home_screen.dart b/lib/layers/presentation/widgets/screens/home_screen.dart similarity index 62% rename from lib/widgets/screens/home_screen.dart rename to lib/layers/presentation/widgets/screens/home_screen.dart index 9656797..e6e9c46 100644 --- a/lib/widgets/screens/home_screen.dart +++ b/lib/layers/presentation/widgets/screens/home_screen.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/custom_screen.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/pages/home/home.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/custom_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/pages/home/home.dart'; class HomeScreen extends StatelessWidget { const HomeScreen({Key? key, required this.gameName}) : super(key: key); diff --git a/lib/widgets/screens/ingredient_screen.dart b/lib/layers/presentation/widgets/screens/ingredient_screen.dart similarity index 53% rename from lib/widgets/screens/ingredient_screen.dart rename to lib/layers/presentation/widgets/screens/ingredient_screen.dart index 670ee41..a081c79 100644 --- a/lib/widgets/screens/ingredient_screen.dart +++ b/lib/layers/presentation/widgets/screens/ingredient_screen.dart @@ -1,9 +1,9 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/pages/ingredients/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/custom_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/pages/ingredients/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/custom_screen.dart'; class IngredientScreen extends StatelessWidget { const IngredientScreen({Key? key, required this.gameName, required this.ingredientName}) : super(key: key); @@ -13,7 +13,7 @@ class IngredientScreen extends StatelessWidget { @override Widget build(BuildContext context) { - final currentMap = DataSource.getMap()[this.gameName]['ingredients']; + final currentMap = DataResource.getMap()[this.gameName]['ingredients']; final ingredient = Ingredient.fromMap(currentMap[ingredientName]); return CustomScreen( diff --git a/lib/widgets/screens/ingredients_screen.dart b/lib/layers/presentation/widgets/screens/ingredients_screen.dart similarity index 64% rename from lib/widgets/screens/ingredients_screen.dart rename to lib/layers/presentation/widgets/screens/ingredients_screen.dart index fe14c03..b578eb4 100644 --- a/lib/widgets/screens/ingredients_screen.dart +++ b/lib/layers/presentation/widgets/screens/ingredients_screen.dart @@ -1,7 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/pages/ingredients/ingredients.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/custom_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/pages/ingredients/ingredients.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/custom_screen.dart'; class IngredientsScreen extends StatelessWidget { const IngredientsScreen({Key? key, required this.gameName}) : super(key: key); diff --git a/lib/widgets/screens/search_screen.dart b/lib/layers/presentation/widgets/screens/search_screen.dart similarity index 61% rename from lib/widgets/screens/search_screen.dart rename to lib/layers/presentation/widgets/screens/search_screen.dart index 7ba8722..0e79e63 100644 --- a/lib/widgets/screens/search_screen.dart +++ b/lib/layers/presentation/widgets/screens/search_screen.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/pages/search/search.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/custom_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/pages/search/search.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/custom_screen.dart'; class SearchScreen extends StatelessWidget { const SearchScreen({Key? key}) : super(key: key); diff --git a/lib/state/search_field_toggle.dart b/lib/layers/state_management/state/search_field_toggle.dart similarity index 100% rename from lib/state/search_field_toggle.dart rename to lib/layers/state_management/state/search_field_toggle.dart diff --git a/lib/main.dart b/lib/main.dart index 5449423..8f8c99c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,169 +1,15 @@ import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/router.dart'; -import 'package:the_elder_scrolls_alchemy_client/state/search_field_toggle.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/error_screen.dart'; -import 'package:flutter_localizations/flutter_localizations.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:the_elder_scrolls_alchemy_client/app.dart'; +import 'package:the_elder_scrolls_alchemy_client/di_container.dart'; +import 'package:flutter_simple_dependency_injection/injector.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - String languageCodeFromPreferences = await MyApp.getSafeLanguageCode(); - String gameNameFromPreferences = await MyApp.getSavedGameName(); + final dependencyInjectionContainer = DependencyInjectionContainer().initialise(Injector()); + final app = dependencyInjectionContainer.get(); runApp( - MyApp(languageCode: languageCodeFromPreferences, gameName: gameNameFromPreferences), + app, ); } - -class MyApp extends StatefulWidget { - MyApp({Key? key, this.languageCode = Constant.fallbackLanguage, this.gameName = Constant.fallbackGameName}) - : super(key: key); - - String languageCode; - String gameName; - - static Future getSavedGameName() async { - String? gameNameFromPreferences = await getGameNameFromPreferences(); - if (gameNameFromPreferences == null) { - return Constant.fallbackGameName; - } - return gameNameFromPreferences; - } - - static String getLocaleLanguageCode(BuildContext context) { - return Localizations.localeOf(context).languageCode; - } - - static Future getSafeLanguageCode() async { - String? languageCodeFromPreferences = await getLanguageCodeFromPreferences(); - if (languageCodeFromPreferences == null) { - return Constant.fallbackLanguage; - } - return languageCodeFromPreferences; - } - - static Future getLanguageCodeFromPreferences() async { - final prefs = await SharedPreferences.getInstance(); - final String? languageCode = prefs.getString('languageCode'); - - return languageCode; - } - - static Future getGameNameFromPreferences() async { - final prefs = await SharedPreferences.getInstance(); - final String? gameName = prefs.getString('gameName'); - - return gameName; - } - - static void setLocaleLanguageCode(BuildContext context, String languageCode) async { - _MyAppState state = context.findAncestorStateOfType<_MyAppState>()!; - state.setLocaleLanguageCode(languageCode); - final prefs = await SharedPreferences.getInstance(); - await prefs.setString('languageCode', languageCode); - } - - static void setGameName(BuildContext context, String gameName) async { - _MyAppState state = context.findAncestorStateOfType<_MyAppState>()!; - state.setGameName(gameName); - final prefs = await SharedPreferences.getInstance(); - await prefs.setString('gameName', gameName); - } - - @override - _MyAppState createState() => _MyAppState(); -} - -class _MyAppState extends State { - setLocaleLanguageCode(String languageCode) { - setState(() { - widget.languageCode = languageCode; - }); - } - - setGameName(String gameName) { - setState(() { - widget.gameName = gameName; - }); - } - - MaterialColor getPrimarySwatch() { - const hash = 0xffa5d6a7; - const greenShade200 = Color(hash); - Map swatch = { - 50: greenShade200.withOpacity(.1), - 100: greenShade200.withOpacity(.2), - 200: greenShade200.withOpacity(.3), - 300: greenShade200.withOpacity(.4), - 400: greenShade200.withOpacity(.5), - 500: greenShade200.withOpacity(.6), - 600: greenShade200.withOpacity(.7), - 700: greenShade200.withOpacity(.8), - 800: greenShade200.withOpacity(.9), - 900: greenShade200.withOpacity(1), - }; - MaterialColor colorCustom = MaterialColor(hash, swatch); - return colorCustom; - } - - @override - Widget build(BuildContext context) { - try { - final router = MaterialApp.router( - localizationsDelegates: const [ - AppLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - ], - supportedLocales: Constant.supportedLanguageCodesToLanguageNamesMap.keys.map((e) => Locale(e)), - // supportedLocales: const [ - // Locale(Constant.lcEnglish, ''), - // Locale(Constant.lcRussian, ''), - // Locale(Constant.lcSpanish, ''), - // Locale(Constant.lcFrench, ''), - // Locale(Constant.lcGerman, ''), - // Locale(Constant.lcItalian, ''), - // Locale(Constant.lcJapanese, ''), - // Locale(Constant.lcPolish, ''), - // Locale.fromSubtags(languageCode: Constant.lcChinese), // generic Chinese - // Locale.fromSubtags(languageCode: Constant.lcChinese, scriptCode: 'Hans'), // generic simplified Chinese - // Locale.fromSubtags(languageCode: Constant.lcChinese, scriptCode: 'Hant'), // generic traditional Chinese - // Locale.fromSubtags(languageCode: Constant.lcChinese, scriptCode: 'Hans', countryCode: 'CN'), - // Locale.fromSubtags(languageCode: Constant.lcChinese, scriptCode: 'Hant', countryCode: 'TW'), - // Locale.fromSubtags(languageCode: Constant.lcChinese, scriptCode: 'Hant', countryCode: 'HK'), - // ], - title: 'TES Alchemy', - routerConfig: AlchemyRouter.getRouter(gameName: widget.gameName), - locale: Locale(widget.languageCode), - theme: ThemeData( - primarySwatch: getPrimarySwatch(), - pageTransitionsTheme: const PageTransitionsTheme( - builders: { - TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(), - TargetPlatform.iOS: CupertinoPageTransitionsBuilder(), - TargetPlatform.linux: FadeUpwardsPageTransitionsBuilder(), - TargetPlatform.macOS: CupertinoPageTransitionsBuilder(), - TargetPlatform.windows: FadeUpwardsPageTransitionsBuilder(), - }, - ), - ), - ); - - final correctWidget = ChangeNotifierProvider( - create: (BuildContext context) { - return SearchFieldToggle(); - }, - child: router, - ); - - return correctWidget; - } catch (exception) { - return ErrorScreen(error: exception); - } - } -} diff --git a/lib/router.dart b/lib/router.dart index 505de46..5163f07 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -1,28 +1,28 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/navigation/navigation.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/effect_screen.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/effects_screen.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/error_screen.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/home_screen.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/ingredient_screen.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/ingredients_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/navigation/navigation.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/effect_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/effects_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/error_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/home_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/ingredient_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/ingredients_screen.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class AlchemyRouter { static bool isGameNameValid({required String gameName}) { - return DataSource.gameNames.contains(gameName); + return DataResource.gameNames.contains(gameName); } static bool isEffectValid({required String gameName, required String effectName}) { - return isGameNameValid(gameName: gameName) && DataSource.getMap()[gameName]['effects'].containsKey(effectName); + return isGameNameValid(gameName: gameName) && DataResource.getMap()[gameName]['effects'].containsKey(effectName); } static bool isIngredientValid({required String gameName, required String ingredientName}) { return isGameNameValid(gameName: gameName) && - DataSource.getMap()[gameName]['ingredients'].containsKey(ingredientName); + DataResource.getMap()[gameName]['ingredients'].containsKey(ingredientName); } static bool isLocaleValid({ diff --git a/lib/widgets/screens/effect_screen.dart b/lib/widgets/screens/effect_screen.dart deleted file mode 100644 index 206e5cb..0000000 --- a/lib/widgets/screens/effect_screen.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; - -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/effect_resource.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/pages/effects/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/custom_screen.dart'; - -class EffectScreen extends StatelessWidget { - const EffectScreen({Key? key, required this.gameName, required this.effectName}) : super(key: key); - final String effectName; - final String gameName; - - @override - Widget build(BuildContext context) { - final effect = Effect.fromMap(DataSource.getMap()[this.gameName]['effects'][effectName]); - - return CustomScreen(gameName: this.gameName, pageWidget: EffectPage(gameName: this.gameName, effect: effect)); - } -} diff --git a/pubspec.lock b/pubspec.lock index d42afd9..085e2d1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -114,6 +114,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_simple_dependency_injection: + dependency: "direct main" + description: + name: flutter_simple_dependency_injection + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" flutter_svg: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index dec02ff..a816656 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,6 +44,7 @@ dependencies: intl: ^0.17.0 shared_preferences: flutter_svg: ^1.1.6 + flutter_simple_dependency_injection: ^2.0.0 dev_dependencies: flutter_test: sdk: flutter diff --git a/test/data/data_source_test.dart b/test/data/data_source_test.dart index 91edae7..681f569 100644 --- a/test/data/data_source_test.dart +++ b/test/data/data_source_test.dart @@ -1,11 +1,11 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; void main() { group("Test data source", () { test("Test skyrim data", () { - Map map = DataSource.getMap()[Constant.gameNameSkyrim]; + Map map = DataResource.getMap()[Constant.gameNameSkyrim]; expect(map.containsKey('effects'), true); expect(map['effects'].length, 55); @@ -15,7 +15,7 @@ void main() { }); test("Test oblivion data", () { - Map map = DataSource.getMap()[Constant.gameNameOblivion]; + Map map = DataResource.getMap()[Constant.gameNameOblivion]; expect(map.containsKey('effects'), true); expect(map['effects'].length, 68); @@ -25,7 +25,7 @@ void main() { }); test("Test morrowind data", () { - Map map = DataSource.getMap()[Constant.gameNameMorrowind]; + Map map = DataResource.getMap()[Constant.gameNameMorrowind]; expect(map.containsKey('effects'), true); expect(map['effects'].length, 67); @@ -35,7 +35,7 @@ void main() { }); test("Test game names", () { - expect(DataSource.gameNames.length, 4); + expect(DataResource.gameNames.length, 4); }); }); } diff --git a/test/widgets/components/cards/effect_big_test.dart b/test/widgets/components/cards/effect_big_test.dart index 686ba19..4e39ff8 100644 --- a/test/widgets/components/cards/effect_big_test.dart +++ b/test/widgets/components/cards/effect_big_test.dart @@ -1,16 +1,16 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_big.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_big.dart'; Widget createWidget() => MaterialApp( locale: Locale(Constant.fallbackLanguage), home: EffectCardBig( gameName: Constant.gameNameSkyrim, - effect: Effect.fromMap(DataSource.getMap()[Constant.gameNameSkyrim]['effects']['Cure Disease']), + effect: Effect.fromMap(DataResource.getMap()[Constant.gameNameSkyrim]['effects']['Cure Disease']), ), ); diff --git a/test/widgets/components/cards/effect_small_test.dart b/test/widgets/components/cards/effect_small_test.dart index 7847bc0..e72b1d9 100644 --- a/test/widgets/components/cards/effect_small_test.dart +++ b/test/widgets/components/cards/effect_small_test.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/effect/effect_small.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/effect/effect_small.dart'; import 'package:shared_preferences/shared_preferences.dart'; const String _languageCode = Constant.fallbackLanguage; @@ -13,7 +13,7 @@ Widget createWidget({String languageCode = Constant.fallbackLanguage}) => Contai locale: Locale(languageCode), home: EffectCardSmall( gameName: Constant.gameNameSkyrim, - effect: Effect.fromMap(DataSource.getMap()[Constant.gameNameSkyrim]['effects']['Cure Disease']), + effect: Effect.fromMap(DataResource.getMap()[Constant.gameNameSkyrim]['effects']['Cure Disease']), ), ), ); diff --git a/test/widgets/components/cards/ingredient_big_test.dart b/test/widgets/components/cards/ingredient_big_test.dart index f133650..5237b17 100644 --- a/test/widgets/components/cards/ingredient_big_test.dart +++ b/test/widgets/components/cards/ingredient_big_test.dart @@ -2,14 +2,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/constant.dart'; -import 'package:the_elder_scrolls_alchemy_client/data/data_source.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/constant.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/data/resources/data_resource.dart'; import 'package:the_elder_scrolls_alchemy_client/main.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/effect.dart'; -import 'package:the_elder_scrolls_alchemy_client/models/ingredient.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/components/cards/ingredient/ingredient_big.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/effect_screen.dart'; -import 'package:the_elder_scrolls_alchemy_client/widgets/screens/effects_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/effect.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/models/ingredient.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/components/cards/ingredient/ingredient_big.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/effect_screen.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/presentation/widgets/screens/effects_screen.dart'; const String _languageCode = Constant.fallbackLanguage; @@ -19,7 +19,7 @@ Widget createWidget({String languageCode = Constant.fallbackLanguage}) => Contai home: IngredientCardBig( gameName: Constant.gameNameSkyrim, ingredient: - Ingredient.fromMap(DataSource.getMap()[Constant.gameNameSkyrim]['ingredients']['Abecean Longfin']), + Ingredient.fromMap(DataResource.getMap()[Constant.gameNameSkyrim]['ingredients']['Abecean Longfin']), // ingredient: Ingredient.fromMap(DataSource.getMap()[DataSource.gameNameMorrowind]['ingredients']['Bread']), ), ), From cf3d9897f7a1b2bc2694cfbb761f33ad945e0f33 Mon Sep 17 00:00:00 2001 From: Gennady Terekhov Date: Tue, 5 Sep 2023 22:22:31 +0300 Subject: [PATCH 2/2] d --- lib/di_container.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/di_container.dart b/lib/di_container.dart index 52edefc..3272753 100644 --- a/lib/di_container.dart +++ b/lib/di_container.dart @@ -1,8 +1,18 @@ import 'package:flutter_simple_dependency_injection/injector.dart'; +import 'package:the_elder_scrolls_alchemy_client/app.dart'; +import 'package:the_elder_scrolls_alchemy_client/layers/business_logic/services/settings_manager.dart'; class DependencyInjectionContainer { - Injector initialise(Injector injector) { + injector.map((injector) => SettingsManager(), isSingleton: true); + + injector.map( + (injector) => TheElderScrollsAlchemyClientApp( + settingsManager: injector.get(), + ), + isSingleton: true, + ); + // injector.map((i) => Logger(), isSingleton: true); // injector.map((i) => "https://api.com/", key: "apiUrl"); // injector.map( @@ -17,4 +27,4 @@ class DependencyInjectionContainer { return injector; } -} \ No newline at end of file +}