From 35889fdb38c71ee404898d1dac82bae98372e9d5 Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 03:59:06 -0300 Subject: [PATCH 01/13] feat(shared): create lib --- apps/flutter/suflex/pubspec.lock | 7 ++ apps/flutter/suflex/pubspec.yaml | 2 + libs/flutter/shared/.gitignore | 30 +++++ libs/flutter/shared/.metadata | 10 ++ libs/flutter/shared/CHANGELOG.md | 3 + libs/flutter/shared/LICENSE | 1 + libs/flutter/shared/README.md | 39 ++++++ libs/flutter/shared/analysis_options.yaml | 4 + libs/flutter/shared/lib/flutter_shared.dart | 7 ++ libs/flutter/shared/project.json | 114 ++++++++++++++++++ libs/flutter/shared/pubspec.yaml | 54 +++++++++ .../shared/test/flutter_shared_test.dart | 12 ++ 12 files changed, 283 insertions(+) create mode 100644 libs/flutter/shared/.gitignore create mode 100644 libs/flutter/shared/.metadata create mode 100644 libs/flutter/shared/CHANGELOG.md create mode 100644 libs/flutter/shared/LICENSE create mode 100644 libs/flutter/shared/README.md create mode 100644 libs/flutter/shared/analysis_options.yaml create mode 100644 libs/flutter/shared/lib/flutter_shared.dart create mode 100644 libs/flutter/shared/project.json create mode 100644 libs/flutter/shared/pubspec.yaml create mode 100644 libs/flutter/shared/test/flutter_shared_test.dart diff --git a/apps/flutter/suflex/pubspec.lock b/apps/flutter/suflex/pubspec.lock index acb7bb9..732329d 100644 --- a/apps/flutter/suflex/pubspec.lock +++ b/apps/flutter/suflex/pubspec.lock @@ -132,6 +132,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.2" + flutter_shared: + dependency: "direct main" + description: + path: "../../../libs/flutter/shared" + relative: true + source: path + version: "0.0.1" flutter_svg: dependency: transitive description: diff --git a/apps/flutter/suflex/pubspec.yaml b/apps/flutter/suflex/pubspec.yaml index 847af46..9adc605 100644 --- a/apps/flutter/suflex/pubspec.yaml +++ b/apps/flutter/suflex/pubspec.yaml @@ -40,6 +40,8 @@ dependencies: path: ../../../libs/flutter/episodes flutter_api: path: ../../../libs/flutter/api + flutter_shared: + path: ../../../libs/flutter/shared # The following adds the Cupertino Icons font to your application. diff --git a/libs/flutter/shared/.gitignore b/libs/flutter/shared/.gitignore new file mode 100644 index 0000000..96486fd --- /dev/null +++ b/libs/flutter/shared/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/libs/flutter/shared/.metadata b/libs/flutter/shared/.metadata new file mode 100644 index 0000000..e7011f6 --- /dev/null +++ b/libs/flutter/shared/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: f1875d570e39de09040c8f79aa13cc56baab8db1 + channel: stable + +project_type: package diff --git a/libs/flutter/shared/CHANGELOG.md b/libs/flutter/shared/CHANGELOG.md new file mode 100644 index 0000000..41cc7d8 --- /dev/null +++ b/libs/flutter/shared/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* TODO: Describe initial release. diff --git a/libs/flutter/shared/LICENSE b/libs/flutter/shared/LICENSE new file mode 100644 index 0000000..ba75c69 --- /dev/null +++ b/libs/flutter/shared/LICENSE @@ -0,0 +1 @@ +TODO: Add your license here. diff --git a/libs/flutter/shared/README.md b/libs/flutter/shared/README.md new file mode 100644 index 0000000..8b55e73 --- /dev/null +++ b/libs/flutter/shared/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/libs/flutter/shared/analysis_options.yaml b/libs/flutter/shared/analysis_options.yaml new file mode 100644 index 0000000..a5744c1 --- /dev/null +++ b/libs/flutter/shared/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/libs/flutter/shared/lib/flutter_shared.dart b/libs/flutter/shared/lib/flutter_shared.dart new file mode 100644 index 0000000..74a8e3f --- /dev/null +++ b/libs/flutter/shared/lib/flutter_shared.dart @@ -0,0 +1,7 @@ +library flutter_shared; + +/// A Calculator. +class Calculator { + /// Returns [value] plus 1. + int addOne(int value) => value + 1; +} diff --git a/libs/flutter/shared/project.json b/libs/flutter/shared/project.json new file mode 100644 index 0000000..b30b606 --- /dev/null +++ b/libs/flutter/shared/project.json @@ -0,0 +1,114 @@ +{ + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "name": "flutter-shared", + "sourceRoot": "libs/flutter/shared/src", + "projectType": "library", + "targets": { + "analyze": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter analyze", + "cwd": "libs/flutter/shared" + } + }, + "clean": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter clean", + "cwd": "libs/flutter/shared" + } + }, + "format": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter format libs/flutter/shared/*", + "cwd": "libs/flutter/shared" + } + }, + "test": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter test", + "cwd": "libs/flutter/shared" + } + }, + "doctor": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter doctor", + "cwd": "libs/flutter/shared" + } + }, + "build-aar": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter build aar", + "cwd": "libs/flutter/shared" + }, + "outputs": [ + "libs/flutter/shared/build" + ] + }, + "build-apk": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter build apk", + "cwd": "libs/flutter/shared" + }, + "outputs": [ + "libs/flutter/shared/build" + ] + }, + "build-appbundle": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter build appbundle", + "cwd": "libs/flutter/shared" + }, + "outputs": [ + "libs/flutter/shared/build" + ] + }, + "build-bundle": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter build bundle", + "cwd": "libs/flutter/shared" + }, + "outputs": [ + "libs/flutter/shared/build" + ] + }, + "build-ios": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter build ios", + "cwd": "libs/flutter/shared" + }, + "outputs": [ + "libs/flutter/shared/build" + ] + }, + "build-ios-framework": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter build ios-framework", + "cwd": "libs/flutter/shared" + }, + "outputs": [ + "libs/flutter/shared/build" + ] + }, + "build-ipa": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "command": "flutter build ipa", + "cwd": "libs/flutter/shared" + }, + "outputs": [ + "libs/flutter/shared/build" + ] + } + }, + "tags": [] +} diff --git a/libs/flutter/shared/pubspec.yaml b/libs/flutter/shared/pubspec.yaml new file mode 100644 index 0000000..13cabc3 --- /dev/null +++ b/libs/flutter/shared/pubspec.yaml @@ -0,0 +1,54 @@ +name: flutter_shared +description: A new Flutter package project. +version: 0.0.1 +homepage: + +environment: + sdk: ">=2.17.6 <3.0.0" + flutter: ">=1.17.0" + +dependencies: + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # To add assets to your package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # To add custom fonts to your package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/custom-fonts/#from-packages diff --git a/libs/flutter/shared/test/flutter_shared_test.dart b/libs/flutter/shared/test/flutter_shared_test.dart new file mode 100644 index 0000000..d2f04fb --- /dev/null +++ b/libs/flutter/shared/test/flutter_shared_test.dart @@ -0,0 +1,12 @@ +import 'package:flutter_test/flutter_test.dart'; + +import 'package:flutter_shared/flutter_shared.dart'; + +void main() { + test('adds one to input values', () { + final calculator = Calculator(); + expect(calculator.addOne(2), 3); + expect(calculator.addOne(-7), -6); + expect(calculator.addOne(0), 1); + }); +} From 75912a0c874293938fd57810e42c8eeac27854e7 Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 04:26:44 -0300 Subject: [PATCH 02/13] feat(core): add dep-graph --- apps/flutter/suflex/project.json | 1 + apps/flutter/suflex/pubspec.lock | 9 +-------- apps/flutter/suflex/pubspec.yaml | 4 ---- libs/flutter/characters/project.json | 1 + libs/flutter/episodes/.flutter-plugins-dependencies | 2 +- libs/flutter/episodes/project.json | 1 + 6 files changed, 5 insertions(+), 13 deletions(-) diff --git a/apps/flutter/suflex/project.json b/apps/flutter/suflex/project.json index cc8e574..04232af 100644 --- a/apps/flutter/suflex/project.json +++ b/apps/flutter/suflex/project.json @@ -3,6 +3,7 @@ "name": "flutter-suflex", "sourceRoot": "apps/flutter/suflex/src", "projectType": "application", + "implicitDependencies": ["flutter-characters", "flutter-episodes"], "targets": { "analyze": { "executor": "@nrwl/workspace:run-commands", diff --git a/apps/flutter/suflex/pubspec.lock b/apps/flutter/suflex/pubspec.lock index 732329d..f411160 100644 --- a/apps/flutter/suflex/pubspec.lock +++ b/apps/flutter/suflex/pubspec.lock @@ -84,7 +84,7 @@ packages: source: sdk version: "0.0.0" flutter_api: - dependency: "direct main" + dependency: transitive description: path: "../../../libs/flutter/api" relative: true @@ -132,13 +132,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.2" - flutter_shared: - dependency: "direct main" - description: - path: "../../../libs/flutter/shared" - relative: true - source: path - version: "0.0.1" flutter_svg: dependency: transitive description: diff --git a/apps/flutter/suflex/pubspec.yaml b/apps/flutter/suflex/pubspec.yaml index 9adc605..3733d29 100644 --- a/apps/flutter/suflex/pubspec.yaml +++ b/apps/flutter/suflex/pubspec.yaml @@ -38,10 +38,6 @@ dependencies: path: ../../../libs/flutter/characters flutter_episodes: path: ../../../libs/flutter/episodes - flutter_api: - path: ../../../libs/flutter/api - flutter_shared: - path: ../../../libs/flutter/shared # The following adds the Cupertino Icons font to your application. diff --git a/libs/flutter/characters/project.json b/libs/flutter/characters/project.json index 5153846..fd9d0aa 100644 --- a/libs/flutter/characters/project.json +++ b/libs/flutter/characters/project.json @@ -3,6 +3,7 @@ "name": "flutter-characters", "sourceRoot": "libs/flutter/characters/src", "projectType": "library", + "implicitDependencies": ["flutter-api"], "targets": { "analyze": { "executor": "@nrwl/workspace:run-commands", diff --git a/libs/flutter/episodes/.flutter-plugins-dependencies b/libs/flutter/episodes/.flutter-plugins-dependencies index 695c367..5c180f9 100644 --- a/libs/flutter/episodes/.flutter-plugins-dependencies +++ b/libs/flutter/episodes/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_ios-2.1.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_android-2.0.14\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-2.0.4\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.7\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-2.1.1\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.1.3\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-2.1.1\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-2.0.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-10-22 02:45:24.384612","version":"3.0.5"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_ios-2.1.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_android-2.0.14\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-2.0.4\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.7\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-2.1.1\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.1.3\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-2.1.1\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-2.0.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-10-22 04:16:19.986117","version":"3.0.5"} \ No newline at end of file diff --git a/libs/flutter/episodes/project.json b/libs/flutter/episodes/project.json index 7108e57..2db4b82 100644 --- a/libs/flutter/episodes/project.json +++ b/libs/flutter/episodes/project.json @@ -3,6 +3,7 @@ "name": "flutter-episodes", "sourceRoot": "libs/flutter/episodes/src", "projectType": "library", + "implicitDependencies": ["flutter-api"], "targets": { "analyze": { "executor": "@nrwl/workspace:run-commands", From 8ed0438e6ece02731834c861fd4c52faf69c6d52 Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 04:59:02 -0300 Subject: [PATCH 03/13] feat(shared): create widgets and remove trash --- apps/flutter/suflex/pubspec.lock | 7 + apps/flutter/suflex/pubspec.yaml | 2 + .../characters/.flutter-plugins-dependencies | 2 +- .../characters/lib/src/characters_page.dart | 2 +- .../lib/src/pages/detail/detail_page.dart | 2 +- .../src/pages/favorites/favorites_page.dart | 2 +- .../lib/src/pages/search/search_page.dart | 2 +- .../character_episodes_list_widget.dart | 51 -------- .../src/widgets/character_image_widget.dart | 30 ----- .../src/widgets/character_info_widget.dart | 122 ------------------ .../lib/src/widgets/episode_card_widget.dart | 52 -------- .../lib/src/widgets/filters_widget.dart | 2 +- libs/flutter/characters/project.json | 2 +- libs/flutter/characters/pubspec.yaml | 2 + libs/flutter/episodes/project.json | 2 +- libs/flutter/shared/lib/flutter_shared.dart | 8 +- .../lib/src/widgets/choice_chip_widget.dart | 0 .../lib/src/widgets/feedback_page_widget.dart | 0 .../lib/src/widgets/generic_label_widget.dart | 0 libs/flutter/shared/pubspec.yaml | 1 + 20 files changed, 23 insertions(+), 268 deletions(-) delete mode 100644 libs/flutter/characters/lib/src/widgets/character_episodes_list_widget.dart delete mode 100644 libs/flutter/characters/lib/src/widgets/character_image_widget.dart delete mode 100644 libs/flutter/characters/lib/src/widgets/character_info_widget.dart delete mode 100644 libs/flutter/characters/lib/src/widgets/episode_card_widget.dart rename libs/flutter/{characters => shared}/lib/src/widgets/choice_chip_widget.dart (100%) rename libs/flutter/{characters => shared}/lib/src/widgets/feedback_page_widget.dart (100%) rename libs/flutter/{characters => shared}/lib/src/widgets/generic_label_widget.dart (100%) diff --git a/apps/flutter/suflex/pubspec.lock b/apps/flutter/suflex/pubspec.lock index f411160..3aef22c 100644 --- a/apps/flutter/suflex/pubspec.lock +++ b/apps/flutter/suflex/pubspec.lock @@ -132,6 +132,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.2" + flutter_shared: + dependency: "direct main" + description: + path: "../../../libs/flutter/shared" + relative: true + source: path + version: "0.0.1" flutter_svg: dependency: transitive description: diff --git a/apps/flutter/suflex/pubspec.yaml b/apps/flutter/suflex/pubspec.yaml index 3733d29..da47826 100644 --- a/apps/flutter/suflex/pubspec.yaml +++ b/apps/flutter/suflex/pubspec.yaml @@ -38,6 +38,8 @@ dependencies: path: ../../../libs/flutter/characters flutter_episodes: path: ../../../libs/flutter/episodes + flutter_shared: + path: ../../../libs/flutter/shared # The following adds the Cupertino Icons font to your application. diff --git a/libs/flutter/characters/.flutter-plugins-dependencies b/libs/flutter/characters/.flutter-plugins-dependencies index 50c7ebd..ad4b307 100644 --- a/libs/flutter/characters/.flutter-plugins-dependencies +++ b/libs/flutter/characters/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_ios-2.1.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_android-2.0.14\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-2.0.4\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.7\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-2.1.1\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.1.3\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-2.1.1\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-2.0.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-10-22 01:57:39.281944","version":"3.0.5"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_ios-2.1.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_android-2.0.14\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-2.0.4\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.7\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-2.1.1\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.1.3\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-2.1.1\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-2.0.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-10-22 04:38:58.958883","version":"3.0.5"} \ No newline at end of file diff --git a/libs/flutter/characters/lib/src/characters_page.dart b/libs/flutter/characters/lib/src/characters_page.dart index 2807910..213c510 100644 --- a/libs/flutter/characters/lib/src/characters_page.dart +++ b/libs/flutter/characters/lib/src/characters_page.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_api/flutter_api.dart'; import 'package:flutter_characters/src/characters_controller.dart'; -import 'package:flutter_characters/src/widgets/feedback_page_widget.dart'; import 'package:flutter_characters/src/widgets/filters_widget.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_modular/flutter_modular.dart'; +import 'package:flutter_shared/flutter_shared.dart'; class CharactersPage extends StatefulWidget { const CharactersPage({Key? key}) : super(key: key); diff --git a/libs/flutter/characters/lib/src/pages/detail/detail_page.dart b/libs/flutter/characters/lib/src/pages/detail/detail_page.dart index 310787b..e81bf82 100644 --- a/libs/flutter/characters/lib/src/pages/detail/detail_page.dart +++ b/libs/flutter/characters/lib/src/pages/detail/detail_page.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_characters/src/pages/detail/detail_controller.dart'; -import 'package:flutter_characters/src/widgets/generic_label_widget.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_modular/flutter_modular.dart'; +import 'package:flutter_shared/flutter_shared.dart'; import 'package:intl/intl.dart'; class DetailPage extends StatefulWidget { diff --git a/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart b/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart index aa360db..cae8a62 100644 --- a/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart +++ b/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_characters/src/pages/favorites/favorites_controller.dart'; -import 'package:flutter_characters/src/widgets/feedback_page_widget.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_modular/flutter_modular.dart'; +import 'package:flutter_shared/flutter_shared.dart'; class FavoritesPage extends StatefulWidget { const FavoritesPage({Key? key}) : super(key: key); diff --git a/libs/flutter/characters/lib/src/pages/search/search_page.dart b/libs/flutter/characters/lib/src/pages/search/search_page.dart index 49a896b..885a0de 100644 --- a/libs/flutter/characters/lib/src/pages/search/search_page.dart +++ b/libs/flutter/characters/lib/src/pages/search/search_page.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_characters/src/pages/search/search_controller.dart'; -import 'package:flutter_characters/src/widgets/feedback_page_widget.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_modular/flutter_modular.dart'; +import 'package:flutter_shared/flutter_shared.dart'; class SearchPage extends StatefulWidget { final String searchText; diff --git a/libs/flutter/characters/lib/src/widgets/character_episodes_list_widget.dart b/libs/flutter/characters/lib/src/widgets/character_episodes_list_widget.dart deleted file mode 100644 index a36c2e2..0000000 --- a/libs/flutter/characters/lib/src/widgets/character_episodes_list_widget.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_api/flutter_api.dart'; -import 'package:flutter_characters/src/widgets/episode_card_widget.dart'; - -var episodeService = EpisodeService(); - -class CharacterEpisodesListWidget extends StatelessWidget { - final List episode; - - const CharacterEpisodesListWidget({Key? key, required this.episode}) : super(key: key); - - List _getIds() { - List ids = episode.map((url) { - var items = url.split('/'); - var id = items[items.length -1]; - - return int.parse(id); - }).toList(); - - return ids; - } - - @override - Widget build(BuildContext context) { - return FutureBuilder>( - future: episodeService.getListOfEpisodes(_getIds()), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator(),); - } else if (snapshot.hasError || snapshot.data == null) { - return const Text('Ops! ocorreu um erro ao carregar os dados. Tente novamente por favor!'); - } - - var episodeList = snapshot.data!; - - return SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Row( - children: episodeList.map((item) { - return EpisodeCardWidget( - episode: item.episode, - id: item.id, - name: item.name, - ); - }).toList(), - ), - ); - }, - ); - } -} \ No newline at end of file diff --git a/libs/flutter/characters/lib/src/widgets/character_image_widget.dart b/libs/flutter/characters/lib/src/widgets/character_image_widget.dart deleted file mode 100644 index 2054143..0000000 --- a/libs/flutter/characters/lib/src/widgets/character_image_widget.dart +++ /dev/null @@ -1,30 +0,0 @@ -import 'package:flutter/material.dart'; - -class CharacterImageWidget extends StatelessWidget { - final String image; - - const CharacterImageWidget({Key? key, required this.image}) : super(key: key); - - @override - Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.all(24), - child: Container( - height: 300, - decoration: BoxDecoration( - color: Colors.grey[100], - borderRadius: BorderRadius.circular(12) - ), - child: ClipRRect( - borderRadius: BorderRadius.circular(12), - child: Image.network( - image, - fit: BoxFit.fill, - width: double.infinity, - height: double.infinity, - ), - ), - ), - ); - } -} \ No newline at end of file diff --git a/libs/flutter/characters/lib/src/widgets/character_info_widget.dart b/libs/flutter/characters/lib/src/widgets/character_info_widget.dart deleted file mode 100644 index df9f656..0000000 --- a/libs/flutter/characters/lib/src/widgets/character_info_widget.dart +++ /dev/null @@ -1,122 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_api/flutter_api.dart'; - -class CharacterInfoWidget extends StatelessWidget { - final String name; - final String species; - final String status; - final String gender; - final DateTime created; - final CharacterLocation origin; - final CharacterLocation location; - - const CharacterInfoWidget({ - Key? key, - required this.name, - required this.species, - required this.status, - required this.gender, - required this.created, - required this.origin, - required this.location - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 24), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - name, - textAlign: TextAlign.center, - style: const TextStyle( - fontSize: 26, - fontWeight: FontWeight.w700 - ), - ), - Text( - species, - textAlign: TextAlign.center, - style: const TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - color: Colors.indigo - ), - ), - Row( - children: [ - SizedBox( - width: 100, - child: Text( - 'Status', - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w400, - color: Colors.grey[500] - ), - ) - ), - Text( - status, - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w400, - color: Colors.grey[900] - ), - ) - ], - ), - Row( - children: [ - SizedBox( - width: 100, - child: Text( - 'Gênero', - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w400, - color: Colors.grey[500] - ), - ) - ), - Text( - gender, - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w400, - color: Colors.grey[900] - ), - ) - ], - ), - Row( - children: [ - SizedBox( - width: 100, - child: Text( - 'Data de criação', - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w400, - color: Colors.grey[500] - ), - ) - ), - Text( - created.toString(), - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w400, - color: Colors.grey[900] - ), - ) - ], - ) - ], - ), - ); - } -} \ No newline at end of file diff --git a/libs/flutter/characters/lib/src/widgets/episode_card_widget.dart b/libs/flutter/characters/lib/src/widgets/episode_card_widget.dart deleted file mode 100644 index 8e179b2..0000000 --- a/libs/flutter/characters/lib/src/widgets/episode_card_widget.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'package:flutter/material.dart'; - -class EpisodeCardWidget extends StatelessWidget { - final int id; - final String episode; - final String name; - - const EpisodeCardWidget({Key? key, required this.id, required this.episode, required this.name}) : super(key: key); - - @override - Widget build(BuildContext context) { - return Container( - margin: const EdgeInsets.symmetric(vertical: 16, horizontal: 8), - height: 150, - width: 150, - decoration: BoxDecoration( - border: Border.all( - width: 1, - color: Colors.grey.shade200 - ), - borderRadius: BorderRadius.circular(10) - ), - child: InkWell( - onTap: () => print('Clicou no episódio $id'), - borderRadius: BorderRadius.circular(10), - child: Padding( - padding: const EdgeInsets.all(20), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - episode, - style: const TextStyle( - fontSize: 22, - fontWeight: FontWeight.w700 - ), - ), - const SizedBox(height: 10,), - Text( - name, - style: TextStyle( - fontSize: 14, - color: Colors.grey[500] - ), - ) - ], - ), - ), - ), - ); - } -} \ No newline at end of file diff --git a/libs/flutter/characters/lib/src/widgets/filters_widget.dart b/libs/flutter/characters/lib/src/widgets/filters_widget.dart index c611b55..e4a108d 100644 --- a/libs/flutter/characters/lib/src/widgets/filters_widget.dart +++ b/libs/flutter/characters/lib/src/widgets/filters_widget.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_api/flutter_api.dart'; import 'package:flutter_characters/src/models/filter.dart'; -import 'package:flutter_characters/src/widgets/choice_chip_widget.dart'; import 'package:flutter_modular/flutter_modular.dart'; +import 'package:flutter_shared/flutter_shared.dart'; class FiltersWidget extends StatefulWidget { final Function(CharacterFilters) onChange; diff --git a/libs/flutter/characters/project.json b/libs/flutter/characters/project.json index fd9d0aa..e0a7136 100644 --- a/libs/flutter/characters/project.json +++ b/libs/flutter/characters/project.json @@ -3,7 +3,7 @@ "name": "flutter-characters", "sourceRoot": "libs/flutter/characters/src", "projectType": "library", - "implicitDependencies": ["flutter-api"], + "implicitDependencies": ["flutter-api", "flutter-shared"], "targets": { "analyze": { "executor": "@nrwl/workspace:run-commands", diff --git a/libs/flutter/characters/pubspec.yaml b/libs/flutter/characters/pubspec.yaml index cd4d505..8feeeb1 100644 --- a/libs/flutter/characters/pubspec.yaml +++ b/libs/flutter/characters/pubspec.yaml @@ -17,6 +17,8 @@ dependencies: intl: ^0.17.0 flutter_api: path: ../api + flutter_shared: + path: ../shared dev_dependencies: flutter_test: diff --git a/libs/flutter/episodes/project.json b/libs/flutter/episodes/project.json index 2db4b82..4e7d86b 100644 --- a/libs/flutter/episodes/project.json +++ b/libs/flutter/episodes/project.json @@ -3,7 +3,7 @@ "name": "flutter-episodes", "sourceRoot": "libs/flutter/episodes/src", "projectType": "library", - "implicitDependencies": ["flutter-api"], + "implicitDependencies": ["flutter-api", "flutter-shared"], "targets": { "analyze": { "executor": "@nrwl/workspace:run-commands", diff --git a/libs/flutter/shared/lib/flutter_shared.dart b/libs/flutter/shared/lib/flutter_shared.dart index 74a8e3f..7b10d57 100644 --- a/libs/flutter/shared/lib/flutter_shared.dart +++ b/libs/flutter/shared/lib/flutter_shared.dart @@ -1,7 +1,5 @@ library flutter_shared; -/// A Calculator. -class Calculator { - /// Returns [value] plus 1. - int addOne(int value) => value + 1; -} +export './src/widgets/choice_chip_widget.dart'; +export './src/widgets/feedback_page_widget.dart'; +export './src/widgets/generic_label_widget.dart'; diff --git a/libs/flutter/characters/lib/src/widgets/choice_chip_widget.dart b/libs/flutter/shared/lib/src/widgets/choice_chip_widget.dart similarity index 100% rename from libs/flutter/characters/lib/src/widgets/choice_chip_widget.dart rename to libs/flutter/shared/lib/src/widgets/choice_chip_widget.dart diff --git a/libs/flutter/characters/lib/src/widgets/feedback_page_widget.dart b/libs/flutter/shared/lib/src/widgets/feedback_page_widget.dart similarity index 100% rename from libs/flutter/characters/lib/src/widgets/feedback_page_widget.dart rename to libs/flutter/shared/lib/src/widgets/feedback_page_widget.dart diff --git a/libs/flutter/characters/lib/src/widgets/generic_label_widget.dart b/libs/flutter/shared/lib/src/widgets/generic_label_widget.dart similarity index 100% rename from libs/flutter/characters/lib/src/widgets/generic_label_widget.dart rename to libs/flutter/shared/lib/src/widgets/generic_label_widget.dart diff --git a/libs/flutter/shared/pubspec.yaml b/libs/flutter/shared/pubspec.yaml index 13cabc3..54549ad 100644 --- a/libs/flutter/shared/pubspec.yaml +++ b/libs/flutter/shared/pubspec.yaml @@ -10,6 +10,7 @@ environment: dependencies: flutter: sdk: flutter + flutter_svg: ^1.1.5 dev_dependencies: flutter_test: From deadf0026dcf7a117e1f1aa365c1eafd10cc1f05 Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 05:13:28 -0300 Subject: [PATCH 04/13] feat(shared): create assets --- .../api/lib/src/shared/shared_pref.dart | 35 ------------------- .../characters/lib/src/characters_page.dart | 2 +- .../lib/src/pages/detail/detail_page.dart | 2 -- .../src/pages/favorites/favorites_page.dart | 4 +-- .../lib/src/pages/search/search_page.dart | 2 +- libs/flutter/shared/lib/flutter_shared.dart | 2 ++ libs/flutter/shared/lib/src/utils/assets.dart | 5 +++ 7 files changed, 11 insertions(+), 41 deletions(-) create mode 100644 libs/flutter/shared/lib/src/utils/assets.dart diff --git a/libs/flutter/api/lib/src/shared/shared_pref.dart b/libs/flutter/api/lib/src/shared/shared_pref.dart index 3c5e45e..a1fac6c 100644 --- a/libs/flutter/api/lib/src/shared/shared_pref.dart +++ b/libs/flutter/api/lib/src/shared/shared_pref.dart @@ -37,38 +37,3 @@ class SharedPref { prefs.setString(key, s); } } - -// import 'dart:convert'; - -// import 'package:flutter_api/flutter_api.dart'; -// import 'package:shared_preferences/shared_preferences.dart'; - -// class SharedPref { -// read(String key) async { -// SharedPreferences prefs = await SharedPreferences.getInstance(); - -// Map json = prefs.getString(key); -// var user = Character.fromJson(json); - -// // Map json = jsonDecode(prefs.getString(key)); - -// print(user); - -// // jsonDecode(prefs.getString(key)) - -// // json.decode(); - -// return prefs.getString(key); -// } - -// save(String key, value) async { -// SharedPreferences prefs = await SharedPreferences.getInstance(); - -// prefs.setString(key, json.encode(value)); -// } - -// remove(String key) async { -// final prefs = await SharedPreferences.getInstance(); -// prefs.remove(key); -// } -// } \ No newline at end of file diff --git a/libs/flutter/characters/lib/src/characters_page.dart b/libs/flutter/characters/lib/src/characters_page.dart index 213c510..c4eedc6 100644 --- a/libs/flutter/characters/lib/src/characters_page.dart +++ b/libs/flutter/characters/lib/src/characters_page.dart @@ -106,7 +106,7 @@ class _CharactersPageState extends State { builder: (_) { if (charactersController.characters.isEmpty && charactersController.hasCharacters) { return const FeedbackPageWidget( - illustration: 'assets/illustrations/search.svg', + illustration: Assets.ilSearch, message: 'Desculpe, não conseguimos \n encontrar o personagem', ); } diff --git a/libs/flutter/characters/lib/src/pages/detail/detail_page.dart b/libs/flutter/characters/lib/src/pages/detail/detail_page.dart index e81bf82..950bcc1 100644 --- a/libs/flutter/characters/lib/src/pages/detail/detail_page.dart +++ b/libs/flutter/characters/lib/src/pages/detail/detail_page.dart @@ -276,7 +276,6 @@ class _DetailPageState extends State { color: Colors.grey, ), ), - onTap: () {}, ), ListTile( contentPadding: const EdgeInsets.symmetric(horizontal: 24), @@ -295,7 +294,6 @@ class _DetailPageState extends State { color: Colors.grey, ), ), - onTap: () {}, ), ], ) diff --git a/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart b/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart index cae8a62..5672c68 100644 --- a/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart +++ b/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart @@ -94,14 +94,14 @@ class _FavoritesPageState extends State { favoriteController.hasFilterFavorites ) { return const FeedbackPageWidget( - illustration: 'assets/illustrations/search.svg', + illustration: Assets.ilSearch, message: 'Desculpe, não conseguimos \n encontrar o personagem', ); } if (favoriteController.favorites.isEmpty && favoriteController.hasFavorites) { return const FeedbackPageWidget( - illustration: 'assets/illustrations/favorite.svg', + illustration: Assets.ilFavorite, message: 'Ops! você ainda não \nadicionou nenhum favorito', ); } diff --git a/libs/flutter/characters/lib/src/pages/search/search_page.dart b/libs/flutter/characters/lib/src/pages/search/search_page.dart index 885a0de..bdf1ae0 100644 --- a/libs/flutter/characters/lib/src/pages/search/search_page.dart +++ b/libs/flutter/characters/lib/src/pages/search/search_page.dart @@ -95,7 +95,7 @@ class _SearchPageState extends State { builder: (_) { if (searchController.characters.isEmpty && searchController.hasCharacters) { return const FeedbackPageWidget( - illustration: 'assets/illustrations/search.svg', + illustration: Assets.ilSearch, message: 'Desculpe, não conseguimos \n encontrar o personagem', ); } diff --git a/libs/flutter/shared/lib/flutter_shared.dart b/libs/flutter/shared/lib/flutter_shared.dart index 7b10d57..8a39713 100644 --- a/libs/flutter/shared/lib/flutter_shared.dart +++ b/libs/flutter/shared/lib/flutter_shared.dart @@ -3,3 +3,5 @@ library flutter_shared; export './src/widgets/choice_chip_widget.dart'; export './src/widgets/feedback_page_widget.dart'; export './src/widgets/generic_label_widget.dart'; + +export './src/utils/assets.dart'; diff --git a/libs/flutter/shared/lib/src/utils/assets.dart b/libs/flutter/shared/lib/src/utils/assets.dart new file mode 100644 index 0000000..dddba4e --- /dev/null +++ b/libs/flutter/shared/lib/src/utils/assets.dart @@ -0,0 +1,5 @@ +class Assets { + static const String ilError = 'assets/illustrations/error.svg'; + static const String ilFavorite = 'assets/illustrations/favorite.svg'; + static const String ilSearch = 'assets/illustrations/search.svg'; +} \ No newline at end of file From 4aacad7600554147ddad88ef852073521eafad48 Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 18:13:47 -0300 Subject: [PATCH 05/13] feat(shared): create widgets skeleton --- .../widgets/skeleton_list_tile_widget.dart | 39 ++++++++++++++ .../lib/src/widgets/skeleton_list_widget.dart | 53 +++++++++++++++++++ .../lib/src/widgets/skeleton_widget.dart | 31 +++++++++++ libs/flutter/shared/pubspec.yaml | 1 + 4 files changed, 124 insertions(+) create mode 100644 libs/flutter/shared/lib/src/widgets/skeleton_list_tile_widget.dart create mode 100644 libs/flutter/shared/lib/src/widgets/skeleton_list_widget.dart create mode 100644 libs/flutter/shared/lib/src/widgets/skeleton_widget.dart diff --git a/libs/flutter/shared/lib/src/widgets/skeleton_list_tile_widget.dart b/libs/flutter/shared/lib/src/widgets/skeleton_list_tile_widget.dart new file mode 100644 index 0000000..c934c59 --- /dev/null +++ b/libs/flutter/shared/lib/src/widgets/skeleton_list_tile_widget.dart @@ -0,0 +1,39 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_shared/flutter_shared.dart'; +import 'package:skeletons/skeletons.dart'; + +class SkeletonListTileWidget extends StatelessWidget { + final Widget child; + final bool isLoading; + + const SkeletonListTileWidget({Key? key, required this.child, required this.isLoading}) : super(key: key); + + @override + Widget build(BuildContext context) { + return SkeletonWidget( + isLoading: isLoading, + skeleton: buildSkeletonView(), + child: child + ); + } + + Widget buildSkeletonView() { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16), + child: SkeletonListTile( + hasSubtitle: true, + hasLeading: false, + contentSpacing: 0, + verticalSpacing: 6, + padding: const EdgeInsets.all(0), + titleStyle: SkeletonLineStyle(borderRadius: BorderRadius.circular(16), height: 18,), + subtitleStyle: SkeletonLineStyle( + borderRadius: BorderRadius.circular(16), + randomLength: true, + maxLength: 128, + height: 14 + ), + ), + ); + } +} \ No newline at end of file diff --git a/libs/flutter/shared/lib/src/widgets/skeleton_list_widget.dart b/libs/flutter/shared/lib/src/widgets/skeleton_list_widget.dart new file mode 100644 index 0000000..b794eb8 --- /dev/null +++ b/libs/flutter/shared/lib/src/widgets/skeleton_list_widget.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_shared/src/widgets/skeleton_widget.dart'; +import 'package:skeletons/skeletons.dart'; + +class SkeletonListWidget extends StatelessWidget { + final Widget child; + final bool isLoading; + final int? itemCount; + final bool hasLeading; + + const SkeletonListWidget({ + Key? key, + required this.child, + required this.isLoading, + this.itemCount = 5, + this.hasLeading = true + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return SkeletonWidget( + isLoading: isLoading, + skeleton: buildSkeletonView(), + child: child + ); + } + + Widget buildSkeletonView() { + return SkeletonListView( + itemCount: itemCount, + item: SkeletonListTile( + verticalSpacing: 12, + hasLeading: hasLeading, + leadingStyle: const SkeletonAvatarStyle( + shape: BoxShape.circle + ), + titleStyle: SkeletonLineStyle( + height: 16, + minLength: 200, + randomLength: true, + borderRadius: BorderRadius.circular(12) + ), + subtitleStyle: SkeletonLineStyle( + height: 12, + maxLength: 200, + randomLength: true, + borderRadius: BorderRadius.circular(12) + ), + hasSubtitle: true, + ), + ); + } +} \ No newline at end of file diff --git a/libs/flutter/shared/lib/src/widgets/skeleton_widget.dart b/libs/flutter/shared/lib/src/widgets/skeleton_widget.dart new file mode 100644 index 0000000..e5369aa --- /dev/null +++ b/libs/flutter/shared/lib/src/widgets/skeleton_widget.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:skeletons/skeletons.dart'; + +class SkeletonWidget extends StatelessWidget { + final Widget child; + final bool isLoading; + final Widget skeleton; + + const SkeletonWidget({Key? key, required this.child, required this.isLoading, required this.skeleton}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Skeleton( + duration: const Duration(milliseconds: 1500), + shimmerGradient: LinearGradient( + colors: [ + Colors.grey.shade100, + Colors.grey.shade200, + Colors.grey.shade200, + Colors.grey.shade100, + ], + stops: const [0.0, 0.3, 1, 1,], + begin: const Alignment(-1, 0), + end: const Alignment(1, 0), + ), + isLoading: isLoading, + skeleton: skeleton, + child: child + ); + } +} \ No newline at end of file diff --git a/libs/flutter/shared/pubspec.yaml b/libs/flutter/shared/pubspec.yaml index 54549ad..869ee53 100644 --- a/libs/flutter/shared/pubspec.yaml +++ b/libs/flutter/shared/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: flutter: sdk: flutter flutter_svg: ^1.1.5 + skeletons: ^0.0.3 dev_dependencies: flutter_test: From 79836d5d1f05db687b0837d4093a5c0f5544ba5d Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 18:15:00 -0300 Subject: [PATCH 06/13] feat(shared): create widget appbar and update lib --- libs/flutter/shared/lib/flutter_shared.dart | 4 + libs/flutter/shared/lib/src/utils/assets.dart | 2 + .../shared/lib/src/widgets/appbar_widget.dart | 107 ++++++++++++++++++ .../lib/src/widgets/generic_label_widget.dart | 2 +- 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 libs/flutter/shared/lib/src/widgets/appbar_widget.dart diff --git a/libs/flutter/shared/lib/flutter_shared.dart b/libs/flutter/shared/lib/flutter_shared.dart index 8a39713..07e6051 100644 --- a/libs/flutter/shared/lib/flutter_shared.dart +++ b/libs/flutter/shared/lib/flutter_shared.dart @@ -1,7 +1,11 @@ library flutter_shared; +export './src/widgets/appbar_widget.dart'; export './src/widgets/choice_chip_widget.dart'; export './src/widgets/feedback_page_widget.dart'; export './src/widgets/generic_label_widget.dart'; +export './src/widgets/skeleton_widget.dart'; +export './src/widgets/skeleton_list_widget.dart'; +export './src/widgets/skeleton_list_tile_widget.dart'; export './src/utils/assets.dart'; diff --git a/libs/flutter/shared/lib/src/utils/assets.dart b/libs/flutter/shared/lib/src/utils/assets.dart index dddba4e..f8c430f 100644 --- a/libs/flutter/shared/lib/src/utils/assets.dart +++ b/libs/flutter/shared/lib/src/utils/assets.dart @@ -2,4 +2,6 @@ class Assets { static const String ilError = 'assets/illustrations/error.svg'; static const String ilFavorite = 'assets/illustrations/favorite.svg'; static const String ilSearch = 'assets/illustrations/search.svg'; + + static const String imgRickMorty = 'assets/images/rickandmortyapi.jpg'; } \ No newline at end of file diff --git a/libs/flutter/shared/lib/src/widgets/appbar_widget.dart b/libs/flutter/shared/lib/src/widgets/appbar_widget.dart new file mode 100644 index 0000000..af2f907 --- /dev/null +++ b/libs/flutter/shared/lib/src/widgets/appbar_widget.dart @@ -0,0 +1,107 @@ +import 'package:flutter/material.dart'; + +class AppBarWidget extends StatelessWidget implements PreferredSizeWidget { + final Widget? leading; + final String title; + final bool? centerTitle; + final bool automaticallyImplyLeading; + final List? actions; + final String? searchHintText; + final ValueChanged? onSubmitted; + final TextInputAction? textInputAction; + final TextEditingController? searchController; + final VoidCallback? onPressedLeadingIcon; + final ValueChanged? onChanged; + final bool? showSearch; + + const AppBarWidget({ + Key? key, + this.leading, + required this.title, + this.centerTitle, + this.automaticallyImplyLeading = true, + this.actions, + this.searchHintText, + this.onSubmitted, + this.textInputAction, + this.searchController, + this.onPressedLeadingIcon, + this.onChanged, + this.showSearch = true, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + final ScaffoldState? scaffold = Scaffold.maybeOf(context); + final bool hasDrawer = scaffold?.hasDrawer ?? false; + final ModalRoute? parentRoute = ModalRoute.of(context); + final bool canPop = parentRoute?.canPop ?? false; + + Widget? leadingIcon = leading; + + if (leadingIcon == null && automaticallyImplyLeading) { + if (hasDrawer) { + leadingIcon = IconButton( + icon: const Icon(Icons.mood_sharp, color: Colors.yellowAccent), + onPressed: () => Scaffold.of(context).openDrawer(), + ); + } else { + if (canPop) { + leadingIcon = IconButton( + icon: const Icon( + Icons.arrow_back_outlined, + color: Colors.black87, + ), + onPressed: () => onPressedLeadingIcon!(), + ); + } + } + } + + return AppBar( + elevation: 0, + backgroundColor: Colors.white, + leading: leadingIcon, + title: Text(title, style: const TextStyle(color: Colors.black87, fontSize: 16),), + centerTitle: centerTitle, + actions: actions, + bottom: showSearch! ? AppBar( + elevation: 0, + automaticallyImplyLeading: false, + backgroundColor: Colors.white, + title: SizedBox( + height: 42, + child: TextField( + controller: searchController, + cursorColor: Colors.grey, + decoration: InputDecoration( + contentPadding: const EdgeInsets.all(0), + fillColor: Colors.grey[100], + filled: true, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(12), + borderSide: BorderSide.none + ), + hintText: searchHintText, + hintStyle: const TextStyle( + color: Colors.grey, + fontSize: 16 + ), + prefixIcon: Container( + padding: const EdgeInsets.symmetric(horizontal: 16), + width: 18, + child: const Icon(Icons.search), + ) + ), + onSubmitted: (value) => onSubmitted!(value), + onChanged: (value) => onChanged!(value), + textInputAction: textInputAction, + ), + ), + ) : null, + ); + } + + @override + Size get preferredSize => Size.fromHeight(showSearch! ? 112 : kToolbarHeight); +} \ No newline at end of file diff --git a/libs/flutter/shared/lib/src/widgets/generic_label_widget.dart b/libs/flutter/shared/lib/src/widgets/generic_label_widget.dart index ecd94a7..b6178c6 100644 --- a/libs/flutter/shared/lib/src/widgets/generic_label_widget.dart +++ b/libs/flutter/shared/lib/src/widgets/generic_label_widget.dart @@ -17,7 +17,7 @@ class GenereicLabelWidget extends StatelessWidget { ), child: Text( label, - style: const TextStyle(color: Colors.red), + style: const TextStyle(color: Colors.red, fontWeight: FontWeight.w700), ), ); } From 075dec7dccbd938a891450ce9a620185a184a492 Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 18:16:09 -0300 Subject: [PATCH 07/13] feat(characters): update layout --- apps/flutter/suflex/pubspec.lock | 7 + apps/flutter/suflex/pubspec.yaml | 1 + .../characters/.flutter-plugins-dependencies | 2 +- .../characters/lib/src/characters_page.dart | 119 +++---- .../lib/src/pages/detail/detail_page.dart | 307 ++++++------------ .../src/pages/favorites/favorites_page.dart | 99 ++---- .../lib/src/pages/search/search_page.dart | 91 ++---- libs/flutter/characters/pubspec.yaml | 1 + 8 files changed, 212 insertions(+), 415 deletions(-) diff --git a/apps/flutter/suflex/pubspec.lock b/apps/flutter/suflex/pubspec.lock index 3aef22c..1f4876b 100644 --- a/apps/flutter/suflex/pubspec.lock +++ b/apps/flutter/suflex/pubspec.lock @@ -352,6 +352,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.1" + skeletons: + dependency: "direct main" + description: + name: skeletons + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.3" sky_engine: dependency: transitive description: flutter diff --git a/apps/flutter/suflex/pubspec.yaml b/apps/flutter/suflex/pubspec.yaml index da47826..f308f77 100644 --- a/apps/flutter/suflex/pubspec.yaml +++ b/apps/flutter/suflex/pubspec.yaml @@ -34,6 +34,7 @@ dependencies: mobx: ^2.1.1 intl: ^0.17.0 shared_preferences: ^2.0.15 + skeletons: ^0.0.3 flutter_characters: path: ../../../libs/flutter/characters flutter_episodes: diff --git a/libs/flutter/characters/.flutter-plugins-dependencies b/libs/flutter/characters/.flutter-plugins-dependencies index ad4b307..defcaee 100644 --- a/libs/flutter/characters/.flutter-plugins-dependencies +++ b/libs/flutter/characters/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_ios-2.1.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_android-2.0.14\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-2.0.4\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.7\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-2.1.1\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.1.3\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-2.1.1\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-2.0.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-10-22 04:38:58.958883","version":"3.0.5"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_ios-2.1.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_android-2.0.14\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-2.0.4\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.7\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-2.1.1\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.1.3\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-2.1.1\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-2.0.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-10-22 05:18:52.864957","version":"3.0.5"} \ No newline at end of file diff --git a/libs/flutter/characters/lib/src/characters_page.dart b/libs/flutter/characters/lib/src/characters_page.dart index c4eedc6..ecbf9f3 100644 --- a/libs/flutter/characters/lib/src/characters_page.dart +++ b/libs/flutter/characters/lib/src/characters_page.dart @@ -34,69 +34,34 @@ class _CharactersPageState extends State { Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, - appBar: buildAppBar(), - body: SafeArea( - child: buildList(), - ), - ); - } - - AppBar buildAppBar() { - return AppBar( - elevation: 0, - backgroundColor: Colors.white, - title: const Text('Personagens', style: TextStyle(color: Colors.black87, fontSize: 16),), - actions: [ - IconButton( - icon: const Icon( - Icons.bookmark_added, - color: Colors.red, - ), - onPressed: () => Modular.to.pushNamed('/favorites'), - ), - IconButton( - icon: const Icon( - Icons.filter_list_outlined, - color: Colors.red, - ), - onPressed: () => changeFilter(), - ) - ], - bottom: AppBar( - elevation: 0, - automaticallyImplyLeading: false, - backgroundColor: Colors.white, - title: SizedBox( - height: 42, - child: TextField( - controller: searchValueController, - cursorColor: Colors.grey, - decoration: InputDecoration( - contentPadding: const EdgeInsets.all(0), - fillColor: Colors.grey[100], - filled: true, - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), - borderSide: BorderSide.none - ), - hintText: 'Buscar personagens', - hintStyle: const TextStyle( - color: Colors.grey, - fontSize: 16 - ), - prefixIcon: Container( - padding: const EdgeInsets.symmetric(horizontal: 16), - width: 18, - child: const Icon(Icons.search), - ) + appBar: AppBarWidget( + title: 'Personagens', + searchHintText: 'Buscar personagens', + searchController: searchValueController, + textInputAction: TextInputAction.search, + onSubmitted: (value) { + Modular.to.pushNamed('/character/search/$value'); + searchValueController.clear(); + }, + actions: [ + IconButton( + icon: const Icon( + Icons.bookmark_added, + color: Colors.red, ), - onSubmitted: (value) { - Modular.to.pushNamed('/character/search/$value'); - searchValueController.clear(); - }, - textInputAction: TextInputAction.search, + onPressed: () => Modular.to.pushNamed('/favorites'), ), - ), + IconButton( + icon: const Icon( + Icons.filter_list_outlined, + color: Colors.red, + ), + onPressed: () => changeFilter(), + ) + ], + ), + body: SafeArea( + child: buildList(), ), ); } @@ -111,20 +76,24 @@ class _CharactersPageState extends State { ); } - return charactersController.hasCharacters ? ListView.builder( - itemCount: charactersController.characters.length, - itemBuilder: (context, index) { - return ListTile( - leading: CircleAvatar( - backgroundImage: NetworkImage(charactersController.characters[index].image), - backgroundColor: Colors.grey[300] - ), - title: Text(charactersController.characters[index].name), - subtitle: Text(charactersController.characters[index].species), - onTap: () => Modular.to.pushNamed('/character/${charactersController.characters[index].id}'), - ); - }, - ) : const Center(child: CircularProgressIndicator(),); + return SkeletonListWidget( + itemCount: 10, + isLoading: !charactersController.hasCharacters, + child: ListView.builder( + itemCount: charactersController.characters.length, + itemBuilder: (context, index) { + return ListTile( + leading: CircleAvatar( + backgroundImage: NetworkImage(charactersController.characters[index].image), + backgroundColor: Colors.grey[300] + ), + title: Text(charactersController.characters[index].name), + subtitle: Text(charactersController.characters[index].species), + onTap: () => Modular.to.pushNamed('/character/${charactersController.characters[index].id}'), + ); + }, + ), + ); }, ); } diff --git a/libs/flutter/characters/lib/src/pages/detail/detail_page.dart b/libs/flutter/characters/lib/src/pages/detail/detail_page.dart index 950bcc1..337a460 100644 --- a/libs/flutter/characters/lib/src/pages/detail/detail_page.dart +++ b/libs/flutter/characters/lib/src/pages/detail/detail_page.dart @@ -4,6 +4,7 @@ import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_modular/flutter_modular.dart'; import 'package:flutter_shared/flutter_shared.dart'; import 'package:intl/intl.dart'; +import 'package:skeletons/skeletons.dart'; class DetailPage extends StatefulWidget { final String id; @@ -47,7 +48,33 @@ class _DetailPageState extends State { length: 2, child: Scaffold( backgroundColor: Colors.white, - appBar: buildAppBar(), + appBar: AppBarWidget( + title: 'Detalhe', + centerTitle: true, + showSearch: false, + onPressedLeadingIcon: () => Modular.to.pop(), + actions: [ + Observer( + builder: (_) { + return detailController.hasCharacter ? IconButton( + icon: detailController.hasFavorite ? const Icon( + Icons.favorite, + color: Colors.red, + ) : const Icon( + Icons.favorite_outline, + color: Colors.black87, + ), + onPressed: () { + detailController.addCharacterToFavorite( + detailController.character, + detailController.hasFavorite + ); + } + ) : Container(); + }, + ), + ], + ), body: SafeArea( child: NestedScrollView( headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { @@ -56,30 +83,26 @@ class _DetailPageState extends State { buildTitle(), const SliverToBoxAdapter( child: TabBar( - indicator: BoxDecoration( - border: Border( - top: BorderSide(color: Colors.red, width: 3), + padding: EdgeInsets.symmetric(horizontal: 8), + indicator: BoxDecoration( + border: Border( + top: BorderSide(color: Colors.red, width: 3), + ), ), + isScrollable: true, + labelColor: Colors.red, + unselectedLabelColor: Colors.grey, + tabs: [ + Tab(child: Text('Informações')), + Tab(child: Text('Episódios ')), + ], ), - isScrollable: true, - labelColor: Colors.red, - unselectedLabelColor: Colors.grey, - tabs: [ - Tab(child: Text('Informações')), - Tab(child: Text('Episódios ')), - ], - ), ), ]; }, body: TabBarView( children: [ - ListView( - children: [ - buildInfo(), - buildOriginLocation(), - ], - ), + buildInfo(), buildCharacterEpisodes(), ], ), @@ -89,66 +112,6 @@ class _DetailPageState extends State { ); } - AppBar buildAppBar() { - return AppBar( - elevation: 0, - backgroundColor: Colors.transparent, - centerTitle: true, - title: const Text('Detalhe', style: TextStyle(color: Colors.black87, fontSize: 18),), - leading: IconButton( - icon: const Icon( - Icons.arrow_back_outlined, - color: Colors.black87, - ), - onPressed: () => Modular.to.pop(), - ), - actions: [ - Observer( - builder: (_) { - return detailController.hasCharacter ? IconButton( - icon: detailController.hasFavorite ? const Icon( - Icons.favorite, - color: Colors.red, - ) : const Icon( - Icons.favorite_outline, - color: Colors.black87, - ), - onPressed: () { - detailController.addCharacterToFavorite( - detailController.character, - detailController.hasFavorite - ); - } - ) : Container(); - }, - ), - ], - ); - } - - buildTabBar() { - return Observer( - builder: (_) { - return detailController.hasCharacter ? SliverToBoxAdapter( - child: TabBar( - indicator: const BoxDecoration( - border: Border( - top: BorderSide(color: Colors.red, width: 3), - ), - ), - isScrollable: true, - labelColor: Colors.red, - unselectedLabelColor: Colors.grey, - tabs: [ - const Tab(child: Text('Informações')), - Tab(child: Text('Episódios (${detailController.episodes.length})')), - ], - ), - ) : Container(); - }, - ); - } - Widget buildImage() { Size size = MediaQuery.of(context).size; @@ -168,8 +131,8 @@ class _DetailPageState extends State { image: NetworkImage(detailController.character.image), ), ), - ) : const Center( - child: CircularProgressIndicator(), + ) : const SkeletonAvatar( + style: SkeletonAvatarStyle(), ), ), ); @@ -178,126 +141,63 @@ class _DetailPageState extends State { } Widget buildTitle() { - Size size = MediaQuery.of(context).size; - return Observer( builder: (_) { return SliverToBoxAdapter( - child: Container( - padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16), - width: size.width, - child: detailController.hasCharacter ? Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - detailController.character.name, - style: const TextStyle( - color: Colors.black87, - fontSize: 18, - fontWeight: FontWeight.bold - ), - ), - Text( - DateFormat.yMd().format(detailController.character.created), - style: const TextStyle( - fontSize: 14, - color: Colors.grey, - ), + child: SkeletonListTileWidget( + isLoading: !detailController.hasCharacter, + child: detailController.hasCharacter ? Container( + decoration: BoxDecoration( + border: Border( + bottom: BorderSide(width: 1, color: Colors.grey.shade200) ) - ], - ) - : const Center(), - ) + ), + child: ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + title: Text(detailController.character.name, style: const TextStyle(fontWeight: FontWeight.w700),), + subtitle: Text(DateFormat.yMd().format(detailController.character.created)), + ), + ) : Container(), + ), ); } ); } Widget buildInfo() { - Size size = MediaQuery.of(context).size; - - return Observer( - builder: (_) { - return detailController.hasCharacter - ? Container( - padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 10), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - SizedBox( - width: size.width, - child: const Text( - 'Inforamções', - style: TextStyle( - color: Colors.black87, - fontWeight: FontWeight.bold, - fontSize: 16 - ), - ), - ), - SizedBox( - width: size.width, - child: Wrap( - children: [ - GenereicLabelWidget(label: detailController.character.status), - GenereicLabelWidget(label: detailController.character.species), - GenereicLabelWidget(label: detailController.character.gender), - ], - ), - ) - ], - ), - ) - : const Center(); - }, - ); - } - - Widget buildOriginLocation() { return Observer( builder: (_) { - return detailController.hasCharacter ? Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - title: const Text( - 'Origin', - style: TextStyle( - color: Colors.black87, - fontWeight: FontWeight.bold, - fontSize: 16 + return SkeletonListWidget( + itemCount: 3, + hasLeading: false, + isLoading: !detailController.hasCharacter, + child: detailController.hasCharacter ? ListView( + children: [ + Padding( + padding: const EdgeInsets.only( + left: 24, right: 24, bottom: 16 ), - ), - subtitle: Text( - detailController.character.origin.name, - textAlign: TextAlign.justify, - style: const TextStyle( - color: Colors.grey, + child: Wrap( + children: [ + GenereicLabelWidget(label: detailController.character.status), + GenereicLabelWidget(label: detailController.character.species), + GenereicLabelWidget(label: detailController.character.gender), + ], ), ), - ), - ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - title: const Text( - 'Location', - style: TextStyle( - color: Colors.black87, - fontWeight: FontWeight.bold, - fontSize: 16 - ), + ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + title: const Text('Origin', style: TextStyle(fontWeight: FontWeight.w700),), + subtitle: Text(detailController.character.origin.name), ), - subtitle: Text( - detailController.character.location.name, - textAlign: TextAlign.justify, - style: const TextStyle( - color: Colors.grey, - ), + ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + title: const Text('Location', style: TextStyle(fontWeight: FontWeight.w700),), + subtitle: Text(detailController.character.location.name), ), - ), - ], - ) - : const Center(); + ], + ) : Container(), + ); }, ); } @@ -305,31 +205,24 @@ class _DetailPageState extends State { Widget buildCharacterEpisodes() { return Observer( builder: (_) { - return ListView( - children: detailController.episodes.map((item) { - return ListTile( - leading: CircleAvatar( - backgroundImage: const AssetImage('assets/images/rickandmortyapi.jpg'), - backgroundColor: Colors.grey[300] - ), - title: Text( - item.episode, - style: const TextStyle( - color: Colors.black87, - fontWeight: FontWeight.bold, - fontSize: 16 + return SkeletonListWidget( + itemCount: 10, + isLoading: !detailController.hasEpisodes, + child: ListView.builder( + itemCount: detailController.episodes.length, + itemBuilder: (context, index) { + return ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 0), + leading: CircleAvatar( + backgroundImage: const AssetImage(Assets.imgRickMorty), + backgroundColor: Colors.grey[300] ), - ), - subtitle: Text( - item.name, - textAlign: TextAlign.justify, - style: const TextStyle( - color: Colors.grey, - ), - ), - onTap: () => Modular.to.pushNamed('/episode/${item.id}'), - ); - }).toList(), + title: Text(detailController.episodes[index].episode, style: const TextStyle(fontWeight: FontWeight.w700),), + subtitle: Text(detailController.episodes[index].name), + onTap: () => Modular.to.pushNamed('/episode/${detailController.episodes[index].id}'), + ); + }, + ) ); }, ); diff --git a/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart b/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart index 5672c68..14da6c7 100644 --- a/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart +++ b/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart @@ -32,57 +32,16 @@ class _FavoritesPageState extends State { Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, - appBar: buildAppBar(), - body: buildBody(), - ); - } - - AppBar buildAppBar() { - return AppBar( - elevation: 0, - backgroundColor: Colors.white, - leading: IconButton( - icon: const Icon( - Icons.arrow_back_outlined, - color: Colors.black87, - ), - onPressed: () => Modular.to.pop(), - ), - centerTitle: true, - title: const Text('Favoritos', style: TextStyle(color: Colors.black87, fontSize: 16),), - bottom: AppBar( - elevation: 0, - automaticallyImplyLeading: false, - backgroundColor: Colors.white, - title: SizedBox( - height: 42, - child: TextField( - controller: searchValueController, - cursorColor: Colors.grey, - decoration: InputDecoration( - contentPadding: const EdgeInsets.all(0), - fillColor: Colors.grey[100], - filled: true, - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), - borderSide: BorderSide.none - ), - hintText: 'Buscar personagens', - hintStyle: const TextStyle( - color: Colors.grey, - fontSize: 16 - ), - prefixIcon: Container( - padding: const EdgeInsets.symmetric(horizontal: 16), - width: 18, - child: const Icon(Icons.search), - ) - ), - onChanged: ((value) => favoriteController.getFilteredToFavorite(value)), - textInputAction: TextInputAction.search, - ), - ), + appBar: AppBarWidget( + title: 'Favoritos', + centerTitle: true, + searchHintText: 'Buscar personagens', + searchController: searchValueController, + textInputAction: TextInputAction.search, + onChanged: ((value) => favoriteController.getFilteredToFavorite(value)), + onPressedLeadingIcon: () => Modular.to.pop(), ), + body: buildBody(), ); } @@ -106,25 +65,29 @@ class _FavoritesPageState extends State { ); } - return favoriteController.hasFavorites ? ListView.builder( - itemCount: favoriteController.favorites.length, - itemBuilder: (context, index) { - return ListTile( - leading: CircleAvatar( - backgroundImage: NetworkImage(favoriteController.favorites[index].image), - backgroundColor: Colors.grey[300] - ), - title: Text(favoriteController.favorites[index].name), - subtitle: Text(favoriteController.favorites[index].species), - onTap: () { - Modular.to.pushNamed('/character/${favoriteController.favorites[index].id}') - .then((value) => favoriteController.getFavorites()); + return SkeletonListWidget( + itemCount: 10, + isLoading: !favoriteController.hasFavorites, + child: ListView.builder( + itemCount: favoriteController.favorites.length, + itemBuilder: (context, index) { + return ListTile( + leading: CircleAvatar( + backgroundImage: NetworkImage(favoriteController.favorites[index].image), + backgroundColor: Colors.grey[300] + ), + title: Text(favoriteController.favorites[index].name), + subtitle: Text(favoriteController.favorites[index].species), + onTap: () { + Modular.to.pushNamed('/character/${favoriteController.favorites[index].id}') + .then((value) => favoriteController.getFavorites()); - searchValueController.clear(); - }, - ); - }, - ) : const Center(child: CircularProgressIndicator(),); + searchValueController.clear(); + }, + ); + }, + ) + ); }, ); } diff --git a/libs/flutter/characters/lib/src/pages/search/search_page.dart b/libs/flutter/characters/lib/src/pages/search/search_page.dart index bdf1ae0..e59c171 100644 --- a/libs/flutter/characters/lib/src/pages/search/search_page.dart +++ b/libs/flutter/characters/lib/src/pages/search/search_page.dart @@ -34,62 +34,21 @@ class _SearchPageState extends State { Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, - appBar: buildAppBar(), + appBar: AppBarWidget( + title: 'Busca', + centerTitle: true, + searchHintText: 'Buscar personagens', + searchController: searchValueController, + textInputAction: TextInputAction.search, + onSubmitted: (value) => searchController.getFilteredCharacters(value), + onPressedLeadingIcon: () => Modular.to.pop(), + ), body: SafeArea( child: buildList(), ), ); } - AppBar buildAppBar() { - return AppBar( - elevation: 0, - backgroundColor: Colors.white, - leading: IconButton( - icon: const Icon( - Icons.arrow_back_outlined, - color: Colors.black87, - ), - onPressed: () => Modular.to.pop(), - ), - centerTitle: true, - title: const Text('Busca', style: TextStyle(color: Colors.black87, fontSize: 16),), - bottom: AppBar( - elevation: 0, - automaticallyImplyLeading: false, - backgroundColor: Colors.white, - title: SizedBox( - height: 42, - child: TextField( - controller: searchValueController, - cursorColor: Colors.grey, - decoration: InputDecoration( - contentPadding: const EdgeInsets.all(0), - fillColor: Colors.grey[100], - filled: true, - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(12), - borderSide: BorderSide.none - ), - hintText: 'Buscar personagens', - hintStyle: const TextStyle( - color: Colors.grey, - fontSize: 16 - ), - prefixIcon: Container( - padding: const EdgeInsets.symmetric(horizontal: 16), - width: 18, - child: const Icon(Icons.search), - ) - ), - onSubmitted: (value) => searchController.getFilteredCharacters(value), - textInputAction: TextInputAction.search, - ), - ), - ), - ); - } - Widget buildList() { return Observer( builder: (_) { @@ -100,20 +59,24 @@ class _SearchPageState extends State { ); } - return searchController.hasCharacters ? ListView.builder( - itemCount: searchController.characters.length, - itemBuilder: (context, index) { - return ListTile( - leading: CircleAvatar( - backgroundImage: NetworkImage(searchController.characters[index].image), - backgroundColor: Colors.grey[300] - ), - title: Text(searchController.characters[index].name), - subtitle: Text(searchController.characters[index].species), - onTap: () => Modular.to.pushNamed('/character/${searchController.characters[index].id}'), - ); - }, - ) : const Center(child: CircularProgressIndicator(),); + return SkeletonListWidget( + itemCount: 10, + isLoading: !searchController.hasCharacters, + child: ListView.builder( + itemCount: searchController.characters.length, + itemBuilder: (context, index) { + return ListTile( + leading: CircleAvatar( + backgroundImage: NetworkImage(searchController.characters[index].image), + backgroundColor: Colors.grey[300] + ), + title: Text(searchController.characters[index].name), + subtitle: Text(searchController.characters[index].species), + onTap: () => Modular.to.pushNamed('/character/${searchController.characters[index].id}'), + ); + }, + ), + ); }, ); } diff --git a/libs/flutter/characters/pubspec.yaml b/libs/flutter/characters/pubspec.yaml index 8feeeb1..4a15e2f 100644 --- a/libs/flutter/characters/pubspec.yaml +++ b/libs/flutter/characters/pubspec.yaml @@ -15,6 +15,7 @@ dependencies: flutter_mobx: ^2.0.6+4 mobx: ^2.1.1 intl: ^0.17.0 + skeletons: ^0.0.3 flutter_api: path: ../api flutter_shared: From e969943fe27466f03bd96ac1f95b4c0e195e8757 Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 18:16:48 -0300 Subject: [PATCH 08/13] feat(episodes): update layout --- .../episodes/.flutter-plugins-dependencies | 2 +- .../episodes/lib/src/episodes_page.dart | 179 +++++++----------- libs/flutter/episodes/pubspec.yaml | 3 + 3 files changed, 73 insertions(+), 111 deletions(-) diff --git a/libs/flutter/episodes/.flutter-plugins-dependencies b/libs/flutter/episodes/.flutter-plugins-dependencies index 5c180f9..734529b 100644 --- a/libs/flutter/episodes/.flutter-plugins-dependencies +++ b/libs/flutter/episodes/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_ios-2.1.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_android-2.0.14\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-2.0.4\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.7\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-2.1.1\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.1.3\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-2.1.1\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-2.0.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-10-22 04:16:19.986117","version":"3.0.5"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_ios-2.1.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"shared_preferences_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_android-2.0.14\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-2.0.4\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.7\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_linux-2.1.1\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.1.3\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_windows-2.1.1\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-2.0.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-10-22 09:40:52.822768","version":"3.0.5"} \ No newline at end of file diff --git a/libs/flutter/episodes/lib/src/episodes_page.dart b/libs/flutter/episodes/lib/src/episodes_page.dart index d1b5edc..d863e8c 100644 --- a/libs/flutter/episodes/lib/src/episodes_page.dart +++ b/libs/flutter/episodes/lib/src/episodes_page.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_episodes/src/episodes_controller.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_modular/flutter_modular.dart'; +import 'package:flutter_shared/flutter_shared.dart'; import 'package:intl/intl.dart'; class EpisodesPage extends StatefulWidget { @@ -43,7 +44,12 @@ class _EpisodesPageState extends State { length: 2, child: Scaffold( backgroundColor: Colors.white, - appBar: buildAppBar(), + appBar: AppBarWidget( + title: 'Episódio', + centerTitle: true, + showSearch: false, + onPressedLeadingIcon: () => Modular.to.pop(), + ), body: SafeArea( child: NestedScrollView( headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { @@ -52,19 +58,20 @@ class _EpisodesPageState extends State { buildTitle(), const SliverToBoxAdapter( child: TabBar( - indicator: BoxDecoration( - border: Border( - top: BorderSide(color: Colors.red, width: 3), + padding: EdgeInsets.symmetric(horizontal: 8), + indicator: BoxDecoration( + border: Border( + top: BorderSide(color: Colors.red, width: 3), + ), ), + isScrollable: true, + labelColor: Colors.red, + unselectedLabelColor: Colors.grey, + tabs: [ + Tab(child: Text('Informações')), + Tab(child: Text('Personagens')), + ], ), - isScrollable: true, - labelColor: Colors.red, - unselectedLabelColor: Colors.grey, - tabs: [ - Tab(child: Text('Informações')), - Tab(child: Text('Personagens')), - ], - ), ), ]; }, @@ -80,22 +87,6 @@ class _EpisodesPageState extends State { ); } - AppBar buildAppBar() { - return AppBar( - elevation: 0, - backgroundColor: Colors.white, - leading: IconButton( - icon: const Icon( - Icons.arrow_back_outlined, - color: Colors.black87, - ), - onPressed: () => Modular.to.pop(), - ), - centerTitle: true, - title: const Text('Episódio', style: TextStyle(color: Colors.black87, fontSize: 16),), - ); - } - Widget buildImage() { Size size = MediaQuery.of(context).size; @@ -109,7 +100,6 @@ class _EpisodesPageState extends State { width: size.width, decoration: const BoxDecoration( image: DecorationImage( - fit: BoxFit.cover, image: AssetImage('assets/images/rickandmortyapi.jpg'), ), ), @@ -119,36 +109,24 @@ class _EpisodesPageState extends State { } Widget buildTitle() { - Size size = MediaQuery.of(context).size; - return Observer( builder: (_) { return SliverToBoxAdapter( - child: Container( - padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16), - width: size.width, - child: episodesController.hasEpisode ? Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - episodesController.episode.name, - style: const TextStyle( - color: Colors.black87, - fontSize: 18, - fontWeight: FontWeight.bold - ), - ), - Text( - DateFormat.yMd().format(episodesController.episode.created), - style: const TextStyle( - fontSize: 14, - color: Colors.grey, - ), + child: SkeletonListTileWidget( + isLoading: !episodesController.hasEpisode, + child: episodesController.hasEpisode ? Container( + decoration: BoxDecoration( + border: Border( + bottom: BorderSide(width: 1, color: Colors.grey.shade200) ) - ], - ) - : const Center(), - ) + ), + child: ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + title: Text(episodesController.episode.name, style: const TextStyle(fontWeight: FontWeight.w700),), + subtitle: Text(DateFormat.yMd().format(episodesController.episode.created)), + ), + ) : Container(), + ), ); } ); @@ -157,49 +135,25 @@ class _EpisodesPageState extends State { Widget buildInfo() { return Observer( builder: (_) { - return episodesController.hasEpisode - ? Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - title: const Text( - 'Episódio', - style: TextStyle( - color: Colors.black87, - fontWeight: FontWeight.bold, - fontSize: 16 - ), - ), - subtitle: Text( - episodesController.episode.episode, - textAlign: TextAlign.justify, - style: const TextStyle( - color: Colors.grey, - ), - ), - ), - ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - title: const Text( - 'Data do AR', - style: TextStyle( - color: Colors.black87, - fontWeight: FontWeight.bold, - fontSize: 16 - ), + return SkeletonListWidget( + itemCount: 3, + hasLeading: false, + isLoading: !episodesController.hasEpisode, + child: episodesController.hasEpisode ? ListView( + children: [ + ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + title: Text(episodesController.episode.episode, style: const TextStyle(fontWeight: FontWeight.w700),), + subtitle: const Text('Episódio'), ), - subtitle: Text( - episodesController.episode.airDate, - textAlign: TextAlign.justify, - style: const TextStyle( - color: Colors.grey, - ), - ), - ), - ], - ) - : const Center(); + ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + title: Text(episodesController.episode.airDate, style: const TextStyle(fontWeight: FontWeight.w700),), + subtitle: const Text('Data do AR'), + ) + ], + ) : Container(), + ); }, ); } @@ -207,19 +161,24 @@ class _EpisodesPageState extends State { Widget buildCharacterEpisodes() { return Observer( builder: (_) { - return ListView.builder( - itemCount: episodesController.characters.length, - itemBuilder: (context, index) { - return ListTile( - leading: CircleAvatar( - backgroundImage: NetworkImage(episodesController.characters[index].image), - backgroundColor: Colors.grey[300] - ), - title: Text(episodesController.characters[index].name), - subtitle: Text(episodesController.characters[index].species), - onTap: () => Modular.to.pushNamed('/character/${episodesController.characters[index].id}'), - ); - }, + return SkeletonListWidget( + itemCount: 10, + isLoading: !episodesController.hasCharacters, + child: ListView.builder( + itemCount: episodesController.characters.length, + itemBuilder: (context, index) { + return ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + leading: CircleAvatar( + backgroundImage: NetworkImage(episodesController.characters[index].image), + backgroundColor: Colors.grey[300] + ), + title: Text(episodesController.characters[index].name, style: const TextStyle(fontWeight: FontWeight.w700),), + subtitle: Text(episodesController.characters[index].species), + onTap: () => Modular.to.pushNamed('/character/${episodesController.characters[index].id}'), + ); + }, + ) ); }, ); diff --git a/libs/flutter/episodes/pubspec.yaml b/libs/flutter/episodes/pubspec.yaml index 3a49ee8..8e4395e 100644 --- a/libs/flutter/episodes/pubspec.yaml +++ b/libs/flutter/episodes/pubspec.yaml @@ -14,8 +14,11 @@ dependencies: flutter_mobx: ^2.0.6+4 mobx: ^2.1.1 intl: ^0.17.0 + skeletons: ^0.0.3 flutter_api: path: ../api + flutter_shared: + path: ../shared dev_dependencies: flutter_test: From 80768b07409072d5bb8deeb59deacb4b7c5d5f13 Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 18:51:32 -0300 Subject: [PATCH 09/13] feat(shared): create widget ListTile --- libs/flutter/shared/lib/flutter_shared.dart | 1 + .../lib/src/widgets/list_tile_widget.dart | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 libs/flutter/shared/lib/src/widgets/list_tile_widget.dart diff --git a/libs/flutter/shared/lib/flutter_shared.dart b/libs/flutter/shared/lib/flutter_shared.dart index 07e6051..9469b51 100644 --- a/libs/flutter/shared/lib/flutter_shared.dart +++ b/libs/flutter/shared/lib/flutter_shared.dart @@ -4,6 +4,7 @@ export './src/widgets/appbar_widget.dart'; export './src/widgets/choice_chip_widget.dart'; export './src/widgets/feedback_page_widget.dart'; export './src/widgets/generic_label_widget.dart'; +export './src/widgets/list_tile_widget.dart'; export './src/widgets/skeleton_widget.dart'; export './src/widgets/skeleton_list_widget.dart'; export './src/widgets/skeleton_list_tile_widget.dart'; diff --git a/libs/flutter/shared/lib/src/widgets/list_tile_widget.dart b/libs/flutter/shared/lib/src/widgets/list_tile_widget.dart new file mode 100644 index 0000000..aaedffd --- /dev/null +++ b/libs/flutter/shared/lib/src/widgets/list_tile_widget.dart @@ -0,0 +1,34 @@ +import 'package:flutter/material.dart'; + +class ListTileWidget extends StatelessWidget { + final ImageProvider? backgroundImage; + final String title; + final String subtitle; + final bool hasLeading; + final bool enabled; + final GestureTapCallback? onTap; + + const ListTileWidget({ + Key? key, + this.backgroundImage, + required this.title, + required this.subtitle, + this.hasLeading = true, + this.enabled = true, + this.onTap + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + leading: hasLeading ? CircleAvatar( + backgroundImage: backgroundImage, + backgroundColor: Colors.grey[300] + ) : null, + title: Text(title, style: const TextStyle(fontWeight: FontWeight.w700, color: Colors.black87),), + subtitle: Text(subtitle), + onTap: enabled ? () => onTap!() : null, + ); + } +} \ No newline at end of file From a4cbbc02e4530d4f0bb70c34639321e3fec4b73f Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 18:52:42 -0300 Subject: [PATCH 10/13] refactor(characters): implement widget ListTile --- .../characters/lib/src/characters_page.dart | 11 ++---- .../lib/src/pages/detail/detail_page.dart | 39 +++++++++---------- .../src/pages/favorites/favorites_page.dart | 11 ++---- .../lib/src/pages/search/search_page.dart | 11 ++---- 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/libs/flutter/characters/lib/src/characters_page.dart b/libs/flutter/characters/lib/src/characters_page.dart index ecbf9f3..1f952d6 100644 --- a/libs/flutter/characters/lib/src/characters_page.dart +++ b/libs/flutter/characters/lib/src/characters_page.dart @@ -82,13 +82,10 @@ class _CharactersPageState extends State { child: ListView.builder( itemCount: charactersController.characters.length, itemBuilder: (context, index) { - return ListTile( - leading: CircleAvatar( - backgroundImage: NetworkImage(charactersController.characters[index].image), - backgroundColor: Colors.grey[300] - ), - title: Text(charactersController.characters[index].name), - subtitle: Text(charactersController.characters[index].species), + return ListTileWidget( + title: charactersController.characters[index].name, + subtitle: charactersController.characters[index].species, + backgroundImage: NetworkImage(charactersController.characters[index].image), onTap: () => Modular.to.pushNamed('/character/${charactersController.characters[index].id}'), ); }, diff --git a/libs/flutter/characters/lib/src/pages/detail/detail_page.dart b/libs/flutter/characters/lib/src/pages/detail/detail_page.dart index 337a460..f935450 100644 --- a/libs/flutter/characters/lib/src/pages/detail/detail_page.dart +++ b/libs/flutter/characters/lib/src/pages/detail/detail_page.dart @@ -152,10 +152,11 @@ class _DetailPageState extends State { bottom: BorderSide(width: 1, color: Colors.grey.shade200) ) ), - child: ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - title: Text(detailController.character.name, style: const TextStyle(fontWeight: FontWeight.w700),), - subtitle: Text(DateFormat.yMd().format(detailController.character.created)), + child: ListTileWidget( + enabled: false, + hasLeading: false, + title: detailController.character.name, + subtitle: DateFormat.yMd().format(detailController.character.created), ), ) : Container(), ), @@ -185,15 +186,17 @@ class _DetailPageState extends State { ], ), ), - ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - title: const Text('Origin', style: TextStyle(fontWeight: FontWeight.w700),), - subtitle: Text(detailController.character.origin.name), + ListTileWidget( + enabled: false, + hasLeading: false, + title: 'Origin', + subtitle: detailController.character.origin.name, ), - ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - title: const Text('Location', style: TextStyle(fontWeight: FontWeight.w700),), - subtitle: Text(detailController.character.location.name), + ListTileWidget( + enabled: false, + hasLeading: false, + title: 'Location', + subtitle: detailController.character.location.name, ), ], ) : Container(), @@ -211,14 +214,10 @@ class _DetailPageState extends State { child: ListView.builder( itemCount: detailController.episodes.length, itemBuilder: (context, index) { - return ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 0), - leading: CircleAvatar( - backgroundImage: const AssetImage(Assets.imgRickMorty), - backgroundColor: Colors.grey[300] - ), - title: Text(detailController.episodes[index].episode, style: const TextStyle(fontWeight: FontWeight.w700),), - subtitle: Text(detailController.episodes[index].name), + return ListTileWidget( + title: detailController.episodes[index].episode, + subtitle: detailController.episodes[index].name, + backgroundImage: const AssetImage(Assets.imgRickMorty), onTap: () => Modular.to.pushNamed('/episode/${detailController.episodes[index].id}'), ); }, diff --git a/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart b/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart index 14da6c7..5a7c5a7 100644 --- a/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart +++ b/libs/flutter/characters/lib/src/pages/favorites/favorites_page.dart @@ -71,13 +71,10 @@ class _FavoritesPageState extends State { child: ListView.builder( itemCount: favoriteController.favorites.length, itemBuilder: (context, index) { - return ListTile( - leading: CircleAvatar( - backgroundImage: NetworkImage(favoriteController.favorites[index].image), - backgroundColor: Colors.grey[300] - ), - title: Text(favoriteController.favorites[index].name), - subtitle: Text(favoriteController.favorites[index].species), + return ListTileWidget( + title: favoriteController.favorites[index].name, + subtitle: favoriteController.favorites[index].species, + backgroundImage: NetworkImage(favoriteController.favorites[index].image), onTap: () { Modular.to.pushNamed('/character/${favoriteController.favorites[index].id}') .then((value) => favoriteController.getFavorites()); diff --git a/libs/flutter/characters/lib/src/pages/search/search_page.dart b/libs/flutter/characters/lib/src/pages/search/search_page.dart index e59c171..48dd585 100644 --- a/libs/flutter/characters/lib/src/pages/search/search_page.dart +++ b/libs/flutter/characters/lib/src/pages/search/search_page.dart @@ -65,13 +65,10 @@ class _SearchPageState extends State { child: ListView.builder( itemCount: searchController.characters.length, itemBuilder: (context, index) { - return ListTile( - leading: CircleAvatar( - backgroundImage: NetworkImage(searchController.characters[index].image), - backgroundColor: Colors.grey[300] - ), - title: Text(searchController.characters[index].name), - subtitle: Text(searchController.characters[index].species), + return ListTileWidget( + title: searchController.characters[index].name, + subtitle: searchController.characters[index].species, + backgroundImage: NetworkImage(searchController.characters[index].image), onTap: () => Modular.to.pushNamed('/character/${searchController.characters[index].id}'), ); }, From 25cf191e8769c889d94bdb087a7d7bbb32323a6c Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 18:52:55 -0300 Subject: [PATCH 11/13] refactor(episode): implement widget ListTile --- .../episodes/lib/src/episodes_page.dart | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/libs/flutter/episodes/lib/src/episodes_page.dart b/libs/flutter/episodes/lib/src/episodes_page.dart index d863e8c..ceb21fb 100644 --- a/libs/flutter/episodes/lib/src/episodes_page.dart +++ b/libs/flutter/episodes/lib/src/episodes_page.dart @@ -120,10 +120,11 @@ class _EpisodesPageState extends State { bottom: BorderSide(width: 1, color: Colors.grey.shade200) ) ), - child: ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - title: Text(episodesController.episode.name, style: const TextStyle(fontWeight: FontWeight.w700),), - subtitle: Text(DateFormat.yMd().format(episodesController.episode.created)), + child: ListTileWidget( + enabled: false, + hasLeading: false, + title: episodesController.episode.name, + subtitle: DateFormat.yMd().format(episodesController.episode.created), ), ) : Container(), ), @@ -141,16 +142,18 @@ class _EpisodesPageState extends State { isLoading: !episodesController.hasEpisode, child: episodesController.hasEpisode ? ListView( children: [ - ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - title: Text(episodesController.episode.episode, style: const TextStyle(fontWeight: FontWeight.w700),), - subtitle: const Text('Episódio'), + ListTileWidget( + enabled: false, + hasLeading: false, + title: episodesController.episode.episode, + subtitle: 'Episódio', + ), + ListTileWidget( + enabled: false, + hasLeading: false, + title: episodesController.episode.airDate, + subtitle: 'Data do AR', ), - ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - title: Text(episodesController.episode.airDate, style: const TextStyle(fontWeight: FontWeight.w700),), - subtitle: const Text('Data do AR'), - ) ], ) : Container(), ); @@ -167,14 +170,10 @@ class _EpisodesPageState extends State { child: ListView.builder( itemCount: episodesController.characters.length, itemBuilder: (context, index) { - return ListTile( - contentPadding: const EdgeInsets.symmetric(horizontal: 24), - leading: CircleAvatar( - backgroundImage: NetworkImage(episodesController.characters[index].image), - backgroundColor: Colors.grey[300] - ), - title: Text(episodesController.characters[index].name, style: const TextStyle(fontWeight: FontWeight.w700),), - subtitle: Text(episodesController.characters[index].species), + return ListTileWidget( + title: episodesController.characters[index].name, + subtitle: episodesController.characters[index].species, + backgroundImage: NetworkImage(episodesController.characters[index].image), onTap: () => Modular.to.pushNamed('/character/${episodesController.characters[index].id}'), ); }, From 7e9658d975cfe5af26c6807450f1df4d7cc91a37 Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 20:22:13 -0300 Subject: [PATCH 12/13] refactor(shared): update widget FeedbackPage --- .../lib/src/widgets/feedback_page_widget.dart | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/libs/flutter/shared/lib/src/widgets/feedback_page_widget.dart b/libs/flutter/shared/lib/src/widgets/feedback_page_widget.dart index 2ae72e5..2cd54c1 100644 --- a/libs/flutter/shared/lib/src/widgets/feedback_page_widget.dart +++ b/libs/flutter/shared/lib/src/widgets/feedback_page_widget.dart @@ -4,8 +4,20 @@ import 'package:flutter_svg/flutter_svg.dart'; class FeedbackPageWidget extends StatelessWidget { final String illustration; final String message; + final String? description; + final String? textButton; + final bool enabledAction; + final VoidCallback? onPressed; - const FeedbackPageWidget({Key? key, required this.message, required this.illustration}) : super(key: key); + const FeedbackPageWidget({ + Key? key, + required this.message, + required this.illustration, + this.description, + this.onPressed, + this.enabledAction = false, + this.textButton + }) : super(key: key); @override Widget build(BuildContext context) { @@ -28,7 +40,21 @@ class FeedbackPageWidget extends StatelessWidget { fontSize: 18, fontWeight: FontWeight.w700, ), - ) + ), + description != null ? Padding( + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 6), + child: Text( + description!, + textAlign: TextAlign.center, + style: const TextStyle( + fontSize: 14, + ), + ), + ) : Container(), + enabledAction ? TextButton( + onPressed: () => onPressed!(), + child: Text(textButton!, style: const TextStyle(color: Colors.red),) + ) : Container(), ], ), ), From 34b206db4c6a5647b6f83673f3772d82164690fc Mon Sep 17 00:00:00 2001 From: Leandro Mancini Date: Sat, 22 Oct 2022 20:37:42 -0300 Subject: [PATCH 13/13] feat(characters): update search global --- .../lib/src/characters_controller.dart | 27 ++++++++++- .../lib/src/characters_controller.g.dart | 46 ++++++++++++++++++- .../characters/lib/src/characters_page.dart | 20 ++++++-- .../src/pages/search/search_controller.dart | 26 ++++++++++- .../src/pages/search/search_controller.g.dart | 46 ++++++++++++++++++- .../lib/src/pages/search/search_page.dart | 1 + 6 files changed, 156 insertions(+), 10 deletions(-) diff --git a/libs/flutter/characters/lib/src/characters_controller.dart b/libs/flutter/characters/lib/src/characters_controller.dart index f43deed..1daa7db 100644 --- a/libs/flutter/characters/lib/src/characters_controller.dart +++ b/libs/flutter/characters/lib/src/characters_controller.dart @@ -7,15 +7,22 @@ var characterService = CharacterService(); class CharactersController = CharactersControllerBase with _$CharactersController; abstract class CharactersControllerBase with Store { + @observable + List allCharacters = []; + @observable List characters = []; @observable bool hasCharacters = false; + @observable + bool hasFilterCharacters = false; + @action getAllCharacters() async { - characters = await characterService.getAllCharacters(); + allCharacters = await characterService.getAllCharacters(); + characters = allCharacters; hasCharacters = true; } @@ -23,8 +30,24 @@ abstract class CharactersControllerBase with Store { getFilteredCharacters(CharacterFilters filters) async { hasCharacters = false; - characters = await characterService.getFilteredCharacters(filters); + allCharacters = await characterService.getFilteredCharacters(filters); + characters = allCharacters; hasCharacters = true; } + + @action + getFilteredToCharacter(String value) async { + if (value.isEmpty) { + hasFilterCharacters = false; + characters = allCharacters; + } else { + List searchCharacter = allCharacters + .where((element) => element.name.toLowerCase().contains(value.toLowerCase())) + .toList(); + + hasFilterCharacters = true; + characters = searchCharacter; + } + } } \ No newline at end of file diff --git a/libs/flutter/characters/lib/src/characters_controller.g.dart b/libs/flutter/characters/lib/src/characters_controller.g.dart index a2e84ab..9dc0b1d 100644 --- a/libs/flutter/characters/lib/src/characters_controller.g.dart +++ b/libs/flutter/characters/lib/src/characters_controller.g.dart @@ -9,6 +9,22 @@ part of 'characters_controller.dart'; // ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic, no_leading_underscores_for_local_identifiers mixin _$CharactersController on CharactersControllerBase, Store { + late final _$allCharactersAtom = + Atom(name: 'CharactersControllerBase.allCharacters', context: context); + + @override + List get allCharacters { + _$allCharactersAtom.reportRead(); + return super.allCharacters; + } + + @override + set allCharacters(List value) { + _$allCharactersAtom.reportWrite(value, super.allCharacters, () { + super.allCharacters = value; + }); + } + late final _$charactersAtom = Atom(name: 'CharactersControllerBase.characters', context: context); @@ -41,6 +57,22 @@ mixin _$CharactersController on CharactersControllerBase, Store { }); } + late final _$hasFilterCharactersAtom = Atom( + name: 'CharactersControllerBase.hasFilterCharacters', context: context); + + @override + bool get hasFilterCharacters { + _$hasFilterCharactersAtom.reportRead(); + return super.hasFilterCharacters; + } + + @override + set hasFilterCharacters(bool value) { + _$hasFilterCharactersAtom.reportWrite(value, super.hasFilterCharacters, () { + super.hasFilterCharacters = value; + }); + } + late final _$getAllCharactersAsyncAction = AsyncAction( 'CharactersControllerBase.getAllCharacters', context: context); @@ -60,11 +92,23 @@ mixin _$CharactersController on CharactersControllerBase, Store { .run(() => super.getFilteredCharacters(filters)); } + late final _$getFilteredToCharacterAsyncAction = AsyncAction( + 'CharactersControllerBase.getFilteredToCharacter', + context: context); + + @override + Future getFilteredToCharacter(String value) { + return _$getFilteredToCharacterAsyncAction + .run(() => super.getFilteredToCharacter(value)); + } + @override String toString() { return ''' +allCharacters: ${allCharacters}, characters: ${characters}, -hasCharacters: ${hasCharacters} +hasCharacters: ${hasCharacters}, +hasFilterCharacters: ${hasFilterCharacters} '''; } } diff --git a/libs/flutter/characters/lib/src/characters_page.dart b/libs/flutter/characters/lib/src/characters_page.dart index 1f952d6..0e88806 100644 --- a/libs/flutter/characters/lib/src/characters_page.dart +++ b/libs/flutter/characters/lib/src/characters_page.dart @@ -40,9 +40,11 @@ class _CharactersPageState extends State { searchController: searchValueController, textInputAction: TextInputAction.search, onSubmitted: (value) { - Modular.to.pushNamed('/character/search/$value'); + Modular.to.pushNamed('/character/search/$value') + .then((value) => charactersController.getAllCharacters()); searchValueController.clear(); }, + onChanged: ((value) => charactersController.getFilteredToCharacter(value)), actions: [ IconButton( icon: const Icon( @@ -70,9 +72,19 @@ class _CharactersPageState extends State { return Observer( builder: (_) { if (charactersController.characters.isEmpty && charactersController.hasCharacters) { - return const FeedbackPageWidget( - illustration: Assets.ilSearch, - message: 'Desculpe, não conseguimos \n encontrar o personagem', + return SingleChildScrollView( + child: FeedbackPageWidget( + illustration: Assets.ilSearch, + message: 'Desculpe, não conseguimos \n encontrar o personagem', + description: 'Não se preocupe, ainda podemos \nbuscar no banco de dados.', + enabledAction: true, + textButton: 'Buscar', + onPressed: () { + Modular.to.pushNamed('/character/search/${searchValueController.text}') + .then((value) => charactersController.getAllCharacters()); + searchValueController.clear(); + }, + ), ); } diff --git a/libs/flutter/characters/lib/src/pages/search/search_controller.dart b/libs/flutter/characters/lib/src/pages/search/search_controller.dart index 0ac88b3..acb69d9 100644 --- a/libs/flutter/characters/lib/src/pages/search/search_controller.dart +++ b/libs/flutter/characters/lib/src/pages/search/search_controller.dart @@ -7,16 +7,38 @@ var characterService = CharacterService(); class SearchController = SearchControllerBase with _$SearchController; abstract class SearchControllerBase with Store { + @observable + List allCharacters = []; + @observable List characters = []; @observable bool hasCharacters = false; + @observable + bool hasFilterCharacters = false; + @action getFilteredCharacters(String name) async { - characters = await characterService.getFilteredCharacters(CharacterFilters(name: name)); - hasCharacters = true; + allCharacters = await characterService.getFilteredCharacters(CharacterFilters(name: name)); + characters = allCharacters; + hasCharacters = true; + } + + @action + getFilteredToSearchCharacter(String value) async { + if (value.isEmpty) { + hasFilterCharacters = false; + characters = allCharacters; + } else { + List searchCharacter = allCharacters + .where((element) => element.name.toLowerCase().contains(value.toLowerCase())) + .toList(); + + hasFilterCharacters = true; + characters = searchCharacter; + } } } \ No newline at end of file diff --git a/libs/flutter/characters/lib/src/pages/search/search_controller.g.dart b/libs/flutter/characters/lib/src/pages/search/search_controller.g.dart index fe326f4..186ee24 100644 --- a/libs/flutter/characters/lib/src/pages/search/search_controller.g.dart +++ b/libs/flutter/characters/lib/src/pages/search/search_controller.g.dart @@ -9,6 +9,22 @@ part of 'search_controller.dart'; // ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic, no_leading_underscores_for_local_identifiers mixin _$SearchController on SearchControllerBase, Store { + late final _$allCharactersAtom = + Atom(name: 'SearchControllerBase.allCharacters', context: context); + + @override + List get allCharacters { + _$allCharactersAtom.reportRead(); + return super.allCharacters; + } + + @override + set allCharacters(List value) { + _$allCharactersAtom.reportWrite(value, super.allCharacters, () { + super.allCharacters = value; + }); + } + late final _$charactersAtom = Atom(name: 'SearchControllerBase.characters', context: context); @@ -41,6 +57,22 @@ mixin _$SearchController on SearchControllerBase, Store { }); } + late final _$hasFilterCharactersAtom = + Atom(name: 'SearchControllerBase.hasFilterCharacters', context: context); + + @override + bool get hasFilterCharacters { + _$hasFilterCharactersAtom.reportRead(); + return super.hasFilterCharacters; + } + + @override + set hasFilterCharacters(bool value) { + _$hasFilterCharactersAtom.reportWrite(value, super.hasFilterCharacters, () { + super.hasFilterCharacters = value; + }); + } + late final _$getFilteredCharactersAsyncAction = AsyncAction( 'SearchControllerBase.getFilteredCharacters', context: context); @@ -51,11 +83,23 @@ mixin _$SearchController on SearchControllerBase, Store { .run(() => super.getFilteredCharacters(name)); } + late final _$getFilteredToSearchCharacterAsyncAction = AsyncAction( + 'SearchControllerBase.getFilteredToSearchCharacter', + context: context); + + @override + Future getFilteredToSearchCharacter(String value) { + return _$getFilteredToSearchCharacterAsyncAction + .run(() => super.getFilteredToSearchCharacter(value)); + } + @override String toString() { return ''' +allCharacters: ${allCharacters}, characters: ${characters}, -hasCharacters: ${hasCharacters} +hasCharacters: ${hasCharacters}, +hasFilterCharacters: ${hasFilterCharacters} '''; } } diff --git a/libs/flutter/characters/lib/src/pages/search/search_page.dart b/libs/flutter/characters/lib/src/pages/search/search_page.dart index 48dd585..532de5a 100644 --- a/libs/flutter/characters/lib/src/pages/search/search_page.dart +++ b/libs/flutter/characters/lib/src/pages/search/search_page.dart @@ -42,6 +42,7 @@ class _SearchPageState extends State { textInputAction: TextInputAction.search, onSubmitted: (value) => searchController.getFilteredCharacters(value), onPressedLeadingIcon: () => Modular.to.pop(), + onChanged: ((value) => searchController.getFilteredToSearchCharacter(value)), ), body: SafeArea( child: buildList(),