├── .github └── workflows │ └── unit.yml ├── .gitignore ├── .metadata ├── .vscode └── launch.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── example ├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android │ ├── .gitignore │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── kotlin │ │ │ │ └── br │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── MainActivity.kt │ │ │ └── res │ │ │ │ ├── drawable-v21 │ │ │ │ └── launch_background.xml │ │ │ │ ├── drawable │ │ │ │ └── launch_background.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── values-night │ │ │ │ └── styles.xml │ │ │ │ └── values │ │ │ │ └── styles.xml │ │ │ └── profile │ │ │ └── AndroidManifest.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ └── settings.gradle ├── example.md ├── ios │ ├── .gitignore │ ├── Flutter │ │ ├── .last_build_id │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ └── Release.xcconfig │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ ├── Icon-App-20x20@1x.png │ │ │ ├── Icon-App-20x20@2x.png │ │ │ ├── Icon-App-20x20@3x.png │ │ │ ├── Icon-App-29x29@1x.png │ │ │ ├── Icon-App-29x29@2x.png │ │ │ ├── Icon-App-29x29@3x.png │ │ │ ├── Icon-App-40x40@1x.png │ │ │ ├── Icon-App-40x40@2x.png │ │ │ ├── Icon-App-40x40@3x.png │ │ │ ├── Icon-App-60x60@2x.png │ │ │ ├── Icon-App-60x60@3x.png │ │ │ ├── Icon-App-76x76@1x.png │ │ │ ├── Icon-App-76x76@2x.png │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ └── LaunchImage.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ └── README.md │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── Runner-Bridging-Header.h ├── lib │ ├── counter │ │ ├── counter_cube.dart │ │ ├── counter_screen.dart │ │ └── counter_screen_animation.dart │ ├── counter_simple_cube │ │ ├── counter_simple_cube.dart │ │ └── counter_simple_cube_screen.dart │ ├── counter_singleton │ │ ├── counter_singleton_cube.dart │ │ ├── counter_singleton_widget.dart │ │ └── screen_counter_singleton.dart │ ├── feedback_manager │ │ ├── feedback_manager_cube.dart │ │ └── feedback_manager_screen.dart │ ├── main.dart │ ├── pokemon │ │ ├── pokemon_cube.dart │ │ ├── pokemon_screen.dart │ │ ├── repository │ │ │ ├── model │ │ │ │ └── pokemon.dart │ │ │ └── pokemon_repository.dart │ │ └── widgets │ │ │ └── pokemon_item_widget.dart │ ├── text_form_field │ │ ├── text_form_field_cube.dart │ │ └── text_form_field_screen.dart │ └── todo │ │ ├── todo_cube.dart │ │ ├── todo_list.dart │ │ └── todo_register.dart ├── linux │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ │ ├── CMakeLists.txt │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ ├── main.cc │ ├── my_application.cc │ └── my_application.h ├── macos │ ├── .gitignore │ ├── Flutter │ │ ├── Flutter-Debug.xcconfig │ │ ├── Flutter-Release.xcconfig │ │ ├── GeneratedPluginRegistrant.swift │ │ └── ephemeral │ │ │ ├── Flutter-Generated.xcconfig │ │ │ └── flutter_export_environment.sh │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── app_icon_1024.png │ │ │ ├── app_icon_128.png │ │ │ ├── app_icon_16.png │ │ │ ├── app_icon_256.png │ │ │ ├── app_icon_32.png │ │ │ ├── app_icon_512.png │ │ │ └── app_icon_64.png │ │ ├── Base.lproj │ │ └── MainMenu.xib │ │ ├── Configs │ │ ├── AppInfo.xcconfig │ │ ├── Debug.xcconfig │ │ ├── Release.xcconfig │ │ └── Warnings.xcconfig │ │ ├── DebugProfile.entitlements │ │ ├── Info.plist │ │ ├── MainFlutterWindow.swift │ │ └── Release.entitlements ├── pubspec.lock ├── pubspec.yaml ├── test │ ├── unit │ │ ├── counter_test.dart │ │ └── pokemon_test.dart │ ├── util │ │ └── robot.dart │ └── widget │ │ └── counter │ │ ├── counter_widget_robot.dart │ │ ├── counter_widget_test.dart │ │ ├── failures │ │ ├── counterScreen_isolatedDiff.png │ │ ├── counterScreen_maskedDiff.png │ │ ├── counterScreen_masterImage.png │ │ └── counterScreen_testImage.png │ │ └── golden_files │ │ └── counterScreen.png ├── web │ ├── favicon.png │ ├── icons │ │ ├── Icon-192.png │ │ ├── Icon-512.png │ │ ├── Icon-maskable-192.png │ │ └── Icon-maskable-512.png │ ├── index.html │ └── manifest.json └── windows │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake │ └── runner │ ├── CMakeLists.txt │ ├── Runner.rc │ ├── flutter_window.cpp │ ├── flutter_window.h │ ├── main.cpp │ ├── resource.h │ ├── resources │ └── app_icon.ico │ ├── runner.exe.manifest │ ├── utils.cpp │ ├── utils.h │ ├── win32_window.cpp │ └── win32_window.h ├── lib ├── cubes.dart └── src │ ├── actions │ ├── cube_action.dart │ └── navigation_cube_action.dart │ ├── cube.dart │ ├── feedback_manager │ ├── bottom_sheet_feedback_mixin.dart │ ├── dialog_feedback_mixin.dart │ ├── feedback_manager.dart │ └── snackbar_feedback_mixin.dart │ ├── injector │ ├── get_it_injector.dart │ └── injector.dart │ ├── observable │ ├── observable_list.dart │ └── observable_value.dart │ ├── util │ ├── cube_navigation_mixin.dart │ ├── cube_provider.dart │ ├── debouncer.dart │ ├── extensions │ │ ├── bool_extensions.dart │ │ ├── build_context_extensions.dart │ │ ├── ext.dart │ │ └── observable_value_extensions.dart │ ├── functions.dart │ └── state_mixin.dart │ └── widgets │ ├── animated_list_cube.dart │ ├── cube_consumer.dart │ ├── cube_widget.dart │ ├── observer.dart │ └── text_form_field.dart ├── media ├── example-folders.png └── icon.png ├── pubspec.lock ├── pubspec.yaml └── test ├── injector └── get_it_injector_test.dart ├── observable ├── observable_list_test.dart └── observable_value_test.dart └── widgets ├── cube_builder ├── cube_builder_robot.dart └── cube_builder_test.dart ├── cube_widget ├── cube_widget_robot.dart └── cube_widget_test.dart └── observer ├── observer_robot.dart └── observer_test.dart /.github/workflows/unit.yml: -------------------------------------------------------------------------------- 1 | name: unit-tests 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | jobs: 8 | test: 9 | runs-on: ${{ matrix.os }} 10 | strategy: 11 | matrix: 12 | os: [ubuntu-18.04] 13 | steps: 14 | # Set up Flutter and add it to the path. 15 | - name: Clone Flutter repository with stable channel 16 | uses: actions/checkout@v2 17 | with: 18 | repository: 'flutter/flutter' 19 | ref: 'stable' 20 | path: 'flutter' 21 | fetch-depth: 0 22 | - name: Add Flutter to the PATH for Unix 23 | run: echo "$GITHUB_WORKSPACE/flutter/bin" >> $GITHUB_PATH 24 | - name: Run Flutter doctor 25 | run: flutter doctor -v 26 | 27 | # Clone the Gallery repository under `code`, to avoid conflicts with `flutter`. 28 | - uses: actions/checkout@v2 29 | with: 30 | path: 'code' 31 | 32 | # Run the tests for the repository. 33 | - run: flutter pub get 34 | working-directory: code 35 | - run: flutter analyze 36 | working-directory: code 37 | - run: flutter format --set-exit-if-changed --dry-run . 38 | working-directory: code 39 | - run: flutter test 40 | working-directory: code 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | build/ 32 | 33 | # Android related 34 | **/android/**/gradle-wrapper.jar 35 | **/android/.gradle 36 | **/android/captures/ 37 | **/android/gradlew 38 | **/android/gradlew.bat 39 | **/android/local.properties 40 | **/android/**/GeneratedPluginRegistrant.java 41 | 42 | # iOS/XCode related 43 | **/ios/**/*.mode1v3 44 | **/ios/**/*.mode2v3 45 | **/ios/**/*.moved-aside 46 | **/ios/**/*.pbxuser 47 | **/ios/**/*.perspectivev3 48 | **/ios/**/*sync/ 49 | **/ios/**/.sconsign.dblite 50 | **/ios/**/.tags* 51 | **/ios/**/.vagrant/ 52 | **/ios/**/DerivedData/ 53 | **/ios/**/Icon? 54 | **/ios/**/Pods/ 55 | **/ios/**/.symlinks/ 56 | **/ios/**/profile 57 | **/ios/**/xcuserdata 58 | **/ios/.generated/ 59 | **/ios/Flutter/App.framework 60 | **/ios/Flutter/Flutter.framework 61 | **/ios/Flutter/Flutter.podspec 62 | **/ios/Flutter/Generated.xcconfig 63 | **/ios/Flutter/app.flx 64 | **/ios/Flutter/app.zip 65 | **/ios/Flutter/flutter_assets/ 66 | **/ios/Flutter/flutter_export_environment.sh 67 | **/ios/ServiceDefinitions.json 68 | **/ios/Runner/GeneratedPluginRegistrant.* 69 | 70 | # Exceptions to above rules. 71 | !**/ios/**/default.mode1v3 72 | !**/ios/**/default.mode2v3 73 | !**/ios/**/default.pbxuser 74 | !**/ios/**/default.perspectivev3 75 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 76 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 8af6b2f038c1172e61d418869363a28dffec3cb4 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "cube", 9 | "request": "launch", 10 | "type": "dart" 11 | }, 12 | { 13 | "name": "cube (profile mode)", 14 | "request": "launch", 15 | "type": "dart", 16 | "flutterMode": "profile" 17 | }, 18 | { 19 | "name": "cube (release mode)", 20 | "request": "launch", 21 | "type": "dart", 22 | "flutterMode": "release" 23 | }, 24 | { 25 | "name": "example", 26 | "cwd": "example", 27 | "request": "launch", 28 | "type": "dart" 29 | }, 30 | { 31 | "name": "example (profile mode)", 32 | "cwd": "example", 33 | "request": "launch", 34 | "type": "dart", 35 | "flutterMode": "profile" 36 | }, 37 | { 38 | "name": "example (release mode)", 39 | "cwd": "example", 40 | "request": "launch", 41 | "type": "dart", 42 | "flutterMode": "release" 43 | } 44 | ] 45 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Rafaelbarbosatec 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | analyzer: 2 | plugins: 3 | - dart_code_metrics 4 | 5 | dart_code_metrics: 6 | anti-patterns: 7 | - long-method 8 | - long-parameter-list 9 | metrics: 10 | cyclomatic-complexity: 20 11 | lines-of-executable-code: 50 12 | maximum-nesting-level: 5 13 | number-of-parameters: 5 14 | source-lines-of-code: 50 15 | metrics-exclude: 16 | - tests/** 17 | rules: 18 | - newline-before-return 19 | - no-boolean-literal-compare 20 | - no-empty-block 21 | - prefer-trailing-comma 22 | - prefer-conditional-expressions 23 | - no-equal-then-else -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | /build/ 32 | 33 | # Web related 34 | lib/generated_plugin_registrant.dart 35 | 36 | # Symbolication related 37 | app.*.symbols 38 | 39 | # Obfuscation related 40 | app.*.map.json 41 | 42 | # Exceptions to above rules. 43 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 44 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled. 5 | 6 | version: 7 | revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 8 | channel: stable 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 17 | base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 18 | - platform: android 19 | create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 20 | base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 21 | - platform: ios 22 | create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 23 | base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 24 | - platform: linux 25 | create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 26 | base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 27 | - platform: macos 28 | create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 29 | base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 30 | - platform: web 31 | create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 32 | base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 33 | - platform: windows 34 | create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 35 | base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268 36 | 37 | # User provided section 38 | 39 | # List of Local paths (relative to this file) that should be 40 | # ignored by the migrate tool. 41 | # 42 | # Files that are not part of the templates will be ignored by default. 43 | unmanaged_files: 44 | - 'lib/main.dart' 45 | - 'ios/Runner.xcodeproj/project.pbxproj' 46 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # examplecube 2 | 3 | Example 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) 13 | 14 | For help getting started with Flutter, view our 15 | [online documentation](https://flutter.dev/docs), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | #include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion flutter.compileSdkVersion 30 | ndkVersion flutter.ndkVersion 31 | 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | 37 | kotlinOptions { 38 | jvmTarget = '1.8' 39 | } 40 | 41 | sourceSets { 42 | main.java.srcDirs += 'src/main/kotlin' 43 | } 44 | 45 | defaultConfig { 46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 47 | applicationId "br.com.example" 48 | // You can update the following values to match your application needs. 49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. 50 | minSdkVersion flutter.minSdkVersion 51 | targetSdkVersion flutter.targetSdkVersion 52 | versionCode flutterVersionCode.toInteger() 53 | versionName flutterVersionName 54 | } 55 | 56 | buildTypes { 57 | release { 58 | // TODO: Add your own signing config for the release build. 59 | // Signing with the debug keys for now, so `flutter run --release` works. 60 | signingConfig signingConfigs.debug 61 | } 62 | } 63 | } 64 | 65 | flutter { 66 | source '../..' 67 | } 68 | 69 | dependencies { 70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 71 | } 72 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /example/android/app/src/main/kotlin/br/com/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package br.com.example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.6.10' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:7.1.2' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip 7 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | *.mode1v3 2 | *.mode2v3 3 | *.moved-aside 4 | *.pbxuser 5 | *.perspectivev3 6 | **/*sync/ 7 | .sconsign.dblite 8 | .tags* 9 | **/.vagrant/ 10 | **/DerivedData/ 11 | Icon? 12 | **/Pods/ 13 | **/.symlinks/ 14 | profile 15 | xcuserdata 16 | **/.generated/ 17 | Flutter/App.framework 18 | Flutter/Flutter.framework 19 | Flutter/Flutter.podspec 20 | Flutter/Generated.xcconfig 21 | Flutter/app.flx 22 | Flutter/app.zip 23 | Flutter/flutter_assets/ 24 | Flutter/flutter_export_environment.sh 25 | ServiceDefinitions.json 26 | Runner/GeneratedPluginRegistrant.* 27 | 28 | # Exceptions to above rules. 29 | !default.mode1v3 30 | !default.mode2v3 31 | !default.pbxuser 32 | !default.perspectivev3 33 | -------------------------------------------------------------------------------- /example/ios/Flutter/.last_build_id: -------------------------------------------------------------------------------- 1 | d3de83d5ad881213c5a73fe73b1dece2 -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 11.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | examplecube 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(FLUTTER_BUILD_NAME) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | NSAppTransportSecurity 45 | 46 | NSAllowsArbitraryLoads 47 | 48 | 49 | CADisableMinimumFrameDurationOnPhone 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/lib/counter/counter_cube.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:flutter/src/widgets/framework.dart'; 3 | 4 | class MsgAction extends CubeAction { 5 | final String? text; 6 | 7 | MsgAction({this.text}); 8 | 9 | @override 10 | String toString() { 11 | return 'MsgAction{text: $text}'; 12 | } 13 | 14 | @override 15 | void onExecute(BuildContext context) { 16 | print(this); 17 | } 18 | } 19 | 20 | class CounterCube extends Cube { 21 | final bool withDebounce; 22 | final count = 0.obs; 23 | 24 | CounterCube({this.withDebounce = true}); 25 | 26 | @override 27 | Future onReady(Object? arguments) { 28 | // do anythings when view is ready 29 | return super.onReady(arguments); 30 | } 31 | 32 | void increment() { 33 | count.modify((value) => value + 1); 34 | if (count.value == 5) { 35 | sendAction(MsgAction(text: "count five")); // to send action to view 36 | } 37 | 38 | if (count.value == 50) { 39 | sendAction( 40 | MsgAction(text: "You are clicking too much o.O"), 41 | ); // to send action to view 42 | } 43 | 44 | if (withDebounce) { 45 | runDebounce( 46 | 'increment', 47 | () => print(count.value), 48 | duration: Duration(seconds: 1), 49 | ); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /example/lib/counter/counter_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:examplecube/counter/counter_cube.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class CounterScreen extends StatelessWidget { 6 | @visibleForTesting 7 | static const KEY_FLOATING_BUTTON = Key('CounterScreen.KEY_FLOATING_BUTTON'); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return CubeConsumer( 12 | builder: (BuildContext context, CounterCube cube) { 13 | return Scaffold( 14 | appBar: AppBar( 15 | title: Text('counter'), 16 | ), 17 | body: Center( 18 | child: Column( 19 | mainAxisAlignment: MainAxisAlignment.center, 20 | children: [ 21 | Text('You have pushed the button this many times:'), 22 | cube.count.build( 23 | (value) => Text(value.toString()), 24 | ), 25 | ], 26 | ), 27 | ), 28 | floatingActionButton: FloatingActionButton( 29 | key: KEY_FLOATING_BUTTON, 30 | onPressed: cube.increment, 31 | tooltip: 'Increment', 32 | child: Icon(Icons.add), 33 | ), // This trailing comma makes auto-formatting nicer for build methods. 34 | ); 35 | }, 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /example/lib/counter/counter_screen_animation.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:examplecube/counter/counter_cube.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class CounterScreenWithAnimation extends StatefulWidget { 6 | @override 7 | _CounterScreenWithAnimationState createState() => 8 | _CounterScreenWithAnimationState(); 9 | } 10 | 11 | class _CounterScreenWithAnimationState extends State 12 | with 13 | CubeStateMixin, 14 | TickerProviderStateMixin { 15 | late AnimationController _controller; 16 | late CurvedAnimation _curveAnimation; 17 | 18 | @override 19 | void initState() { 20 | _controller = AnimationController( 21 | vsync: this, 22 | duration: Duration(seconds: 1), 23 | ); 24 | _curveAnimation = CurvedAnimation( 25 | parent: _controller, 26 | curve: Curves.bounceOut, 27 | ); 28 | super.initState(); 29 | _controller.forward(); 30 | } 31 | 32 | @override 33 | void dispose() { 34 | _controller.dispose(); 35 | super.dispose(); 36 | } 37 | 38 | @override 39 | Widget build(BuildContext context) { 40 | return Scaffold( 41 | appBar: AppBar( 42 | title: Text('Cube with animation'), 43 | ), 44 | body: ScaleTransition( 45 | scale: _curveAnimation, 46 | child: Center( 47 | child: Column( 48 | mainAxisAlignment: MainAxisAlignment.center, 49 | children: [ 50 | Text('description_counter'), 51 | cube.count.build((value) { 52 | return Text(value.toString()); 53 | }), 54 | ], 55 | ), 56 | ), 57 | ), 58 | floatingActionButton: FloatingActionButton( 59 | onPressed: cube.increment, 60 | tooltip: 'Increment', 61 | child: Icon(Icons.add), 62 | ), // This trailing comma makes auto-formatting nicer for build methods. 63 | ); 64 | } 65 | 66 | @override 67 | void onAction(CubeAction action) { 68 | print('onAction: $action'); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /example/lib/counter_simple_cube/counter_simple_cube.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | 3 | class CounterSimpleCube extends SimpleCube { 4 | final count = 0.obs; 5 | 6 | void increment() { 7 | count.modify((value) => value + 1); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/lib/counter_simple_cube/counter_simple_cube_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:examplecube/counter_simple_cube/counter_simple_cube.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class CounterSimpleCubeScreen extends StatefulWidget { 6 | const CounterSimpleCubeScreen({Key? key}) : super(key: key); 7 | 8 | @override 9 | _CounterSimpleCubeScreenState createState() => 10 | _CounterSimpleCubeScreenState(); 11 | } 12 | 13 | class _CounterSimpleCubeScreenState extends State { 14 | late CounterSimpleCube cube; 15 | 16 | @override 17 | void initState() { 18 | cube = inject(); 19 | super.initState(); 20 | } 21 | 22 | @override 23 | void dispose() { 24 | cube.dispose(); 25 | super.dispose(); 26 | } 27 | 28 | @override 29 | Widget build(BuildContext context) { 30 | return Scaffold( 31 | appBar: AppBar( 32 | title: Text('counter'), 33 | ), 34 | body: Center( 35 | child: Column( 36 | mainAxisAlignment: MainAxisAlignment.center, 37 | children: [ 38 | Text('description_counter'), 39 | cube.count.build( 40 | (value) => Text(value.toString()), 41 | ), 42 | ], 43 | ), 44 | ), 45 | floatingActionButton: FloatingActionButton( 46 | onPressed: cube.increment, 47 | tooltip: 'Increment', 48 | child: Icon(Icons.add), 49 | ), // This trailing comma makes auto-formatting nicer for build methods. 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /example/lib/counter_singleton/counter_singleton_cube.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | 3 | class CounterSingletonCube extends Cube { 4 | final count = 0.obs; 5 | 6 | void increment() => count.modify((value) => value + 1); 7 | } 8 | -------------------------------------------------------------------------------- /example/lib/counter_singleton/counter_singleton_widget.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:cubes/cubes.dart'; 4 | import 'package:examplecube/counter_singleton/counter_singleton_cube.dart'; 5 | import 'package:flutter/material.dart'; 6 | 7 | class CounterSingletonWidget extends CubeWidget { 8 | @override 9 | Widget buildView(BuildContext context, CounterSingletonCube cube) { 10 | return Scaffold( 11 | body: Center( 12 | child: Column( 13 | mainAxisAlignment: MainAxisAlignment.center, 14 | children: [ 15 | Text('You have pushed the button this many times:'), 16 | SizedBox( 17 | height: 20, 18 | ), 19 | cube.count.build((value) { 20 | return Text(value.toString()); 21 | }), 22 | ], 23 | ), 24 | ), 25 | floatingActionButton: FloatingActionButton( 26 | heroTag: Random().nextInt(1000), 27 | onPressed: cube.increment, 28 | tooltip: 'Increment', 29 | child: Icon(Icons.add), 30 | ), // This trailing comma makes auto-formatting nicer for build methods. 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /example/lib/counter_singleton/screen_counter_singleton.dart: -------------------------------------------------------------------------------- 1 | import 'package:examplecube/counter_singleton/counter_singleton_widget.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class ScreenCounterSingleton extends StatelessWidget { 5 | @override 6 | Widget build(BuildContext context) { 7 | return Scaffold( 8 | appBar: AppBar( 9 | title: Text('singleton'), 10 | ), 11 | body: Column( 12 | children: [ 13 | Expanded( 14 | child: Row( 15 | children: [ 16 | Expanded(child: CounterSingletonWidget()), 17 | Expanded(child: CounterSingletonWidget()), 18 | ], 19 | ), 20 | ), 21 | Expanded( 22 | child: Row( 23 | children: [ 24 | Expanded(child: CounterSingletonWidget()), 25 | Expanded(child: CounterSingletonWidget()), 26 | ], 27 | ), 28 | ), 29 | ], 30 | ), 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /example/lib/feedback_manager/feedback_manager_cube.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | 3 | class FeedbackManagerCube extends Cube { 4 | final dialogControl = CFeedBackControl().obs; 5 | final bottomSheetControl = CFeedBackControl().obs; 6 | final snackBarControl = CFeedBackControl().obs; 7 | 8 | void showDialogPer3Seconds() async { 9 | if (dialogControl.value.show) return; 10 | dialogControl.show(data: 'Dialog Example\n\nawait 3 seconds'); 11 | await Future.delayed(Duration(seconds: 3)); 12 | dialogControl.hide(); 13 | } 14 | 15 | void showBottomSheetPer3Seconds() async { 16 | if (bottomSheetControl.value.show) return; 17 | bottomSheetControl.show(data: 'BottomSheet Example\n\nawait 3 seconds'); 18 | await Future.delayed(Duration(seconds: 3)); 19 | bottomSheetControl.hide(); 20 | } 21 | 22 | void showSnackBar() { 23 | snackBarControl.show(data: 'SnackBar Example'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /example/lib/feedback_manager/feedback_manager_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:examplecube/feedback_manager/feedback_manager_cube.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class FeedbackManagerScreen extends CubeWidget { 6 | @override 7 | Widget buildView(BuildContext context, FeedbackManagerCube cube) { 8 | return Scaffold( 9 | appBar: AppBar( 10 | title: Text('FeedBackManager'), 11 | ), 12 | body: CFeedBackManager( 13 | dialogControllers: [ 14 | CDialogController( 15 | observable: cube.dialogControl, 16 | dismissible: false, 17 | builder: (data, context) => Center( 18 | child: Card( 19 | child: Padding( 20 | padding: const EdgeInsets.all(20.0), 21 | child: Text(data), 22 | ), 23 | ), 24 | ), 25 | ), 26 | ], 27 | bottomSheetControllers: [ 28 | CBottomSheetController( 29 | dismissible: false, 30 | observable: cube.bottomSheetControl, 31 | builder: (data, context) => Container( 32 | height: 200, 33 | child: Center( 34 | child: Text(data), 35 | ), 36 | ), 37 | ), 38 | ], 39 | snackBarControllers: [ 40 | CSnackBarController( 41 | observable: cube.snackBarControl, 42 | builder: (data, context) => SnackBar(content: Text(data)), 43 | ), 44 | ], 45 | child: _buildContent(cube), 46 | ), 47 | ); 48 | } 49 | 50 | Widget _buildContent(FeedbackManagerCube cube) { 51 | return Center( 52 | child: Column( 53 | mainAxisSize: MainAxisSize.min, 54 | children: [ 55 | ElevatedButton( 56 | child: Text('Show dialog per 3 seconds'), 57 | onPressed: cube.showDialogPer3Seconds, 58 | ), 59 | SizedBox( 60 | height: 20, 61 | ), 62 | ElevatedButton( 63 | child: Text('Show bottomSheet per 3 seconds'), 64 | onPressed: cube.showBottomSheetPer3Seconds, 65 | ), 66 | SizedBox( 67 | height: 20, 68 | ), 69 | ElevatedButton( 70 | child: Text('Show snackBar'), 71 | onPressed: cube.showSnackBar, 72 | ), 73 | ], 74 | ), 75 | ); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /example/lib/pokemon/pokemon_cube.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:cubes/cubes.dart'; 4 | import 'package:examplecube/pokemon/repository/model/pokemon.dart'; 5 | import 'package:examplecube/pokemon/repository/pokemon_repository.dart'; 6 | 7 | class PokemonCube extends Cube { 8 | static const LIMIT_PAGE = 20; 9 | final PokemonRepository repository; 10 | 11 | PokemonCube(this.repository); 12 | 13 | final list = [].obs; 14 | final progress = false.obs; 15 | final snackBarController = CFeedBackControl().obs; 16 | 17 | @override 18 | Future onReady(Object? arguments) { 19 | fetchPokemonList(); 20 | return super.onReady(arguments); 21 | } 22 | 23 | void fetchPokemonList({bool isMore = false}) { 24 | if (progress.value) return; 25 | int page = 0; 26 | if (isMore) { 27 | page = (list.length ~/ LIMIT_PAGE) + 1; 28 | } 29 | progress.value = true; 30 | repository.getPokemonList(page: page, limit: LIMIT_PAGE)?.then((value) { 31 | if (isMore) { 32 | list.addAll(value); 33 | } else { 34 | list.value = value; 35 | } 36 | }).catchError((error) { 37 | snackBarController.show(data: error.toString()); 38 | }).whenComplete(() => progress.value = false); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /example/lib/pokemon/pokemon_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:examplecube/pokemon/pokemon_cube.dart'; 3 | import 'package:examplecube/pokemon/repository/model/pokemon.dart'; 4 | import 'package:examplecube/pokemon/widgets/pokemon_item_widget.dart'; 5 | import 'package:flutter/material.dart'; 6 | 7 | class PokemonScreen extends CubeWidget { 8 | @override 9 | Widget buildView(BuildContext context, PokemonCube cube) { 10 | return Scaffold( 11 | appBar: AppBar( 12 | title: Text('Pokemons with CubeWidget'), 13 | ), 14 | body: CFeedBackManager( 15 | snackBarControllers: [ 16 | CSnackBarController( 17 | observable: cube.snackBarController, 18 | builder: (value, context) => SnackBar(content: Text(value)), 19 | ), 20 | ], 21 | child: Stack( 22 | children: [ 23 | cube.list.build>( 24 | (data) { 25 | return ListView.builder( 26 | itemCount: data.length, 27 | itemBuilder: (context, index) { 28 | if (index >= data.length - 3) { 29 | cube.fetchPokemonList(isMore: true); 30 | } 31 | 32 | return PokemonItemWidget( 33 | item: data[index], 34 | ); 35 | }, 36 | ); 37 | }, 38 | ), 39 | cube.progress.build( 40 | (value) => value.conditional( 41 | match: Center(child: CircularProgressIndicator()), 42 | ), 43 | animate: true, 44 | ), 45 | ], 46 | ), 47 | ), 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /example/lib/pokemon/repository/model/pokemon.dart: -------------------------------------------------------------------------------- 1 | class Pokemon { 2 | List? abilities; 3 | String? detailPageURL; 4 | double? weight; 5 | List? weakness; 6 | String? number; 7 | int? height; 8 | String? collectiblesSlug; 9 | String? featured; 10 | String? slug; 11 | String? description; 12 | String? name; 13 | String? thumbnailAltText; 14 | String? thumbnailImage; 15 | int? id; 16 | List? type; 17 | 18 | Pokemon({ 19 | this.abilities, 20 | this.detailPageURL, 21 | this.weight, 22 | this.weakness, 23 | this.number, 24 | this.height, 25 | this.collectiblesSlug, 26 | this.featured, 27 | this.slug, 28 | this.description, 29 | this.name, 30 | this.thumbnailAltText, 31 | this.thumbnailImage, 32 | this.id, 33 | this.type, 34 | }); 35 | 36 | Pokemon.fromJson(Map json) { 37 | abilities = json['abilities'].cast(); 38 | detailPageURL = json['detailPageURL']; 39 | weight = json['weight'].toDouble(); 40 | weakness = json['weakness'].cast(); 41 | number = json['number']; 42 | height = json['height']; 43 | collectiblesSlug = json['collectibles_slug']; 44 | featured = json['featured']; 45 | slug = json['slug']; 46 | description = json['description']; 47 | name = json['name']; 48 | thumbnailAltText = json['thumbnailAltText']; 49 | thumbnailImage = json['thumbnailImage']; 50 | id = json['id']; 51 | type = json['type'].cast(); 52 | } 53 | 54 | Map toJson() { 55 | final Map data = Map(); 56 | data['abilities'] = this.abilities; 57 | data['detailPageURL'] = this.detailPageURL; 58 | data['weight'] = this.weight; 59 | data['weakness'] = this.weakness; 60 | data['number'] = this.number; 61 | data['height'] = this.height; 62 | data['collectibles_slug'] = this.collectiblesSlug; 63 | data['featured'] = this.featured; 64 | data['slug'] = this.slug; 65 | data['description'] = this.description; 66 | data['name'] = this.name; 67 | data['thumbnailAltText'] = this.thumbnailAltText; 68 | data['thumbnailImage'] = this.thumbnailImage; 69 | data['id'] = this.id; 70 | data['type'] = this.type; 71 | 72 | return data; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /example/lib/pokemon/repository/pokemon_repository.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:examplecube/pokemon/repository/model/pokemon.dart'; 4 | import 'package:flutter/foundation.dart'; 5 | import 'package:http/http.dart' as http; 6 | 7 | class PokemonRepository { 8 | Future>? getPokemonList({int page = 0, int limit = 20}) { 9 | String paramLimit = ''; 10 | paramLimit = '&limit=$limit'; 11 | String CORS = ''; 12 | if (kIsWeb) { 13 | CORS = 'https://cors-anywhere.herokuapp.com/'; 14 | } 15 | 16 | return http 17 | .get( 18 | Uri.parse( 19 | '${CORS}http://104.131.18.84/pokemon?page=$page$paramLimit', 20 | ), 21 | ) 22 | .then( 23 | (response) { 24 | return jsonDecode(response.body)['data'] 25 | .map((item) => Pokemon.fromJson(item)) 26 | .toList(); 27 | }, 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /example/lib/pokemon/widgets/pokemon_item_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:examplecube/pokemon/repository/model/pokemon.dart'; 2 | import 'package:flutter/foundation.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class PokemonItemWidget extends StatefulWidget { 6 | final Pokemon? item; 7 | 8 | final Function(Pokemon?)? onClick; 9 | 10 | const PokemonItemWidget({Key? key, this.item, this.onClick}) 11 | : super(key: key); 12 | @override 13 | _PokemonItemWidgetState createState() => _PokemonItemWidgetState(); 14 | } 15 | 16 | class _PokemonItemWidgetState extends State 17 | with TickerProviderStateMixin { 18 | late AnimationController _controller; 19 | late Animation _animationSlide; 20 | 21 | @override 22 | void initState() { 23 | _controller = 24 | AnimationController(vsync: this, duration: Duration(seconds: 1)); 25 | _animationSlide = 26 | Tween(begin: Offset(2.0, 0.0), end: Offset(0.0, 0.0)).animate( 27 | CurvedAnimation( 28 | parent: _controller, 29 | curve: Curves.decelerate, 30 | ), 31 | ); 32 | _controller.forward(from: 0.0); 33 | super.initState(); 34 | } 35 | 36 | @override 37 | Widget build(BuildContext context) { 38 | return SlideTransition( 39 | position: _animationSlide, 40 | child: Container( 41 | margin: const EdgeInsets.all(5.0), 42 | child: Card( 43 | child: _getListTile(), 44 | ), 45 | ), 46 | ); 47 | } 48 | 49 | ListTile _getListTile() { 50 | return ListTile( 51 | contentPadding: const EdgeInsets.all(10), 52 | leading: _getLeadingWidget(widget.item!.thumbnailImage!), 53 | title: _getTittleWidget(widget.item!.name!), 54 | subtitle: Text( 55 | widget.item!.description!, 56 | maxLines: 3, 57 | ), 58 | onTap: () { 59 | if (widget.onClick != null) { 60 | widget.onClick!(widget.item); 61 | } 62 | }, 63 | ); 64 | } 65 | 66 | Widget _getLeadingWidget(String url) { 67 | return Container( 68 | width: 50, 69 | height: 50, 70 | child: Image.network(_getUrl(url)), 71 | ); 72 | } 73 | 74 | Widget _getTittleWidget(String name) { 75 | return Padding( 76 | padding: const EdgeInsets.only(bottom: 10), 77 | child: Text( 78 | name, 79 | style: TextStyle(fontWeight: FontWeight.bold), 80 | ), 81 | ); 82 | } 83 | 84 | @override 85 | void dispose() { 86 | _controller.dispose(); 87 | super.dispose(); 88 | } 89 | 90 | String _getUrl(String url) { 91 | String CORS = ''; 92 | if (kIsWeb) { 93 | CORS = 'https://cors-anywhere.herokuapp.com/'; 94 | } 95 | 96 | return '$CORS$url'; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /example/lib/text_form_field/text_form_field_cube.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | 3 | class TextFormFieldCube extends Cube { 4 | final textFieldControl = CTextFormFieldControl.empty().obs; 5 | 6 | void cleanText() { 7 | textFieldControl.text = ''; 8 | } 9 | 10 | void changeText() { 11 | textFieldControl.text = 'Change Text'; 12 | } 13 | 14 | void setError() { 15 | textFieldControl.error = 'error example'; 16 | } 17 | 18 | void enable() { 19 | textFieldControl.enable = true; 20 | } 21 | 22 | void disable() { 23 | textFieldControl.enable = false; 24 | } 25 | 26 | void changeObscureText() { 27 | textFieldControl.enableObscureText = !textFieldControl.enableObscureText; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /example/lib/text_form_field/text_form_field_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:examplecube/text_form_field/text_form_field_cube.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class TextFormFieldScreen extends CubeWidget { 6 | @override 7 | Widget buildView(BuildContext context, TextFormFieldCube cube) { 8 | return Scaffold( 9 | appBar: AppBar( 10 | title: Text('CTexFormField'), 11 | ), 12 | body: Center( 13 | child: Padding( 14 | padding: const EdgeInsets.all(20.0), 15 | child: Column( 16 | mainAxisSize: MainAxisSize.min, 17 | children: [ 18 | CTextFormField( 19 | observable: cube.textFieldControl, 20 | decoration: InputDecoration(hintText: 'Digite algo'), 21 | obscureTextButtonConfiguration: CObscureTextButtonConfiguration( 22 | show: true, 23 | align: CObscureTextAlign.right, 24 | iconHide: Icon(Icons.visibility_off_outlined), 25 | iconShow: Icon(Icons.visibility_outlined), 26 | ), 27 | ), 28 | SizedBox( 29 | height: 100, 30 | ), 31 | _buildButtons(cube), 32 | ], 33 | ), 34 | ), 35 | ), 36 | ); 37 | } 38 | 39 | Widget _buildButtons(TextFormFieldCube cube) { 40 | return Wrap( 41 | children: [ 42 | ElevatedButton( 43 | child: Text('Clean text'), 44 | onPressed: cube.cleanText, 45 | ), 46 | SizedBox(width: 10), 47 | ElevatedButton( 48 | child: Text('Change text'), 49 | onPressed: cube.changeText, 50 | ), 51 | SizedBox(width: 10), 52 | ElevatedButton( 53 | child: Text('Set error'), 54 | onPressed: cube.setError, 55 | ), 56 | SizedBox(width: 10), 57 | ElevatedButton(child: Text('enable'), onPressed: cube.enable), 58 | SizedBox(width: 10), 59 | ElevatedButton( 60 | child: Text('disable'), 61 | onPressed: cube.disable, 62 | ), 63 | SizedBox(width: 10), 64 | ElevatedButton( 65 | child: Text('change obscureText'), 66 | onPressed: cube.changeObscureText, 67 | ), 68 | ], 69 | ); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /example/lib/todo/todo_cube.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | 3 | class TodoCube extends Cube with CubeNavigation { 4 | final todoList = ['first TODO', 'second TODO'].obs; 5 | 6 | void addTodo(String todo) => todoList.add(todo); 7 | 8 | void delete(String todo) => todoList.remove(todo); 9 | } 10 | -------------------------------------------------------------------------------- /example/lib/todo/todo_list.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:examplecube/todo/todo_cube.dart'; 3 | import 'package:examplecube/todo/todo_register.dart'; 4 | import 'package:flutter/material.dart'; 5 | 6 | class TodoList extends CubeWidget { 7 | @override 8 | Widget buildView(BuildContext context, TodoCube cube) { 9 | return Scaffold( 10 | appBar: AppBar( 11 | title: Text('Todo List'), 12 | ), 13 | body: CAnimatedList( 14 | observable: cube.todoList, 15 | itemBuilder: (context, item, animation, type) { 16 | // ignore: prefer-conditional-expressions 17 | if (type == TypeAnimationListEnum.add) { 18 | return ScaleTransition( 19 | scale: animation, 20 | child: _buildItem(item, cube), 21 | ); 22 | } else { 23 | return SizeTransition( 24 | sizeFactor: animation, 25 | child: _buildItem(item, cube), 26 | ); 27 | } 28 | }, 29 | ), 30 | floatingActionButton: FloatingActionButton( 31 | onPressed: () => _navToRegister(context), 32 | tooltip: 'Increment', 33 | child: Icon(Icons.add), 34 | ), // 35 | ); 36 | } 37 | 38 | Widget _buildItem(String text, TodoCube cube) { 39 | return Card( 40 | margin: const EdgeInsets.symmetric( 41 | horizontal: 10, 42 | vertical: 5, 43 | ), 44 | child: Container( 45 | padding: const EdgeInsets.all(15), 46 | child: Row( 47 | children: [ 48 | Expanded(child: Text(text)), 49 | IconButton( 50 | icon: Icon( 51 | Icons.delete, 52 | color: Colors.red, 53 | ), 54 | onPressed: () { 55 | cube.delete(text); 56 | }, 57 | ), 58 | ], 59 | ), 60 | ), 61 | ); 62 | } 63 | 64 | void _navToRegister(BuildContext context) { 65 | Navigator.push( 66 | context, 67 | MaterialPageRoute(builder: (context) => TodoRegister()), 68 | ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /example/lib/todo/todo_register.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:examplecube/todo/todo_cube.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class TodoRegister extends CubeWidget { 6 | final formKey = GlobalKey(); 7 | final textEditingController = TextEditingController(); 8 | 9 | @override 10 | Widget buildView(BuildContext context, TodoCube cube) { 11 | return Scaffold( 12 | appBar: AppBar( 13 | title: Text('Todo register'), 14 | ), 15 | body: Form( 16 | key: formKey, 17 | child: Card( 18 | margin: const EdgeInsets.all(10), 19 | child: Padding( 20 | padding: const EdgeInsets.all(20.0), 21 | child: Column( 22 | mainAxisSize: MainAxisSize.min, 23 | children: [ 24 | TextFormField( 25 | controller: textEditingController, 26 | decoration: InputDecoration(hintText: 'todo'), 27 | validator: (value) { 28 | if (value!.isEmpty) { 29 | return 'Required field'; 30 | } 31 | 32 | return null; 33 | }, 34 | ), 35 | SizedBox( 36 | height: 20, 37 | ), 38 | SizedBox( 39 | width: double.maxFinite, 40 | child: ElevatedButton( 41 | style: ButtonStyle( 42 | backgroundColor: 43 | MaterialStateProperty.all(context.theme.primaryColor), 44 | ), 45 | child: Text('Save'), 46 | onPressed: () { 47 | if (formKey.currentState!.validate()) { 48 | cube.addTodo(textEditingController.text); 49 | context.pop(textEditingController.text); 50 | } 51 | }, 52 | ), 53 | ), 54 | ], 55 | ), 56 | ), 57 | ), 58 | ), 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /example/linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /example/linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "example"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "example"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GObject::dispose. 85 | static void my_application_dispose(GObject* object) { 86 | MyApplication* self = MY_APPLICATION(object); 87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 89 | } 90 | 91 | static void my_application_class_init(MyApplicationClass* klass) { 92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 95 | } 96 | 97 | static void my_application_init(MyApplication* self) {} 98 | 99 | MyApplication* my_application_new() { 100 | return MY_APPLICATION(g_object_new(my_application_get_type(), 101 | "application-id", APPLICATION_ID, 102 | "flags", G_APPLICATION_NON_UNIQUE, 103 | nullptr)); 104 | } 105 | -------------------------------------------------------------------------------- /example/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/xcuserdata/ 7 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | 9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 10 | } 11 | -------------------------------------------------------------------------------- /example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig: -------------------------------------------------------------------------------- 1 | // This is a generated file; do not edit or check into version control. 2 | FLUTTER_ROOT=/Users/rafaelbarbosa/flutter 3 | FLUTTER_APPLICATION_PATH=/Users/rafaelbarbosa/Documents/MyProjects/cube/example 4 | COCOAPODS_PARALLEL_CODE_SIGN=true 5 | FLUTTER_TARGET=/Users/rafaelbarbosa/Documents/MyProjects/cube/example/lib/main.dart 6 | FLUTTER_BUILD_DIR=build 7 | FLUTTER_BUILD_NAME=1.0.0 8 | FLUTTER_BUILD_NUMBER=1 9 | DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ== 10 | DART_OBFUSCATION=false 11 | TRACK_WIDGET_CREATION=true 12 | TREE_SHAKE_ICONS=false 13 | PACKAGE_CONFIG=/Users/rafaelbarbosa/Documents/MyProjects/cube/example/.dart_tool/package_config.json 14 | -------------------------------------------------------------------------------- /example/macos/Flutter/ephemeral/flutter_export_environment.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This is a generated file; do not edit or check into version control. 3 | export "FLUTTER_ROOT=/Users/rafaelbarbosa/flutter" 4 | export "FLUTTER_APPLICATION_PATH=/Users/rafaelbarbosa/Documents/MyProjects/cube/example" 5 | export "COCOAPODS_PARALLEL_CODE_SIGN=true" 6 | export "FLUTTER_TARGET=/Users/rafaelbarbosa/Documents/MyProjects/cube/example/lib/main.dart" 7 | export "FLUTTER_BUILD_DIR=build" 8 | export "FLUTTER_BUILD_NAME=1.0.0" 9 | export "FLUTTER_BUILD_NUMBER=1" 10 | export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==" 11 | export "DART_OBFUSCATION=false" 12 | export "TRACK_WIDGET_CREATION=true" 13 | export "TREE_SHAKE_ICONS=false" 14 | export "PACKAGE_CONFIG=/Users/rafaelbarbosa/Documents/MyProjects/cube/example/.dart_tool/package_config.json" 15 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 64 | 65 | 71 | 73 | 79 | 80 | 81 | 82 | 84 | 85 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @NSApplicationMain 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /example/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = br.com.example 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2021 br.com. All rights reserved. 15 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /example/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | com.apple.security.network.client 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | NSAppTransportSecurity 32 | 33 | NSAllowsArbitraryLoads 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController.init() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: examplecube 2 | description: Example 3 | 4 | # The following line prevents the package from being accidentally published to 5 | # pub.dev using `pub publish`. This is preferred for private packages. 6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 7 | 8 | # The following defines the version and build number for your application. 9 | # A version number is three numbers separated by dots, like 1.2.43 10 | # followed by an optional build number separated by a +. 11 | # Both the version and the builder number may be overridden in flutter 12 | # build by specifying --build-name and --build-number, respectively. 13 | # In Android, build-name is used as versionName while build-number used as versionCode. 14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 16 | # Read more about iOS versioning at 17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 18 | version: 1.0.0+1 19 | 20 | environment: 21 | sdk: '>=2.12.0 <3.0.0' 22 | 23 | dependencies: 24 | flutter: 25 | sdk: flutter 26 | 27 | cubes: 28 | path: ../ 29 | http: ^0.13.0 30 | mockito: ^5.0.1 31 | 32 | dev_dependencies: 33 | flutter_test: 34 | sdk: flutter 35 | 36 | # For information on the generic Dart part of this file, see the 37 | # following page: https://dart.dev/tools/pub/pubspec 38 | 39 | # The following section is specific to Flutter. 40 | flutter: 41 | 42 | # The following line ensures that the Material Icons font is 43 | # included with your application, so that you can use the icons in 44 | # the material Icons class. 45 | uses-material-design: true 46 | 47 | # To add assets to your application, add an assets section, like this: 48 | # assets: 49 | # - lang/ 50 | 51 | # An image asset can refer to one or more resolution-specific "variants", see 52 | # https://flutter.dev/assets-and-images/#resolution-aware. 53 | 54 | # For details regarding adding assets from package dependencies, see 55 | # https://flutter.dev/assets-and-images/#from-packages 56 | 57 | # To add custom fonts to your application, add a fonts section here, 58 | # in this "flutter" section. Each entry in this list should have a 59 | # "family" key with the font family name, and a "fonts" key with a 60 | # list giving the asset and other descriptors for the font. For 61 | # example: 62 | # fonts: 63 | # - family: Schyler 64 | # fonts: 65 | # - asset: fonts/Schyler-Regular.ttf 66 | # - asset: fonts/Schyler-Italic.ttf 67 | # style: italic 68 | # - family: Trajan Pro 69 | # fonts: 70 | # - asset: fonts/TrajanPro.ttf 71 | # - asset: fonts/TrajanPro_Bold.ttf 72 | # weight: 700 73 | # 74 | # For details regarding fonts from package dependencies, 75 | # see https://flutter.dev/custom-fonts/#from-packages 76 | -------------------------------------------------------------------------------- /example/test/unit/counter_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget tests. 2 | // 3 | // To perform an interaction with a widget in your tests, use the WidgetTester 4 | // utility that Flutter provides. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:examplecube/counter/counter_cube.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | 11 | void main() { 12 | late CounterCube cube; 13 | setUp(() { 14 | cube = CounterCube(); 15 | }); 16 | 17 | tearDown(() { 18 | cube.dispose(); 19 | }); 20 | test('initial value', () { 21 | expect(cube.count.value, 0); 22 | }); 23 | 24 | test('increment value', () { 25 | cube.increment(); 26 | expect(cube.count.value, 1); 27 | }); 28 | 29 | test('increment value 3 times', () { 30 | cube.increment(); 31 | cube.increment(); 32 | cube.increment(); 33 | expect(cube.count.value, 3); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /example/test/unit/pokemon_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:examplecube/pokemon/pokemon_cube.dart'; 2 | import 'package:examplecube/pokemon/repository/model/pokemon.dart'; 3 | import 'package:examplecube/pokemon/repository/pokemon_repository.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | import 'package:mockito/mockito.dart'; 6 | 7 | class MockPokemonRepository extends Mock implements PokemonRepository {} 8 | 9 | void main() { 10 | late MockPokemonRepository repository; 11 | late PokemonCube cube; 12 | setUp(() { 13 | repository = MockPokemonRepository(); 14 | cube = PokemonCube(repository); 15 | }); 16 | 17 | tearDown(() { 18 | cube.dispose(); 19 | }); 20 | 21 | test('initial value', () { 22 | expect(cube.list.value, []); 23 | expect(cube.progress.value, false); 24 | }); 25 | 26 | test('load pokémons', () async { 27 | final List mockList = [ 28 | Pokemon(), 29 | Pokemon(), 30 | Pokemon(), 31 | Pokemon(), 32 | Pokemon(), 33 | ]; 34 | 35 | when( 36 | repository.getPokemonList(), 37 | ).thenAnswer((_) => Future.value(mockList)); 38 | 39 | await cube.onReady(null); 40 | 41 | expect(cube.list.value, isA>()); 42 | expect(cube.list.value, mockList); 43 | expect(cube.progress.value, false); 44 | }); 45 | } 46 | -------------------------------------------------------------------------------- /example/test/util/robot.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | 4 | /// 5 | /// Created by 6 | /// 7 | /// ─▄▀─▄▀ 8 | /// ──▀──▀ 9 | /// █▀▀▀▀▀█▄ 10 | /// █░░░░░█─█ 11 | /// ▀▄▄▄▄▄▀▀ 12 | /// 13 | /// Rafaelbarbosatec 14 | /// on 03/09/21 15 | 16 | class CubeRobotMaterialAppParams { 17 | final ThemeData? themeData; 18 | final ThemeData? darkTheme; 19 | final ThemeMode? themeMode; 20 | final Locale? locale; 21 | final Iterable>? localizationsDelegates; 22 | final Iterable? supportedLocales; 23 | 24 | CubeRobotMaterialAppParams({ 25 | this.themeData, 26 | this.themeMode, 27 | this.darkTheme, 28 | this.localizationsDelegates, 29 | this.supportedLocales, 30 | this.locale, 31 | }); 32 | } 33 | 34 | abstract class Robot { 35 | static const SIZE_DEVICE_DEFAULT = Size(1440, 2560); 36 | final WidgetTester tester; 37 | 38 | Robot(this.tester); 39 | 40 | Future widgetSetup( 41 | Widget widget, { 42 | Duration? awaitAnimation, 43 | Size? sizeScreen, 44 | CubeRobotMaterialAppParams? materialAppParams, 45 | }) async { 46 | tester.binding.window.physicalSizeTestValue = 47 | sizeScreen ?? SIZE_DEVICE_DEFAULT; 48 | await tester.pumpWidget( 49 | MaterialApp( 50 | home: widget, 51 | theme: materialAppParams?.themeData, 52 | localizationsDelegates: materialAppParams?.localizationsDelegates, 53 | supportedLocales: 54 | materialAppParams?.supportedLocales ?? [Locale('en', 'US')], 55 | darkTheme: materialAppParams?.darkTheme, 56 | themeMode: materialAppParams?.themeMode, 57 | locale: materialAppParams?.locale, 58 | debugShowCheckedModeBanner: false, 59 | ), 60 | ); 61 | 62 | await awaitForAnimations(duration: awaitAnimation); 63 | } 64 | 65 | Future awaitForAnimations({Duration? duration}) async { 66 | try { 67 | await tester.pumpAndSettle(duration ?? Duration(milliseconds: 300)); 68 | } catch (e) { 69 | await tester.pump(duration); 70 | } 71 | } 72 | 73 | Future takeSnapshot(String filename) { 74 | return expectLater( 75 | find.byType(MaterialApp), 76 | matchesGoldenFile('./golden_files/$filename.png'), 77 | ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /example/test/widget/counter/counter_widget_robot.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:examplecube/counter/counter_cube.dart'; 3 | import 'package:examplecube/counter/counter_screen.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | 6 | import '../../util/robot.dart'; 7 | 8 | class CounterWidgetRobot extends Robot { 9 | CounterWidgetRobot(WidgetTester tester) : super(tester); 10 | 11 | Future setup() async { 12 | _setupInjections(); 13 | 14 | await widgetSetup( 15 | CounterScreen(), 16 | ); 17 | } 18 | 19 | void _setupInjections() { 20 | Cubes.resetInjector(); 21 | Cubes.registerFactory((i) => CounterCube(withDebounce: false)); 22 | } 23 | 24 | Finder get buttonIncrement { 25 | return find.byKey(CounterScreen.KEY_FLOATING_BUTTON); 26 | } 27 | 28 | void assetText() { 29 | final finder = find.text('You have pushed the button this many times:'); 30 | expect(finder, findsOneWidget); 31 | } 32 | 33 | void assetValue0() { 34 | final finder = find.text('0'); 35 | expect(finder, findsOneWidget); 36 | } 37 | 38 | void assetValue3() { 39 | final finder = find.text('3'); 40 | expect(finder, findsOneWidget); 41 | } 42 | 43 | Future clickIncrement() async { 44 | await tester.tap(buttonIncrement); 45 | await awaitForAnimations(); 46 | } 47 | 48 | Future assetSnapshotScreen() { 49 | return takeSnapshot('counterScreen'); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /example/test/widget/counter/counter_widget_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_test/flutter_test.dart'; 2 | 3 | import 'counter_widget_robot.dart'; 4 | 5 | void main() { 6 | testWidgets('Should load Screen', (WidgetTester tester) async { 7 | final robot = CounterWidgetRobot(tester); 8 | await robot.setup(); 9 | await robot.assetSnapshotScreen(); 10 | }); 11 | 12 | testWidgets('Should increment counter when click in button', 13 | (WidgetTester tester) async { 14 | final robot = CounterWidgetRobot(tester); 15 | await robot.setup(); 16 | robot.assetText(); 17 | robot.assetValue0(); 18 | await robot.clickIncrement(); 19 | await robot.clickIncrement(); 20 | await robot.clickIncrement(); 21 | robot.assetValue3(); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /example/test/widget/counter/failures/counterScreen_isolatedDiff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/test/widget/counter/failures/counterScreen_isolatedDiff.png -------------------------------------------------------------------------------- /example/test/widget/counter/failures/counterScreen_maskedDiff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/test/widget/counter/failures/counterScreen_maskedDiff.png -------------------------------------------------------------------------------- /example/test/widget/counter/failures/counterScreen_masterImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/test/widget/counter/failures/counterScreen_masterImage.png -------------------------------------------------------------------------------- /example/test/widget/counter/failures/counterScreen_testImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/test/widget/counter/failures/counterScreen_testImage.png -------------------------------------------------------------------------------- /example/test/widget/counter/golden_files/counterScreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/test/widget/counter/golden_files/counterScreen.png -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/web/favicon.png -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | example 30 | 31 | 32 | 33 | 36 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /example/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "short_name": "example", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /example/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.14) 3 | project(example LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "example") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(SET CMP0063 NEW) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | # Generated plugin build rules, which manage building the plugins and adding 56 | # them to the application. 57 | include(flutter/generated_plugins.cmake) 58 | 59 | 60 | # === Installation === 61 | # Support files are copied into place next to the executable, so that it can 62 | # run in place. This is done instead of making a separate bundle (as on Linux) 63 | # so that building and running from within Visual Studio will work. 64 | set(BUILD_BUNDLE_DIR "$") 65 | # Make the "install" step default, as it's required to run. 66 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 67 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 68 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 69 | endif() 70 | 71 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 72 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 73 | 74 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 75 | COMPONENT Runtime) 76 | 77 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 78 | COMPONENT Runtime) 79 | 80 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 81 | COMPONENT Runtime) 82 | 83 | if(PLUGIN_BUNDLED_LIBRARIES) 84 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 85 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 86 | COMPONENT Runtime) 87 | endif() 88 | 89 | # Fully re-copy the assets directory on each build to avoid having stale files 90 | # from a previous install. 91 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 92 | install(CODE " 93 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 94 | " COMPONENT Runtime) 95 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 96 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 97 | 98 | # Install the AOT library on non-Debug builds only. 99 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 100 | CONFIGURATIONS Profile;Release 101 | COMPONENT Runtime) 102 | -------------------------------------------------------------------------------- /example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # === Flutter Library === 14 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 15 | 16 | # Published to parent scope for install step. 17 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 18 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 19 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 20 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 21 | 22 | list(APPEND FLUTTER_LIBRARY_HEADERS 23 | "flutter_export.h" 24 | "flutter_windows.h" 25 | "flutter_messenger.h" 26 | "flutter_plugin_registrar.h" 27 | "flutter_texture_registrar.h" 28 | ) 29 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 30 | add_library(flutter INTERFACE) 31 | target_include_directories(flutter INTERFACE 32 | "${EPHEMERAL_DIR}" 33 | ) 34 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 35 | add_dependencies(flutter flutter_assemble) 36 | 37 | # === Wrapper === 38 | list(APPEND CPP_WRAPPER_SOURCES_CORE 39 | "core_implementations.cc" 40 | "standard_codec.cc" 41 | ) 42 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 43 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 44 | "plugin_registrar.cc" 45 | ) 46 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 47 | list(APPEND CPP_WRAPPER_SOURCES_APP 48 | "flutter_engine.cc" 49 | "flutter_view_controller.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 52 | 53 | # Wrapper sources needed for a plugin. 54 | add_library(flutter_wrapper_plugin STATIC 55 | ${CPP_WRAPPER_SOURCES_CORE} 56 | ${CPP_WRAPPER_SOURCES_PLUGIN} 57 | ) 58 | apply_standard_settings(flutter_wrapper_plugin) 59 | set_target_properties(flutter_wrapper_plugin PROPERTIES 60 | POSITION_INDEPENDENT_CODE ON) 61 | set_target_properties(flutter_wrapper_plugin PROPERTIES 62 | CXX_VISIBILITY_PRESET hidden) 63 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 64 | target_include_directories(flutter_wrapper_plugin PUBLIC 65 | "${WRAPPER_ROOT}/include" 66 | ) 67 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 68 | 69 | # Wrapper sources needed for the runner. 70 | add_library(flutter_wrapper_app STATIC 71 | ${CPP_WRAPPER_SOURCES_CORE} 72 | ${CPP_WRAPPER_SOURCES_APP} 73 | ) 74 | apply_standard_settings(flutter_wrapper_app) 75 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 76 | target_include_directories(flutter_wrapper_app PUBLIC 77 | "${WRAPPER_ROOT}/include" 78 | ) 79 | add_dependencies(flutter_wrapper_app flutter_assemble) 80 | 81 | # === Flutter tool backend === 82 | # _phony_ is a non-existent file to force this command to run every time, 83 | # since currently there's no way to get a full input/output list from the 84 | # flutter tool. 85 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 86 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 87 | add_custom_command( 88 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 89 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 90 | ${CPP_WRAPPER_SOURCES_APP} 91 | ${PHONY_OUTPUT} 92 | COMMAND ${CMAKE_COMMAND} -E env 93 | ${FLUTTER_TOOL_ENVIRONMENT} 94 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 95 | windows-x64 $ 96 | VERBATIM 97 | ) 98 | add_custom_target(flutter_assemble DEPENDS 99 | "${FLUTTER_LIBRARY}" 100 | ${FLUTTER_LIBRARY_HEADERS} 101 | ${CPP_WRAPPER_SOURCES_CORE} 102 | ${CPP_WRAPPER_SOURCES_PLUGIN} 103 | ${CPP_WRAPPER_SOURCES_APP} 104 | ) 105 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Disable Windows macros that collide with C++ standard library functions. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 25 | 26 | # Add dependency libraries and include directories. Add any application-specific 27 | # dependencies here. 28 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 29 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 30 | 31 | # Run the Flutter tool portions of the build. This must not be removed. 32 | add_dependencies(${BINARY_NAME} flutter_assemble) 33 | -------------------------------------------------------------------------------- /example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #ifdef FLUTTER_BUILD_NUMBER 64 | #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0 67 | #endif 68 | 69 | #ifdef FLUTTER_BUILD_NAME 70 | #define VERSION_AS_STRING #FLUTTER_BUILD_NAME 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "br.com" "\0" 93 | VALUE "FileDescription", "example" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 br.com. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "example.exe" "\0" 98 | VALUE "ProductName", "example" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | return true; 30 | } 31 | 32 | void FlutterWindow::OnDestroy() { 33 | if (flutter_controller_) { 34 | flutter_controller_ = nullptr; 35 | } 36 | 37 | Win32Window::OnDestroy(); 38 | } 39 | 40 | LRESULT 41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 42 | WPARAM const wparam, 43 | LPARAM const lparam) noexcept { 44 | // Give Flutter, including plugins, an opportunity to handle window messages. 45 | if (flutter_controller_) { 46 | std::optional result = 47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 48 | lparam); 49 | if (result) { 50 | return *result; 51 | } 52 | } 53 | 54 | switch (message) { 55 | case WM_FONTCHANGE: 56 | flutter_controller_->engine()->ReloadSystemFonts(); 57 | break; 58 | } 59 | 60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 61 | } 62 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.CreateAndShow(L"example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | std::string utf8_string; 52 | if (target_length == 0 || target_length > utf8_string.max_size()) { 53 | return utf8_string; 54 | } 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates and shows a win32 window with |title| and position and size using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size to will treat the width height passed in to this function 35 | // as logical pixels and scale to appropriate for the default monitor. Returns 36 | // true if the window was created successfully. 37 | bool CreateAndShow(const std::wstring& title, 38 | const Point& origin, 39 | const Size& size); 40 | 41 | // Release OS resources associated with window. 42 | void Destroy(); 43 | 44 | // Inserts |content| into the window tree. 45 | void SetChildContent(HWND content); 46 | 47 | // Returns the backing Window handle to enable clients to set icon and other 48 | // window properties. Returns nullptr if the window has been destroyed. 49 | HWND GetHandle(); 50 | 51 | // If true, closing this window will quit the application. 52 | void SetQuitOnClose(bool quit_on_close); 53 | 54 | // Return a RECT representing the bounds of the current client area. 55 | RECT GetClientArea(); 56 | 57 | protected: 58 | // Processes and route salient window messages for mouse handling, 59 | // size change and DPI. Delegates handling of these to member overloads that 60 | // inheriting classes can handle. 61 | virtual LRESULT MessageHandler(HWND window, 62 | UINT const message, 63 | WPARAM const wparam, 64 | LPARAM const lparam) noexcept; 65 | 66 | // Called when CreateAndShow is called, allowing subclass window-related 67 | // setup. Subclasses should return false if setup fails. 68 | virtual bool OnCreate(); 69 | 70 | // Called when Destroy is called. 71 | virtual void OnDestroy(); 72 | 73 | private: 74 | friend class WindowClassRegistrar; 75 | 76 | // OS callback called by message pump. Handles the WM_NCCREATE message which 77 | // is passed when the non-client area is being created and enables automatic 78 | // non-client DPI scaling so that the non-client area automatically 79 | // responsponds to changes in DPI. All other messages are handled by 80 | // MessageHandler. 81 | static LRESULT CALLBACK WndProc(HWND const window, 82 | UINT const message, 83 | WPARAM const wparam, 84 | LPARAM const lparam) noexcept; 85 | 86 | // Retrieves a class instance pointer for |window| 87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 88 | 89 | bool quit_on_close_ = false; 90 | 91 | // window handle for top level window. 92 | HWND window_handle_ = nullptr; 93 | 94 | // window handle for hosted content. 95 | HWND child_content_ = nullptr; 96 | }; 97 | 98 | #endif // RUNNER_WIN32_WINDOW_H_ 99 | -------------------------------------------------------------------------------- /lib/cubes.dart: -------------------------------------------------------------------------------- 1 | library cube; 2 | 3 | import 'package:flutter/widgets.dart'; 4 | 5 | import 'src/cube.dart'; 6 | import 'src/injector/get_it_injector.dart'; 7 | import 'src/injector/injector.dart'; 8 | import 'src/util/cube_provider.dart'; 9 | 10 | export 'package:cubes/src/actions/cube_action.dart'; 11 | export 'package:cubes/src/cube.dart'; 12 | export 'package:cubes/src/feedback_manager/feedback_manager.dart'; 13 | export 'package:cubes/src/injector/injector.dart'; 14 | export 'package:cubes/src/observable/observable_list.dart'; 15 | export 'package:cubes/src/observable/observable_value.dart'; 16 | export 'package:cubes/src/util/cube_navigation_mixin.dart'; 17 | export 'package:cubes/src/util/cube_provider.dart'; 18 | export 'package:cubes/src/util/extensions/ext.dart'; 19 | export 'package:cubes/src/util/functions.dart'; 20 | export 'package:cubes/src/util/state_mixin.dart'; 21 | export 'package:cubes/src/widgets/animated_list_cube.dart'; 22 | export 'package:cubes/src/widgets/cube_consumer.dart'; 23 | export 'package:cubes/src/widgets/cube_widget.dart'; 24 | export 'package:cubes/src/widgets/text_form_field.dart'; 25 | 26 | /// Core of the package where you will have useful functions and settings 27 | class Cubes { 28 | /// instance of the Cubes 29 | static final Cubes _instance = Cubes._internal(); 30 | CInjector _injector = GetItInjector(); 31 | 32 | Cubes._internal(); 33 | 34 | /// Factory to get instance of the Cubes 35 | factory Cubes() { 36 | return _instance; 37 | } 38 | 39 | /// Use to get dependency registered 40 | static T get({String? dependencyName}) { 41 | return _instance._injector.get(dependencyName: dependencyName); 42 | } 43 | 44 | /// Use to get dependency registered by async 45 | static Future getAsync({String? dependencyName}) { 46 | return _instance._injector.getAsync(dependencyName: dependencyName); 47 | } 48 | 49 | /// Method used to register dependency by lazy 50 | static void registerLazySingleton( 51 | CDependencyInjectorBuilder builder, { 52 | String? dependencyName, 53 | }) { 54 | _instance._injector.registerLazySingleton( 55 | builder, 56 | dependencyName: dependencyName, 57 | ); 58 | } 59 | 60 | /// Method used to register dependency by factory 61 | static void registerFactory( 62 | CDependencyInjectorBuilder builder, { 63 | String? dependencyName, 64 | }) { 65 | _instance._injector.registerFactory( 66 | builder, 67 | dependencyName: dependencyName, 68 | ); 69 | } 70 | 71 | /// Method used to register singleton dependency 72 | static void registerSingleton( 73 | T value, { 74 | String? dependencyName, 75 | }) { 76 | _instance._injector.registerSingleton( 77 | value, 78 | dependencyName: dependencyName, 79 | ); 80 | } 81 | 82 | static void registerSingletonAsync( 83 | CDependencyInjectorAsyncBuilder builder, { 84 | String? dependencyName, 85 | }) { 86 | _instance._injector.registerSingletonAsync( 87 | builder, 88 | dependencyName: dependencyName, 89 | ); 90 | } 91 | 92 | static void registerFactoryAsync( 93 | CDependencyInjectorAsyncBuilder builder, { 94 | String? dependencyName, 95 | }) { 96 | _instance._injector.registerFactoryAsync( 97 | builder, 98 | dependencyName: dependencyName, 99 | ); 100 | } 101 | 102 | /// Use to reset injector 103 | static void resetInjector() => _instance._injector.reset(); 104 | 105 | /// Use to get injector 106 | CInjector get injector => _instance._injector; 107 | 108 | /// Use to register your on Injector 109 | set injector(CInjector injector) => _instance._injector = injector; 110 | 111 | /// Use to get Cube registered in de Widget tree. 112 | static C? of(BuildContext context) { 113 | return context.dependOnInheritedWidgetOfExactType>()?.cube; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /lib/src/actions/cube_action.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | /// 4 | /// Created by 5 | /// 6 | /// ─▄▀─▄▀ 7 | /// ──▀──▀ 8 | /// █▀▀▀▀▀█▄ 9 | /// █░░░░░█─█ 10 | /// ▀▄▄▄▄▄▀▀ 11 | /// 12 | /// Rafaelbarbosatec 13 | /// on 14/02/22 14 | /// Base to Actions 15 | 16 | abstract class CubeAction { 17 | /// When the action is sent he will are executed per this method 18 | // ignore: no-empty-block 19 | void onExecute(BuildContext context) {} 20 | } 21 | -------------------------------------------------------------------------------- /lib/src/actions/navigation_cube_action.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/src/actions/cube_action.dart'; 2 | import 'package:cubes/src/util/extensions/ext.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | /// 6 | /// Created by 7 | /// 8 | /// ─▄▀─▄▀ 9 | /// ──▀──▀ 10 | /// █▀▀▀▀▀█▄ 11 | /// █░░░░░█─█ 12 | /// ▀▄▄▄▄▄▀▀ 13 | /// 14 | /// Rafaelbarbosatec 15 | /// on 14/02/22 16 | 17 | enum NavigationType { 18 | pushNamed, 19 | pushNamedAndRemoveUntil, 20 | pushReplacementNamed, 21 | pop, 22 | } 23 | 24 | class NavigationCubeAction extends CubeAction { 25 | final String? routeName; 26 | final Object? arguments; 27 | final RouteSettings? settings; 28 | final bool fullscreenDialog; 29 | final RoutePredicate? predicate; 30 | final NavigationType type; 31 | final Object? result; 32 | final ValueChanged? onResult; 33 | 34 | NavigationCubeAction({ 35 | this.type = NavigationType.pushNamed, 36 | this.routeName, 37 | this.arguments, 38 | this.onResult, 39 | this.settings, 40 | this.fullscreenDialog = false, 41 | this.predicate, 42 | this.result, 43 | }); 44 | 45 | NavigationCubeAction.pop({ 46 | this.result, 47 | }) : type = NavigationType.pop, 48 | routeName = null, 49 | predicate = null, 50 | settings = null, 51 | onResult = null, 52 | fullscreenDialog = false, 53 | arguments = null; 54 | 55 | NavigationCubeAction.pushNamed({ 56 | required this.routeName, 57 | this.arguments, 58 | this.onResult, 59 | }) : type = NavigationType.pushNamed, 60 | predicate = null, 61 | settings = null, 62 | fullscreenDialog = false, 63 | result = null; 64 | 65 | NavigationCubeAction.pushNamedAndRemoveUntil({ 66 | required this.routeName, 67 | required this.predicate, 68 | this.arguments, 69 | this.onResult, 70 | }) : type = NavigationType.pushNamedAndRemoveUntil, 71 | settings = null, 72 | fullscreenDialog = false, 73 | result = null; 74 | 75 | NavigationCubeAction.pushReplacementNamed({ 76 | required this.routeName, 77 | this.arguments, 78 | this.onResult, 79 | }) : type = NavigationType.pushReplacementNamed, 80 | settings = null, 81 | predicate = null, 82 | fullscreenDialog = false, 83 | result = null; 84 | 85 | @override 86 | void onExecute(BuildContext context) { 87 | switch (type) { 88 | case NavigationType.pushNamed: 89 | context 90 | .goToNamed(routeName!, arguments: arguments) 91 | .then((r) => onResult?.call(r)); 92 | break; 93 | case NavigationType.pushNamedAndRemoveUntil: 94 | context 95 | .goToNamedAndRemoveUntil( 96 | routeName!, 97 | predicate!, 98 | arguments: arguments, 99 | ) 100 | .then((r) => onResult?.call(r)); 101 | break; 102 | case NavigationType.pushReplacementNamed: 103 | context 104 | .goToNamedReplacement(routeName!, arguments: arguments) 105 | .then((r) => onResult?.call(r)); 106 | break; 107 | case NavigationType.pop: 108 | context.pop(result); 109 | break; 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /lib/src/cube.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/material.dart'; 4 | 5 | import '../cubes.dart'; 6 | import 'util/debouncer.dart'; 7 | 8 | /// Function to notify Actions 9 | typedef OnActionChanged = void Function( 10 | A valueA, 11 | CubeAction valueB, 12 | ); 13 | 14 | /// Base to create Cube 15 | abstract class Cube extends SimpleCube { 16 | List> _onActionListeners = []; 17 | 18 | OnActionChanged? _cubeActionListener; 19 | 20 | /// called when the view is ready 21 | /// [arguments] if passed through CubeBuilder, if not, get arguments 22 | /// from `ModalRoute.of(context).settings.arguments;` 23 | // ignore: no-empty-block 24 | Future onReady(Object? arguments) { 25 | return Future.value(); 26 | } 27 | 28 | /// Add OnActionListener 29 | void addOnActionListener( 30 | OnActionChanged? listener, 31 | ) { 32 | _onActionListeners.add(listener as OnActionChanged); 33 | } 34 | 35 | /// Remove OnActionListener 36 | void removeOnActionListener( 37 | OnActionChanged? listener, 38 | ) { 39 | _onActionListeners.remove(listener); 40 | } 41 | 42 | /// Method to send anything to view 43 | @protected 44 | void sendAction(CubeAction action) { 45 | if (_onActionListeners.isNotEmpty) { 46 | _onActionListeners.last(this, action); 47 | } 48 | } 49 | 50 | @override 51 | void dispose() { 52 | removeOnActionListener(_cubeActionListener); 53 | super.dispose(); 54 | } 55 | 56 | /// Uses to listen `CubeAction` sended to view 57 | @protected 58 | void listenActions(ValueChanged listener) { 59 | _cubeActionListener = (cube, action) => listener(action); 60 | addOnActionListener(_cubeActionListener); 61 | } 62 | } 63 | 64 | abstract class SimpleCube { 65 | Map? _debounceMap; 66 | Map? _listenersObservableMap; 67 | 68 | /// 69 | /// Uses to apply debounce. 70 | /// 71 | /// Example: 72 | /// 73 | /// runDebounce( 74 | /// 'increment', 75 | /// () => print(count.value), 76 | /// duration: Duration(seconds: 1), 77 | /// ); 78 | /// 79 | @protected 80 | void runDebounce( 81 | dynamic identify, 82 | VoidCallback call, { 83 | Duration duration = const Duration(milliseconds: 400), 84 | }) { 85 | try { 86 | if (_debounceMap == null) { 87 | _debounceMap = {}; 88 | } 89 | if (_debounceMap?.containsKey(identify) == true) { 90 | if (_debounceMap![identify]?.delay != duration) { 91 | _debounceMap![identify] = Debounce(duration); 92 | } 93 | _debounceMap![identify]?.call(call); 94 | } else { 95 | _debounceMap![identify] = Debounce(duration); 96 | _debounceMap![identify]?.call(call); 97 | } 98 | } on Exception catch (e) { 99 | print('[ERROR]runDebounce: $e'); 100 | } 101 | } 102 | 103 | /// Uses to listen `ObservableValue` inner Cube 104 | @protected 105 | void listen(ObservableValue observableValue, ValueChanged listener) { 106 | if (_listenersObservableMap == null) { 107 | _listenersObservableMap = {}; 108 | } 109 | _listenersObservableMap![observableValue] = () { 110 | listener(observableValue.value); 111 | }; 112 | observableValue.addListener(_listenersObservableMap![observableValue]!); 113 | } 114 | 115 | /// called when the cube is destroyed 116 | void dispose() { 117 | _debounceMap?.clear(); 118 | _listenersObservableMap?.forEach((key, value) => key.removeListener(value)); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /lib/src/feedback_manager/dialog_feedback_mixin.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import '../observable/observable_value.dart'; 4 | import 'feedback_manager.dart'; 5 | 6 | /// Class responsible for configuring the dialogs 7 | class CDialogController { 8 | final bool dismissible; 9 | final Color? barrierColor; 10 | final bool useSafeArea; 11 | final bool useRootNavigator; 12 | final RouteSettings? routeSettings; 13 | final ObservableValue> observable; 14 | final WidgetByDataBuilder builder; 15 | 16 | Widget doBuild(T data, BuildContext context) { 17 | return builder(data, context); 18 | } 19 | 20 | CDialogController({ 21 | required this.observable, 22 | required this.builder, 23 | this.dismissible = true, 24 | this.barrierColor = Colors.black54, 25 | this.useSafeArea = true, 26 | this.useRootNavigator = true, 27 | this.routeSettings, 28 | }); 29 | } 30 | 31 | /// Mixin responsible for adding listeners to ObservableValue and controlling 32 | /// the display of dialogs 33 | mixin DialogFeedBackMixin on State { 34 | static const ANIMATION_DURATION = 150; 35 | final Map _mapDialogIsShowing = {}; 36 | final Map _mapDialogListeners = {}; 37 | List? dialogControllers; 38 | 39 | /// Configure listeners of the dialogControllers. 40 | void confDialogFeedBack(List? controllers) { 41 | dialogControllers = controllers; 42 | dialogControllers?.forEach(_registerDialog); 43 | } 44 | 45 | @override 46 | void dispose() { 47 | dialogControllers?.forEach(_disposeDialog); 48 | super.dispose(); 49 | } 50 | 51 | /// Listener that controls the display of the Dialog. 52 | void _listenerDialogController(CDialogController element) { 53 | if (!mounted) return; 54 | if (element.observable.value.show && !_mapDialogIsShowing[element]!) { 55 | _showDialog(element); 56 | } else if (!element.observable.value.show && 57 | _mapDialogIsShowing[element]!) { 58 | _mapDialogIsShowing[element] = false; 59 | Navigator.pop(context); 60 | } 61 | } 62 | 63 | /// Displays Dialog with the added settings. 64 | void _showDialog(CDialogController element) async { 65 | await Future.delayed(Duration(milliseconds: ANIMATION_DURATION)); 66 | _mapDialogIsShowing[element] = true; 67 | await showDialog( 68 | context: context, 69 | barrierDismissible: element.dismissible, 70 | barrierColor: element.barrierColor, 71 | useSafeArea: element.useSafeArea, 72 | useRootNavigator: element.useRootNavigator, 73 | routeSettings: element.routeSettings, 74 | builder: (context) { 75 | return WillPopScope( 76 | onWillPop: () => Future.value(element.dismissible), 77 | child: element.doBuild(element.observable.value.data, context), 78 | ); 79 | }, 80 | ); 81 | _mapDialogIsShowing[element] = false; 82 | element.observable.setValueWithoutNotify = 83 | element.observable.value.copyWith(show: false); 84 | } 85 | 86 | void _registerDialog(CDialogController element) { 87 | _mapDialogIsShowing[element] = false; 88 | _mapDialogListeners[element] = () => _listenerDialogController(element); 89 | element.observable.addListener(_mapDialogListeners[element]!); 90 | } 91 | 92 | void _disposeDialog(CDialogController element) { 93 | element.observable.removeListener(_mapDialogListeners[element]!); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /lib/src/feedback_manager/feedback_manager.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import 'bottom_sheet_feedback_mixin.dart'; 4 | import 'dialog_feedback_mixin.dart'; 5 | import 'snackbar_feedback_mixin.dart'; 6 | 7 | export 'package:cubes/src/feedback_manager/bottom_sheet_feedback_mixin.dart'; 8 | export 'package:cubes/src/feedback_manager/dialog_feedback_mixin.dart'; 9 | export 'package:cubes/src/feedback_manager/snackbar_feedback_mixin.dart'; 10 | 11 | typedef WidgetByDataBuilder = Widget Function(T data, BuildContext context); 12 | 13 | /// class used to control feedbacks 14 | class CFeedBackControl { 15 | final bool show; 16 | final T? data; 17 | 18 | /// Constructor of the CFeedBackControl 19 | CFeedBackControl({this.show = false, this.data}); 20 | 21 | CFeedBackControl copyWith({bool? show, T? data}) { 22 | return CFeedBackControl( 23 | show: show ?? this.show, 24 | data: data ?? this.data, 25 | ); 26 | } 27 | } 28 | 29 | /// Widget that allows us to control Dialog, BottomSheet and SnackBars 30 | /// using ObservableValue 31 | class CFeedBackManager extends StatefulWidget { 32 | final Widget child; 33 | 34 | final List? bottomSheetControllers; 35 | final List? dialogControllers; 36 | final List? snackBarControllers; 37 | const CFeedBackManager({ 38 | Key? key, 39 | required this.child, 40 | this.bottomSheetControllers, 41 | this.dialogControllers, 42 | this.snackBarControllers, 43 | }) : super(key: key); 44 | @override 45 | _CFeedBackManagerState createState() => _CFeedBackManagerState(); 46 | } 47 | 48 | class _CFeedBackManagerState extends State 49 | with DialogFeedBackMixin, BottomSheetFeedBackMixin, SnackBarFeedBackMixin { 50 | @override 51 | void initState() { 52 | confBottomSheetFeedBack(widget.bottomSheetControllers); 53 | confDialogFeedBack(widget.dialogControllers); 54 | confSnackBarFeedBack(widget.snackBarControllers); 55 | super.initState(); 56 | } 57 | 58 | @override 59 | Widget build(BuildContext context) => widget.child; 60 | } 61 | -------------------------------------------------------------------------------- /lib/src/feedback_manager/snackbar_feedback_mixin.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import '../observable/observable_value.dart'; 4 | import 'feedback_manager.dart'; 5 | 6 | typedef SnackBarByDataBuilder = SnackBar Function( 7 | T data, 8 | BuildContext context, 9 | ); 10 | 11 | /// Class responsible for configuring the SnackBars 12 | class CSnackBarController { 13 | final ObservableValue> observable; 14 | final SnackBarByDataBuilder builder; 15 | 16 | /// Method used to get SnackBar with data type 17 | SnackBar doBuild(T data, BuildContext context) { 18 | return builder(data, context); 19 | } 20 | 21 | /// Constructor of the CSnackBarController 22 | CSnackBarController({ 23 | required this.observable, 24 | required this.builder, 25 | }); 26 | } 27 | 28 | /// Mixin responsible for adding listeners to ObservableValue and controlling 29 | /// the display of SnackBars 30 | mixin SnackBarFeedBackMixin on State { 31 | List? snackBarControllers; 32 | ScaffoldFeatureController? snackBarController; 33 | final Map _mapSnackBarIsShowing = {}; 34 | 35 | /// Configure listeners of the snackBarControllers. 36 | void confSnackBarFeedBack(List? controllers) { 37 | snackBarControllers = controllers; 38 | snackBarControllers?.forEach(_registerSnackBar); 39 | } 40 | 41 | @override 42 | void dispose() { 43 | snackBarControllers?.forEach(_disposeSnackBar); 44 | super.dispose(); 45 | } 46 | 47 | /// Listener that controls the display of the snackBar. 48 | void _listenerDialogController(CSnackBarController element) { 49 | if (!mounted) return; 50 | if (element.observable.value.show && !_mapSnackBarIsShowing[element]!) { 51 | _showSnackBar(element); 52 | } else if (!element.observable.value.show && 53 | _mapSnackBarIsShowing[element]!) { 54 | _mapSnackBarIsShowing[element] = false; 55 | snackBarController?.close(); 56 | } 57 | } 58 | 59 | /// Displays SnackBar with the added settings. 60 | void _showSnackBar(CSnackBarController element) async { 61 | _mapSnackBarIsShowing[element] = true; 62 | 63 | final snackBar = element.doBuild(element.observable.value.data, context); 64 | 65 | snackBarController = ScaffoldMessenger.of(context).showSnackBar(snackBar); 66 | 67 | await Future.delayed(snackBar.duration); 68 | 69 | _mapSnackBarIsShowing[element] = false; 70 | element.observable.setValueWithoutNotify = 71 | element.observable.value.copyWith(show: false); 72 | } 73 | 74 | void _registerSnackBar(CSnackBarController element) { 75 | _mapSnackBarIsShowing[element] = false; 76 | element.observable.addListener(() => _listenerDialogController(element)); 77 | } 78 | 79 | void _disposeSnackBar(CSnackBarController element) { 80 | element.observable.dispose(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /lib/src/injector/get_it_injector.dart: -------------------------------------------------------------------------------- 1 | import 'package:get_it/get_it.dart'; 2 | 3 | import 'injector.dart'; 4 | 5 | final _getIt = GetIt.instance; 6 | 7 | /// CInjector implemented with GetIt 8 | class GetItInjector extends CInjector { 9 | @override 10 | T get({String? dependencyName}) { 11 | return _getIt.get(instanceName: dependencyName); 12 | } 13 | 14 | @override 15 | Future getAsync({String? dependencyName}) { 16 | return _getIt.getAsync(instanceName: dependencyName); 17 | } 18 | 19 | @override 20 | Future reset({bool dispose = false}) { 21 | return _getIt.reset(dispose: dispose); 22 | } 23 | 24 | @override 25 | void registerFactory( 26 | CDependencyInjectorBuilder builder, { 27 | String? dependencyName, 28 | }) { 29 | _getIt.registerFactory( 30 | () => builder(this), 31 | instanceName: dependencyName, 32 | ); 33 | } 34 | 35 | @override 36 | void registerLazySingleton( 37 | CDependencyInjectorBuilder builder, { 38 | String? dependencyName, 39 | }) { 40 | _getIt.registerLazySingleton( 41 | () => builder(this), 42 | instanceName: dependencyName, 43 | ); 44 | } 45 | 46 | @override 47 | void registerSingleton(T value, {String? dependencyName}) { 48 | _getIt.registerSingleton( 49 | value, 50 | instanceName: dependencyName, 51 | ); 52 | } 53 | 54 | @override 55 | void registerSingletonAsync( 56 | CDependencyInjectorAsyncBuilder builder, { 57 | String? dependencyName, 58 | }) { 59 | _getIt.registerSingletonAsync( 60 | () => builder(this), 61 | instanceName: dependencyName, 62 | ); 63 | } 64 | 65 | @override 66 | void registerFactoryAsync( 67 | CDependencyInjectorAsyncBuilder builder, { 68 | String? dependencyName, 69 | }) { 70 | _getIt.registerFactoryAsync( 71 | () => builder(this), 72 | instanceName: dependencyName, 73 | ); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /lib/src/injector/injector.dart: -------------------------------------------------------------------------------- 1 | /// Function to receive dependency to inject 2 | typedef CDependencyInjectorBuilder = T Function(CInjector injector); 3 | 4 | /// Function to receive dependency to inject 5 | typedef CDependencyInjectorAsyncBuilder = Future Function( 6 | CInjector injector, 7 | ); 8 | 9 | /// Interface responsible to manager dependency injector 10 | abstract class CInjector { 11 | /// Method used to register dependency by lazy 12 | void registerLazySingleton( 13 | CDependencyInjectorBuilder builder, { 14 | String? dependencyName, 15 | }); 16 | 17 | /// Method used to register dependency by factory 18 | void registerFactory( 19 | CDependencyInjectorBuilder builder, { 20 | String? dependencyName, 21 | }); 22 | 23 | /// Method used to register singleton dependency 24 | void registerSingleton( 25 | T value, { 26 | String? dependencyName, 27 | }); 28 | 29 | /// Method used to register dependency async 30 | void registerFactoryAsync( 31 | CDependencyInjectorAsyncBuilder builder, { 32 | String? dependencyName, 33 | }); 34 | 35 | /// Method used to register dependency async 36 | void registerSingletonAsync( 37 | CDependencyInjectorAsyncBuilder builder, { 38 | String? dependencyName, 39 | }); 40 | 41 | /// Method used to get dependency 42 | T get({String? dependencyName}); 43 | 44 | /// Method used to get dependency async 45 | Future getAsync({String? dependencyName}); 46 | 47 | /// Method used to reset dependencies registered 48 | Future reset({bool dispose = false}); 49 | } 50 | -------------------------------------------------------------------------------- /lib/src/observable/observable_list.dart: -------------------------------------------------------------------------------- 1 | import 'observable_value.dart'; 2 | 3 | /// Class that represents our list-type observable 4 | class ObservableList extends ObservableValue> { 5 | /// Constructor to init ObservableValue with value 6 | ObservableList({required List value}) : super(value: value) { 7 | setValueWithoutNotify = value; 8 | } 9 | 10 | /// add element in list and notify listeners 11 | void add(T value) { 12 | this.value.add(value); 13 | notifyListeners(); 14 | } 15 | 16 | /// add element list in list and notify listeners 17 | void addAll(Iterable value) { 18 | this.value.addAll(value); 19 | notifyListeners(); 20 | } 21 | 22 | /// clear list and notify listeners 23 | void clear() { 24 | value.clear(); 25 | notifyListeners(); 26 | } 27 | 28 | /// remove in list and notify listeners 29 | void remove(T value) { 30 | this.value.remove(value); 31 | notifyListeners(); 32 | } 33 | 34 | /// remove element by index in list and notify listeners 35 | void removeAt(int index) { 36 | value.removeAt(index); 37 | notifyListeners(); 38 | } 39 | 40 | /// remove element in list and notify listeners 41 | void removeWhere(bool test(T element)) { 42 | value.removeWhere(test); 43 | notifyListeners(); 44 | } 45 | 46 | /// remove last element in list and notify listeners 47 | void removeLast() { 48 | value.removeLast(); 49 | notifyListeners(); 50 | } 51 | 52 | /// remove element by range in list and notify listeners 53 | void removeRange(int start, int end) { 54 | value.removeRange(start, end); 55 | notifyListeners(); 56 | } 57 | 58 | /// insert element in the index 59 | void insert(int index, T element) { 60 | value.insert(index, element); 61 | notifyListeners(); 62 | } 63 | 64 | /// insert element list in the index 65 | void insertAll(int index, Iterable iterable) { 66 | value.insertAll(index, iterable); 67 | notifyListeners(); 68 | } 69 | 70 | /// replace elements in list and notify listeners 71 | void replaceRange(int start, int end, Iterable replacement) { 72 | value.replaceRange(start, end, replacement); 73 | notifyListeners(); 74 | } 75 | 76 | /// use to modify specific item in the list 77 | void modifyItem(int index, T modify(T value)) { 78 | if (value.length > index) { 79 | value[index] = modify(value[index]); 80 | notifyListeners(); 81 | } 82 | } 83 | 84 | /// use [List.indexOf] 85 | int indexOf(T element) { 86 | return value.indexOf(element); 87 | } 88 | 89 | /// use [List.indexWhere] 90 | int indexWhere(bool test(T element), [int start = 0]) { 91 | return value.indexWhere(test, start); 92 | } 93 | 94 | /// get if list is empty 95 | bool get isEmpty => value.isEmpty; 96 | 97 | /// get if list is not empty 98 | bool get isNotEmpty => !isEmpty; 99 | 100 | /// get size list 101 | int get length => value.length; 102 | 103 | /// get first item 104 | T get first => value.first; 105 | 106 | /// get last item 107 | T get last => value.last; 108 | } 109 | -------------------------------------------------------------------------------- /lib/src/observable/observable_value.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/foundation.dart'; 2 | 3 | typedef ModifyValue = T Function(T value); 4 | 5 | /// Class that represents our observable 6 | class ObservableValue extends ChangeNotifier { 7 | T _value; 8 | T _lastValue; 9 | 10 | /// Constructor to init ObservableValue with value 11 | ObservableValue({required T value}) 12 | : _value = value, 13 | _lastValue = value; 14 | 15 | /// Get current value of the observable 16 | T get value => _value; 17 | 18 | /// Set current value of the observable 19 | set value(T newValue) => update(newValue); 20 | 21 | /// Get las value of the observable 22 | T? get lastValue => _lastValue; 23 | 24 | /// Method uses to set value without notify listeners 25 | // ignore: avoid_setters_without_getters 26 | set setValueWithoutNotify(T value) => _value = value; 27 | 28 | void _setValueAndNotify(T newValue) { 29 | if (T is List) { 30 | _lastValue = List.of(_value as List) as T; 31 | } else if (T is Map) { 32 | _lastValue = Map.of(_value as Map) as T; 33 | } else { 34 | _lastValue = _value; 35 | } 36 | _value = newValue; 37 | notifyListeners(); 38 | } 39 | 40 | @override 41 | void notifyListeners() { 42 | try { 43 | super.notifyListeners(); 44 | } on Exception catch (_) { 45 | print('A $runtimeType was used after being disposed'); 46 | } 47 | } 48 | 49 | @override 50 | void dispose() { 51 | try { 52 | super.dispose(); 53 | } on Exception catch (_) { 54 | print('Once you have called dispose() on a $runtimeType,' 55 | ' it can no longer be used.'); 56 | } 57 | } 58 | 59 | /// uses to update value 60 | void update(T value) => _setValueAndNotify(value); 61 | 62 | /// user do modify value. recommended return new instance 63 | /// (use copyWith if is possible). 64 | void modify(ModifyValue modify) => _setValueAndNotify(modify(value)); 65 | } 66 | -------------------------------------------------------------------------------- /lib/src/util/cube_navigation_mixin.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/src/actions/navigation_cube_action.dart'; 2 | import 'package:cubes/src/cube.dart'; 3 | import 'package:flutter/widgets.dart'; 4 | 5 | /// 6 | /// Created by 7 | /// 8 | /// ─▄▀─▄▀ 9 | /// ──▀──▀ 10 | /// █▀▀▀▀▀█▄ 11 | /// █░░░░░█─█ 12 | /// ▀▄▄▄▄▄▀▀ 13 | /// 14 | /// Rafaelbarbosatec 15 | /// on 14/02/22 16 | 17 | mixin CubeNavigation on Cube { 18 | void navToNamed( 19 | String routeName, { 20 | Object? arguments, 21 | ValueChanged? onResult, 22 | }) { 23 | this.sendAction( 24 | NavigationCubeAction.pushNamed( 25 | routeName: routeName, 26 | arguments: arguments, 27 | onResult: onResult, 28 | ), 29 | ); 30 | } 31 | 32 | void navToNamedAndRemoveUntil( 33 | String routeName, 34 | RoutePredicate predicate, { 35 | Object? arguments, 36 | ValueChanged? onResult, 37 | }) { 38 | this.sendAction( 39 | NavigationCubeAction.pushNamedAndRemoveUntil( 40 | routeName: routeName, 41 | arguments: arguments, 42 | predicate: predicate, 43 | onResult: onResult, 44 | ), 45 | ); 46 | } 47 | 48 | void navToNamedReplacement( 49 | String routeName, { 50 | Object? arguments, 51 | ValueChanged? onResult, 52 | }) { 53 | this.sendAction( 54 | NavigationCubeAction.pushReplacementNamed( 55 | routeName: routeName, 56 | arguments: arguments, 57 | onResult: onResult, 58 | ), 59 | ); 60 | } 61 | 62 | void navPop([T? result]) { 63 | this.sendAction( 64 | NavigationCubeAction.pop(result: result), 65 | ); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /lib/src/util/cube_provider.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../cube.dart'; 4 | 5 | /// Used to provide `Cube` 6 | class CubeProvider extends InheritedWidget { 7 | final C cube; 8 | 9 | /// CubeProvider constructor 10 | CubeProvider({ 11 | Key? key, 12 | required this.cube, 13 | required Widget child, 14 | }) : super(key: key, child: child); 15 | 16 | /// Used to return Cube that was provided 17 | static C? of(BuildContext context) { 18 | return context.dependOnInheritedWidgetOfExactType>()?.cube; 19 | } 20 | 21 | @override 22 | bool updateShouldNotify(covariant CubeProvider oldWidget) => 23 | oldWidget.cube != cube; 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/util/debouncer.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/foundation.dart'; 4 | 5 | /// Class used to apply "debounce" 6 | class Debounce { 7 | final Duration delay; 8 | Timer? _timer; 9 | 10 | /// Debounce constructor 11 | Debounce(this.delay); 12 | 13 | /// Method used to call method and reset time if it is not finished 14 | void call(VoidCallback action) { 15 | _timer?.cancel(); 16 | _timer = Timer(delay, action); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/src/util/extensions/bool_extensions.dart: -------------------------------------------------------------------------------- 1 | import '../functions.dart'; 2 | 3 | /// 4 | /// Created by 5 | /// 6 | /// ─▄▀─▄▀ 7 | /// ──▀──▀ 8 | /// █▀▀▀▀▀█▄ 9 | /// █░░░░░█─█ 10 | /// ▀▄▄▄▄▄▀▀ 11 | /// 12 | /// Rafaelbarbosatec 13 | /// on 14/02/22 14 | 15 | extension BoolExtensions on bool { 16 | T? conditional({ 17 | required T match, 18 | T? notMatch, 19 | }) => 20 | genericConditional( 21 | condition: this, 22 | match: match, 23 | notMatch: notMatch, 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /lib/src/util/extensions/build_context_extensions.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import '../../../cubes.dart'; 4 | 5 | extension BuildContextExtensions on BuildContext { 6 | Future goToNamed( 7 | String routeName, { 8 | Object? arguments, 9 | }) { 10 | return Navigator.pushNamed(this, routeName, arguments: arguments); 11 | } 12 | 13 | Future goToNamedAndRemoveUntil( 14 | String routeName, 15 | RoutePredicate predicate, { 16 | Object? arguments, 17 | }) { 18 | return Navigator.pushNamedAndRemoveUntil( 19 | this, 20 | routeName, 21 | predicate, 22 | arguments: arguments, 23 | ); 24 | } 25 | 26 | Future goToNamedReplacement( 27 | String routeName, { 28 | Object? arguments, 29 | }) { 30 | return Navigator.pushReplacementNamed( 31 | this, 32 | routeName, 33 | arguments: arguments, 34 | ); 35 | } 36 | 37 | Future goTo( 38 | WidgetBuilder builder, { 39 | RouteSettings? settings, 40 | bool fullscreenDialog = false, 41 | }) { 42 | return Navigator.push( 43 | this, 44 | MaterialPageRoute( 45 | builder: builder, 46 | fullscreenDialog: fullscreenDialog, 47 | settings: settings, 48 | ), 49 | ); 50 | } 51 | 52 | Future goToReplacement( 53 | WidgetBuilder builder, { 54 | RouteSettings? settings, 55 | bool fullscreenDialog = false, 56 | }) { 57 | return Navigator.pushReplacement( 58 | this, 59 | MaterialPageRoute( 60 | builder: builder, 61 | fullscreenDialog: fullscreenDialog, 62 | settings: settings, 63 | ), 64 | ); 65 | } 66 | 67 | Future goToAndRemoveUntil( 68 | WidgetBuilder builder, 69 | RoutePredicate predicate, { 70 | RouteSettings? settings, 71 | bool fullscreenDialog = false, 72 | }) { 73 | return Navigator.pushAndRemoveUntil( 74 | this, 75 | MaterialPageRoute( 76 | builder: builder, 77 | fullscreenDialog: fullscreenDialog, 78 | settings: settings, 79 | ), 80 | predicate, 81 | ); 82 | } 83 | 84 | void pop([T? result]) { 85 | Navigator.pop(this, result); 86 | } 87 | 88 | MediaQueryData get mediaQuery => MediaQuery.of(this); 89 | EdgeInsets get padding => mediaQuery.padding; 90 | EdgeInsets get viewInsets => mediaQuery.viewInsets; 91 | 92 | Size get sizeScreen => mediaQuery.size; 93 | double get widthScreen => sizeScreen.width; 94 | double get heightScreen => sizeScreen.height; 95 | 96 | ThemeData get theme => Theme.of(this); 97 | TextTheme get textTheme => theme.textTheme; 98 | ScaffoldState get scaffold => Scaffold.of(this); 99 | 100 | ScaffoldMessengerState get scaffoldMessenger => ScaffoldMessenger.of(this); 101 | 102 | ScaffoldFeatureController showSnackBar( 103 | SnackBar snackBar, 104 | ) { 105 | return scaffoldMessenger.showSnackBar(snackBar); 106 | } 107 | 108 | void clearSnackBars() { 109 | scaffoldMessenger.clearSnackBars(); 110 | } 111 | 112 | C? getCube() => Cubes.of(this); 113 | 114 | Object? get arguments => ModalRoute.of(this)?.settings.arguments; 115 | } 116 | -------------------------------------------------------------------------------- /lib/src/util/extensions/ext.dart: -------------------------------------------------------------------------------- 1 | export 'package:cubes/src/util/extensions/bool_extensions.dart'; 2 | export 'package:cubes/src/util/extensions/build_context_extensions.dart'; 3 | export 'package:cubes/src/util/extensions/observable_value_extensions.dart'; 4 | -------------------------------------------------------------------------------- /lib/src/util/extensions/observable_value_extensions.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../../cubes.dart'; 4 | import '../../widgets/observer.dart'; 5 | 6 | /// Extension to facilitate the use of CObserver 7 | 8 | extension ObservableValueExtensions on ObservableValue { 9 | /// Use to create CObserver by ObservableValue 10 | CObserver build( 11 | ObserverBuilder builder, { 12 | bool animate = false, 13 | WhenBuild? when, 14 | AnimatedSwitcherTransitionBuilder transitionBuilder = 15 | AnimatedSwitcher.defaultTransitionBuilder, 16 | Duration duration = const Duration(milliseconds: 300), 17 | }) { 18 | return CObserver( 19 | observable: this as ObservableValue, 20 | animate: animate, 21 | transitionBuilder: transitionBuilder, 22 | duration: duration, 23 | when: when, 24 | builder: builder, 25 | ); 26 | } 27 | } 28 | 29 | /// Extension to facilitate create ObservableValue 30 | extension ObservableValueExtension on T { 31 | /// Create ObservableValue 32 | ObservableValue get obs => ObservableValue(value: this); 33 | } 34 | 35 | /// Extension to facilitate create ObservableList 36 | extension ListToObservableValue on List { 37 | /// Create ObservableList 38 | ObservableList get obs => ObservableList(value: this); 39 | } 40 | 41 | extension FeedbackControlExtensions on ObservableValue> { 42 | void show({T? data}) { 43 | modify((value) => value.copyWith(show: true, data: data)); 44 | } 45 | 46 | void hide() { 47 | modify((value) => value.copyWith(show: false)); 48 | } 49 | } 50 | 51 | extension CTextFormFieldControlExtensions 52 | on ObservableValue { 53 | String get text => value.text; 54 | set text(String text) { 55 | modify((value) => value.copyWith(text: text)); 56 | } 57 | 58 | String get error => value.error ?? ''; 59 | set error(String? error) { 60 | modify((value) => value.copyWith(error: error)); 61 | } 62 | 63 | bool get enable => value.enable; 64 | set enable(bool enable) { 65 | modify((value) => value.copyWith(enable: enable)); 66 | } 67 | 68 | bool get enableObscureText => value.obscureText; 69 | set enableObscureText(bool enable) { 70 | modify((value) => value.copyWith(obscureText: enable)); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /lib/src/util/functions.dart: -------------------------------------------------------------------------------- 1 | import '../../cubes.dart'; 2 | 3 | /// Method util uses to return anything for conditional. 4 | T? genericConditional({ 5 | required bool condition, 6 | required T match, 7 | T? notMatch, 8 | }) { 9 | return condition ? match : notMatch; 10 | } 11 | 12 | T inject({String? dependencyName}) { 13 | return Cubes.get(dependencyName: dependencyName); 14 | } 15 | -------------------------------------------------------------------------------- /lib/src/util/state_mixin.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../cubes.dart'; 4 | 5 | /// Mixin postFrame to uses in State 6 | extension StateExt on State { 7 | /// Used to update widget in next frame 8 | void postFrame(VoidCallback callback) { 9 | Future.delayed(Duration.zero, () { 10 | if (mounted) callback(); 11 | }); 12 | } 13 | } 14 | 15 | /// Mixin to user Cube in StatefulWidget 16 | mixin CubeStateMixin on State { 17 | /// Cube that will be used 18 | C? _cube; 19 | 20 | set cube(C cube) => _cube = cube; 21 | C get cube => _cube!; 22 | 23 | /// Initial data used in `cube.onReady` 24 | Object? get initData => null; 25 | 26 | @override 27 | void initState() { 28 | super.initState(); 29 | _cube = _cube ?? inject(); 30 | _cube?.addOnActionListener(_innerOnAction); 31 | postFrame(_ready); 32 | } 33 | 34 | @override 35 | void dispose() { 36 | _cube?.dispose(); 37 | removeOnActionListener(); 38 | super.dispose(); 39 | } 40 | 41 | /// Remove action listeners. 42 | void removeOnActionListener() => 43 | _cube?.removeOnActionListener(_innerOnAction); 44 | 45 | void _innerOnAction(C cube, CubeAction action) => onAction(action); 46 | 47 | /// Method tha receive action from cube. 48 | void onAction(CubeAction action); 49 | 50 | void _ready() { 51 | var data = initData ?? ModalRoute.of(context)?.settings.arguments; 52 | _cube?.onReady(data); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lib/src/widgets/animated_list_cube.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../observable/observable_list.dart'; 4 | 5 | enum TypeAnimationListEnum { add, remove } 6 | 7 | typedef AnimatedListCubeItemBuilder = Widget Function( 8 | BuildContext context, 9 | T item, 10 | Animation animation, 11 | TypeAnimationListEnum type, 12 | ); 13 | 14 | class CAnimatedList extends StatefulWidget { 15 | final AnimatedListCubeItemBuilder itemBuilder; 16 | final Axis scrollDirection; 17 | final bool reverse; 18 | final ScrollController? controller; 19 | final bool? primary; 20 | final ScrollPhysics? physics; 21 | final bool shrinkWrap; 22 | final EdgeInsetsGeometry? padding; 23 | final ObservableList observable; 24 | 25 | const CAnimatedList({ 26 | Key? key, 27 | required this.observable, 28 | required this.itemBuilder, 29 | this.scrollDirection = Axis.vertical, 30 | this.reverse = false, 31 | this.controller, 32 | this.primary, 33 | this.physics, 34 | this.shrinkWrap = false, 35 | this.padding, 36 | }) : super(key: key); 37 | 38 | @override 39 | _AnimatedListState createState() => _AnimatedListState(); 40 | } 41 | 42 | class _AnimatedListState extends State { 43 | final GlobalKey _listKey = GlobalKey(); 44 | 45 | List itemList = []; 46 | 47 | @override 48 | void initState() { 49 | itemList.addAll(widget.observable.value as Iterable); 50 | widget.observable.addListener(_listener); 51 | super.initState(); 52 | } 53 | 54 | @override 55 | void dispose() { 56 | widget.observable.removeListener(_listener); 57 | super.dispose(); 58 | } 59 | 60 | @override 61 | Widget build(BuildContext context) { 62 | return AnimatedList( 63 | key: _listKey, 64 | itemBuilder: (context, index, animation) { 65 | if (itemList.length <= index) return SizedBox.shrink(); 66 | 67 | return (widget as CAnimatedList).itemBuilder( 68 | context, 69 | itemList[index], 70 | animation, 71 | TypeAnimationListEnum.add, 72 | ); 73 | }, 74 | padding: widget.padding, 75 | scrollDirection: widget.scrollDirection, 76 | shrinkWrap: widget.shrinkWrap, 77 | controller: widget.controller, 78 | physics: widget.physics, 79 | initialItemCount: widget.observable.length, 80 | primary: widget.primary, 81 | reverse: widget.reverse, 82 | ); 83 | } 84 | 85 | void _listener() async { 86 | if (itemList.length != widget.observable.length) { 87 | for (var element in itemList) { 88 | if (!widget.observable.value.contains(element)) { 89 | final index = itemList.indexOf(element); 90 | _listKey.currentState?.removeItem( 91 | index, 92 | (context, animation) => (widget as CAnimatedList).itemBuilder( 93 | context, 94 | element, 95 | animation, 96 | TypeAnimationListEnum.remove, 97 | ), 98 | ); 99 | } 100 | } 101 | 102 | for (var element in widget.observable.value) { 103 | if (!itemList.contains(element)) { 104 | final index = widget.observable.value.indexOf(element); 105 | _listKey.currentState?.insertItem(index); 106 | } 107 | } 108 | } 109 | _refresh(); 110 | } 111 | 112 | Future _refresh() async { 113 | await Future.delayed(Duration.zero); 114 | setState(() { 115 | itemList.clear(); 116 | itemList.addAll(widget.observable.value as Iterable); 117 | }); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /lib/src/widgets/cube_consumer.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import '../../cubes.dart'; 4 | 5 | typedef AsyncCubeWidgetBuilder = Widget Function( 6 | BuildContext context, 7 | C cube, 8 | ); 9 | 10 | typedef InitCallback = Function(C cube); 11 | typedef CubeWidgetDispose = bool Function(C cube); 12 | 13 | /// Widget responsible for getting instance and providing Cube 14 | class CubeConsumer extends StatefulWidget { 15 | const CubeConsumer({ 16 | Key? key, 17 | required this.builder, 18 | this.arguments, 19 | this.cube, 20 | this.onAction, 21 | this.dispose, 22 | }) : super(key: key); 23 | 24 | final Object? arguments; 25 | final AsyncCubeWidgetBuilder builder; 26 | final OnActionChanged? onAction; 27 | final CubeWidgetDispose? dispose; 28 | final C? cube; 29 | 30 | @override 31 | _CubeConsumerState createState() => _CubeConsumerState(); 32 | } 33 | 34 | class _CubeConsumerState extends State { 35 | late C cube; 36 | 37 | @override 38 | void initState() { 39 | super.initState(); 40 | cube = cubeWidget.cube ?? inject(); 41 | cube.addOnActionListener(_onAction); 42 | postFrame(_ready); 43 | } 44 | 45 | @override 46 | void dispose() { 47 | if (cubeWidget.dispose?.call(cube) ?? true) { 48 | cube.dispose(); 49 | } 50 | cube.removeOnActionListener(_onAction); 51 | super.dispose(); 52 | } 53 | 54 | @override 55 | Widget build(BuildContext context) { 56 | return CubeProvider( 57 | cube: cube, 58 | child: cubeWidget.builder(context, cube), 59 | ); 60 | } 61 | 62 | void _onAction(C cube, CubeAction data) { 63 | postFrame(() { 64 | data.onExecute(context); 65 | cubeWidget.onAction?.call(cube, data); 66 | }); 67 | } 68 | 69 | void _ready() { 70 | cube.onReady(widget.arguments ?? context.arguments); 71 | } 72 | 73 | CubeConsumer get cubeWidget => (widget as CubeConsumer); 74 | } 75 | -------------------------------------------------------------------------------- /lib/src/widgets/cube_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../cubes.dart'; 4 | 5 | /// Widget created to replace StatelessWidget and facilitate the use of Cube 6 | /// This is responsible for getting instance and providing Cube 7 | abstract class CubeWidget extends StatelessWidget { 8 | const CubeWidget({Key? key}) : super(key: key); 9 | 10 | /// called when cube send any Action to view. 11 | // ignore: no-empty-block 12 | void onAction(BuildContext context, C cube, CubeAction action) {} 13 | 14 | /// if you want the widget to not call `dispose` in the Cube, return false 15 | bool dispose(C cube) => true; 16 | 17 | /// Arguments that will be sent to the cube through the onReady () method 18 | /// If this argument is not set, 19 | /// ModalRoute.of(context)?.settings?.Arguments will be sent 20 | Object? get arguments => null; 21 | 22 | @protected 23 | Widget buildView(BuildContext context, C cube); 24 | 25 | @override 26 | Widget build(BuildContext context) { 27 | return CubeConsumer( 28 | builder: buildView, 29 | arguments: arguments, 30 | onAction: (cube, data) => onAction(context, cube, data), 31 | dispose: dispose, 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/src/widgets/observer.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import '../observable/observable_value.dart'; 4 | import '../util/state_mixin.dart'; 5 | 6 | typedef ObserverBuilder = Widget? Function(T value); 7 | typedef WhenBuild = bool Function(T last, T next); 8 | typedef WithoutContextWidgetBuilder = Widget Function(); 9 | 10 | /// Widget responsible for building another widget 11 | /// through ObservableValue updates 12 | class CObserver extends StatefulWidget { 13 | const CObserver({ 14 | Key? key, 15 | required this.observable, 16 | required this.builder, 17 | this.emptyBuilder, 18 | this.animate = false, 19 | this.when, 20 | this.transitionBuilder = AnimatedSwitcher.defaultTransitionBuilder, 21 | this.duration = const Duration(milliseconds: 300), 22 | }) : super(key: key); 23 | 24 | final ObservableValue observable; 25 | final ObserverBuilder builder; 26 | final WithoutContextWidgetBuilder? emptyBuilder; 27 | final WhenBuild? when; 28 | final bool animate; 29 | final AnimatedSwitcherTransitionBuilder transitionBuilder; 30 | final Duration duration; 31 | 32 | @override 33 | _CObserverState createState() => _CObserverState(); 34 | } 35 | 36 | class _CObserverState extends State { 37 | @override 38 | void initState() { 39 | widget.observable.addListener(_listener); 40 | super.initState(); 41 | } 42 | 43 | @override 44 | void dispose() { 45 | widget.observable.removeListener(_listener); 46 | super.dispose(); 47 | } 48 | 49 | @override 50 | Widget build(BuildContext context) { 51 | if (widget.animate) { 52 | return AnimatedSwitcher( 53 | duration: widget.duration, 54 | transitionBuilder: widget.transitionBuilder, 55 | child: _buildChild(), 56 | ); 57 | } 58 | 59 | return _buildChild(); 60 | } 61 | 62 | Widget _buildChild() { 63 | return widgetObserver.builder(widget.observable.value) ?? 64 | (widgetObserver.emptyBuilder?.call() ?? SizedBox.shrink()); 65 | } 66 | 67 | void _listener() { 68 | final canRebuild = widgetObserver.when?.call( 69 | widget.observable.lastValue, 70 | widget.observable.value, 71 | ) ?? 72 | true; 73 | if (canRebuild) { 74 | // ignore: no-empty-block 75 | postFrame(() => setState(() {})); 76 | } 77 | } 78 | 79 | CObserver get widgetObserver => (widget as CObserver); 80 | } 81 | -------------------------------------------------------------------------------- /media/example-folders.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/media/example-folders.png -------------------------------------------------------------------------------- /media/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RafaelBarbosatec/cube/15022fb1356a96da0213eda62f4140cfaca0b4bc/media/icon.png -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: cubes 2 | description: Simple State Manager (Focusing on simplicity and rebuilding only the necessary) 3 | version: 1.5.5 4 | homepage: https://github.com/RafaelBarbosatec/cube 5 | 6 | environment: 7 | sdk: ">=2.12.0 <3.0.0" 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | 13 | get_it: ^7.2.0 14 | 15 | 16 | dev_dependencies: 17 | mocktail: any 18 | dart_code_metrics: ^4.16.0 19 | flutter_test: 20 | sdk: flutter 21 | 22 | flutter: 23 | 24 | -------------------------------------------------------------------------------- /test/injector/get_it_injector_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:cubes/src/injector/get_it_injector.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | void main() { 6 | late CInjector injector; 7 | var _counter = 0; 8 | setUp(() { 9 | injector = GetItInjector(); 10 | }); 11 | 12 | tearDown(() { 13 | _counter = 0; 14 | injector.reset(); 15 | }); 16 | 17 | test('verify return injected factory', () { 18 | injector.registerFactory((injector) { 19 | _counter++; 20 | return 'count: $_counter'; 21 | }); 22 | expect(injector.get(), 'count: 1'); 23 | expect(injector.get(), 'count: 2'); 24 | expect(injector.get(), 'count: 3'); 25 | }); 26 | 27 | test('verify return injected singleton', () { 28 | _counter++; 29 | injector.registerSingleton( 30 | 'count: $_counter', 31 | ); 32 | expect(injector.get(), 'count: 1'); 33 | expect(injector.get(), 'count: 1'); 34 | expect(injector.get(), 'count: 1'); 35 | }); 36 | 37 | test('verify return injected singleton lazy', () { 38 | injector.registerLazySingleton( 39 | (injector) { 40 | _counter++; 41 | 42 | return 'count: $_counter'; 43 | }, 44 | ); 45 | expect(injector.get(), 'count: 1'); 46 | expect(injector.get(), 'count: 1'); 47 | expect(injector.get(), 'count: 1'); 48 | }); 49 | 50 | test('verify return injected factory async', () { 51 | injector.registerFactoryAsync( 52 | (injector) async { 53 | await Future.delayed(Duration(seconds: 1)); 54 | 55 | return 'value async'; 56 | }, 57 | ); 58 | injector.getAsync().then((value) { 59 | expect(value, 'value async'); 60 | }); 61 | }); 62 | 63 | test('verify return injected singleton async', () async { 64 | injector.registerSingletonAsync( 65 | (injector) async { 66 | await Future.delayed(Duration(seconds: 1)); 67 | _counter++; 68 | 69 | return 'count: $_counter'; 70 | }, 71 | ); 72 | 73 | final r1 = await injector.getAsync(); 74 | final r2 = await injector.getAsync(); 75 | 76 | expect(r1, 'count: 1'); 77 | expect(r2, 'count: 1'); 78 | }); 79 | } 80 | -------------------------------------------------------------------------------- /test/observable/observable_list_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | 4 | void main() { 5 | late ObservableList _observableListValue; 6 | List? _valueNotify; 7 | 8 | setUp(() { 9 | _observableListValue = ObservableList(value: []); 10 | _observableListValue.addListener(() { 11 | _valueNotify = _observableListValue.value; 12 | }); 13 | }); 14 | 15 | tearDown(() { 16 | _valueNotify = null; 17 | _observableListValue.dispose(); 18 | }); 19 | 20 | test('verify initial value', () { 21 | expect(_observableListValue.value, []); 22 | }); 23 | 24 | test('verify update list', () { 25 | _observableListValue.update([3, 2, 1]); 26 | expect(_valueNotify, [3, 2, 1]); 27 | }); 28 | 29 | test('verify add value in list', () { 30 | _observableListValue.add(1); 31 | expect(_valueNotify, [1]); 32 | _observableListValue.add(3); 33 | expect(_valueNotify, [1, 3]); 34 | }); 35 | 36 | test('verify addAll in list', () { 37 | _observableListValue.addAll([3, 2, 1]); 38 | expect(_valueNotify, [3, 2, 1]); 39 | }); 40 | 41 | test('verify remove value in list', () { 42 | _observableListValue.update([3, 2, 1]); 43 | _observableListValue.remove(1); 44 | expect(_valueNotify, [3, 2]); 45 | }); 46 | 47 | test('verify clean list', () { 48 | _observableListValue.update([3, 2, 1]); 49 | expect(_valueNotify, [3, 2, 1]); 50 | _observableListValue.clear(); 51 | expect(_valueNotify, []); 52 | }); 53 | 54 | test('verify modifyitem', () { 55 | _observableListValue.update([3, 2, 1]); 56 | expect(_valueNotify, [3, 2, 1]); 57 | _observableListValue.modifyItem(0, (value) => value + 1); 58 | expect(_valueNotify, [4, 2, 1]); 59 | _observableListValue.removeAt(0); 60 | expect(_valueNotify, [2, 1]); 61 | _observableListValue.modifyItem(0, (value) => value + 3); 62 | expect(_valueNotify, [5, 1]); 63 | }); 64 | } 65 | -------------------------------------------------------------------------------- /test/observable/observable_value_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | 4 | void main() { 5 | late ObservableValue _observableValue; 6 | int? _valueNotify; 7 | setUp(() { 8 | _observableValue = ObservableValue(value: 0); 9 | _observableValue.addListener(() { 10 | _valueNotify = _observableValue.value; 11 | }); 12 | }); 13 | 14 | tearDown(() { 15 | _valueNotify = null; 16 | _observableValue.dispose(); 17 | }); 18 | 19 | test('verify initial value', () { 20 | expect(_observableValue.value, 0); 21 | }); 22 | 23 | test('verify change value with update', () { 24 | _observableValue.update(10); 25 | expect(_observableValue.value, 10); 26 | }); 27 | 28 | test('verify change value with modify', () { 29 | _observableValue.modify((value) => value + 10); 30 | expect(_observableValue.value, 10); 31 | }); 32 | 33 | test('verify lastValue', () { 34 | _observableValue.update(10); 35 | _observableValue.update(30); 36 | _observableValue.update(40); 37 | expect(_observableValue.lastValue, 30); 38 | expect(_observableValue.value, 40); 39 | }); 40 | 41 | test('verify value in listeners', () { 42 | _observableValue.update(10); 43 | expect(_valueNotify, 10); 44 | _observableValue.modify((value) => value + 10); 45 | expect(_valueNotify, 20); 46 | }); 47 | } 48 | -------------------------------------------------------------------------------- /test/widgets/cube_builder/cube_builder_robot.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:mocktail/mocktail.dart'; 5 | 6 | class ActionExample extends CubeAction {} 7 | 8 | class CubeExample extends Cube { 9 | void sendAction(CubeAction action) { 10 | super.sendAction(action); 11 | } 12 | } 13 | 14 | class MockCubeTest extends Mock implements CubeExample {} 15 | 16 | class CubeBuilderRobot { 17 | final WidgetTester tester; 18 | CubeExample? _cubeReturned; 19 | CubeAction? _actionReturnedInView; 20 | late CubeExample _cubeMock; 21 | final Map _argumentTest = { 22 | 'cube': 'Simple State Manager with dependency injection.', 23 | }; 24 | CubeBuilderRobot(this.tester); 25 | 26 | void _setupInjections({bool useMock = true}) { 27 | _cubeMock = useMock ? MockCubeTest() : CubeExample(); 28 | if (useMock) { 29 | when(() => _cubeMock.onReady(any())).thenAnswer((realInvocation) { 30 | return Future.value(); 31 | }); 32 | } 33 | Cubes.resetInjector(); 34 | Cubes.registerSingleton(_cubeMock); 35 | } 36 | 37 | Future setup({bool useMock = true}) async { 38 | _setupInjections(useMock: useMock); 39 | 40 | await tester.pumpWidget( 41 | MaterialApp( 42 | home: CubeConsumer( 43 | arguments: _argumentTest, 44 | onAction: (cube, action) { 45 | _actionReturnedInView = action; 46 | }, 47 | builder: (context, cube) { 48 | _cubeReturned = cube; 49 | 50 | return Container(); 51 | }, 52 | ), 53 | ), 54 | ); 55 | } 56 | 57 | Future assetCubeReturnedInBuilder() async { 58 | await tester.pumpAndSettle(); 59 | expect(_cubeReturned, _cubeMock); 60 | } 61 | 62 | Future assetCallOnReadyInCube() async { 63 | await tester.pumpAndSettle(); 64 | verify(() => _cubeMock.onReady(_argumentTest)).called(1); 65 | } 66 | 67 | Future assetActionSentByCube() async { 68 | await tester.pumpAndSettle(); 69 | final action = ActionExample(); 70 | _cubeMock.sendAction(action); 71 | await tester.pumpAndSettle(); 72 | expect(_actionReturnedInView, action); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/widgets/cube_builder/cube_builder_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_test/flutter_test.dart'; 2 | 3 | import 'cube_builder_robot.dart'; 4 | 5 | void main() { 6 | testWidgets('Should return cube injected', (tester) async { 7 | final robot = CubeBuilderRobot(tester); 8 | await robot.setup(); 9 | await robot.assetCubeReturnedInBuilder(); 10 | }); 11 | testWidgets('Should call onReady in cube when view is ready', (tester) async { 12 | final robot = CubeBuilderRobot(tester); 13 | await robot.setup(); 14 | await robot.assetCallOnReadyInCube(); 15 | }); 16 | testWidgets('Should receive an action in the view', (tester) async { 17 | final robot = CubeBuilderRobot(tester); 18 | await robot.setup(useMock: false); 19 | await robot.assetActionSentByCube(); 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /test/widgets/cube_widget/cube_widget_robot.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:mocktail/mocktail.dart'; 5 | 6 | import '../cube_builder/cube_builder_robot.dart'; 7 | 8 | class MockCubeTest extends Mock implements CubeExample {} 9 | 10 | class CubeWidgetExample extends CubeWidget { 11 | @override 12 | Object get arguments => CubeWidgetRobot._argumentTest; 13 | 14 | @override 15 | Widget buildView(BuildContext context, CubeExample cube) { 16 | CubeWidgetRobot.cubeReturned = cube; 17 | 18 | return Container(); 19 | } 20 | 21 | @override 22 | void onAction(BuildContext context, CubeExample cube, CubeAction action) { 23 | CubeWidgetRobot.actionReturned = action; 24 | super.onAction(context, cube, action); 25 | } 26 | } 27 | 28 | class CubeWidgetRobot { 29 | final WidgetTester tester; 30 | late CubeExample _cubeMock; 31 | CubeWidgetRobot(this.tester); 32 | static Cube? cubeReturned; 33 | static CubeAction? actionReturned; 34 | static final Map _argumentTest = { 35 | 'cube': 'Simple State Manager with dependency injection', 36 | }; 37 | 38 | Future setup({bool useMock = true}) async { 39 | _setupInjections(useMock: useMock); 40 | await tester.pumpWidget( 41 | MaterialApp( 42 | home: CubeWidgetExample(), 43 | ), 44 | ); 45 | } 46 | 47 | void _setupInjections({bool useMock = true}) { 48 | _cubeMock = useMock ? MockCubeTest() : CubeExample(); 49 | if (useMock) { 50 | when(() => _cubeMock.onReady(any())).thenAnswer((realInvocation) { 51 | return Future.value(); 52 | }); 53 | } 54 | Cubes.resetInjector(); 55 | Cubes.registerSingleton(_cubeMock); 56 | } 57 | 58 | Future assetCubeReturnedInBuilder() async { 59 | await tester.pumpAndSettle(); 60 | expect(CubeWidgetRobot.cubeReturned, _cubeMock); 61 | } 62 | 63 | Future assetCallOnReadyInCube() async { 64 | await tester.pumpAndSettle(); 65 | verify(() => _cubeMock.onReady(_argumentTest)).called(1); 66 | } 67 | 68 | Future assetActionSentByCube() async { 69 | await tester.pumpAndSettle(); 70 | final action = ActionExample(); 71 | _cubeMock.sendAction(action); 72 | await tester.pumpAndSettle(); 73 | expect(CubeWidgetRobot.actionReturned, action); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /test/widgets/cube_widget/cube_widget_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_test/flutter_test.dart'; 2 | 3 | import 'cube_widget_robot.dart'; 4 | 5 | void main() { 6 | testWidgets('Should return cube injected', (tester) async { 7 | final robot = CubeWidgetRobot(tester); 8 | await robot.setup(); 9 | await robot.assetCubeReturnedInBuilder(); 10 | }); 11 | 12 | testWidgets('Should call onReady in cube', (tester) async { 13 | final robot = CubeWidgetRobot(tester); 14 | await robot.setup(); 15 | await robot.assetCallOnReadyInCube(); 16 | }); 17 | 18 | testWidgets('Should receive an action in the view', (tester) async { 19 | final robot = CubeWidgetRobot(tester); 20 | await robot.setup(useMock: false); 21 | await robot.assetActionSentByCube(); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /test/widgets/observer/observer_robot.dart: -------------------------------------------------------------------------------- 1 | import 'package:cubes/cubes.dart'; 2 | import 'package:cubes/src/widgets/observer.dart'; 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | 6 | class ObserverRobot { 7 | final WidgetTester tester; 8 | int? _valueReturnedInBuilder; 9 | WhenBuild? whenBuild; 10 | final ObservableValue _count = ObservableValue(value: 0); 11 | 12 | ObserverRobot(this.tester); 13 | 14 | Future setup() async { 15 | await tester.pumpWidget( 16 | MaterialApp( 17 | home: CObserver( 18 | observable: _count, 19 | when: (lastValue, newValue) { 20 | return whenBuild?.call(lastValue, newValue) ?? true; 21 | }, 22 | builder: (value) { 23 | _valueReturnedInBuilder = value; 24 | 25 | return Container( 26 | child: Text(value.toString()), 27 | ); 28 | }, 29 | ), 30 | ), 31 | ); 32 | } 33 | 34 | Future assetInitialValue() async { 35 | await tester.pumpAndSettle(); 36 | expect(_valueReturnedInBuilder, 0); 37 | } 38 | 39 | void changeValueWithUpdate(int value) { 40 | _count.update(value); 41 | } 42 | 43 | void incrementValueWithModify(int increment) { 44 | _count.modify((value) => value + increment); 45 | } 46 | 47 | Future assetValue(int value) async { 48 | await tester.pumpAndSettle(); 49 | expect(_valueReturnedInBuilder, value); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/widgets/observer/observer_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_test/flutter_test.dart'; 2 | 3 | import 'observer_robot.dart'; 4 | 5 | void main() { 6 | testWidgets('Should render with initial value', (tester) async { 7 | final robot = ObserverRobot(tester); 8 | await robot.setup(); 9 | await robot.assetInitialValue(); 10 | }); 11 | 12 | testWidgets('Should update render with new value', (tester) async { 13 | final robot = ObserverRobot(tester); 14 | await robot.setup(); 15 | robot.changeValueWithUpdate(25); 16 | await robot.assetValue(25); 17 | }); 18 | 19 | // ignore: lines_longer_than_80_chars 20 | testWidgets( 21 | 'Should update render with new value using modify', 22 | (tester) async { 23 | final robot = ObserverRobot(tester); 24 | await robot.setup(); 25 | robot.incrementValueWithModify(25); 26 | robot.incrementValueWithModify(5); 27 | await robot.assetValue(30); 28 | }, 29 | ); 30 | 31 | testWidgets( 32 | 'Should note update render when not accept in WhenBuild', 33 | (tester) async { 34 | final robot = ObserverRobot(tester); 35 | await robot.setup(); 36 | robot.whenBuild = ((lastV, newV) { 37 | return (newV - lastV) == 1; 38 | }); 39 | robot.changeValueWithUpdate(5); 40 | await robot.assetValue(0); 41 | robot.changeValueWithUpdate(6); 42 | await robot.assetValue(6); 43 | }, 44 | ); 45 | } 46 | --------------------------------------------------------------------------------