From 15e8fb0bc906c211726e9e89a77380bcbd47b2f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BChler?= Date: Tue, 1 Aug 2023 12:55:47 +0200 Subject: [PATCH] feat(fluorflow): initial version of the released framework MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This initializes the FluorFlow framework and the generator companion. Signed-off-by: Christoph Bühler --- .github/test__.__yml | 33 + .github/workflows/release.yml | 37 + .gitignore | 3 + .releaserc.json | 43 + LICENSE | 201 +++ README.md | 26 + melos.yaml | 44 + packages/fluorflow/.gitignore | 34 + packages/fluorflow/.metadata | 10 + packages/fluorflow/.pubignore | 4 + packages/fluorflow/CHANGELOG.md | 1 + packages/fluorflow/LICENSE | 201 +++ packages/fluorflow/README.md | 203 +++ packages/fluorflow/analysis_options.yaml | 15 + packages/fluorflow/bin/fluorflow.dart | 20 + packages/fluorflow/example/.gitignore | 48 + packages/fluorflow/example/.metadata | 30 + packages/fluorflow/example/README.md | 16 + .../fluorflow/example/analysis_options.yaml | 29 + packages/fluorflow/example/ios/.gitignore | 34 + .../ios/Flutter/AppFrameworkInfo.plist | 26 + .../example/ios/Flutter/Debug.xcconfig | 1 + .../example/ios/Flutter/Release.xcconfig | 1 + .../ios/Runner.xcodeproj/project.pbxproj | 613 ++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/WorkspaceSettings.xcsettings | 8 + .../xcshareddata/xcschemes/Runner.xcscheme | 98 ++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/WorkspaceSettings.xcsettings | 8 + .../example/ios/Runner/AppDelegate.swift | 13 + .../AppIcon.appiconset/Contents.json | 122 ++ .../Icon-App-1024x1024@1x.png | Bin 0 -> 10932 bytes .../AppIcon.appiconset/Icon-App-20x20@1x.png | Bin 0 -> 295 bytes .../AppIcon.appiconset/Icon-App-20x20@2x.png | Bin 0 -> 406 bytes .../AppIcon.appiconset/Icon-App-20x20@3x.png | Bin 0 -> 450 bytes .../AppIcon.appiconset/Icon-App-29x29@1x.png | Bin 0 -> 282 bytes .../AppIcon.appiconset/Icon-App-29x29@2x.png | Bin 0 -> 462 bytes .../AppIcon.appiconset/Icon-App-29x29@3x.png | Bin 0 -> 704 bytes .../AppIcon.appiconset/Icon-App-40x40@1x.png | Bin 0 -> 406 bytes .../AppIcon.appiconset/Icon-App-40x40@2x.png | Bin 0 -> 586 bytes .../AppIcon.appiconset/Icon-App-40x40@3x.png | Bin 0 -> 862 bytes .../AppIcon.appiconset/Icon-App-60x60@2x.png | Bin 0 -> 862 bytes .../AppIcon.appiconset/Icon-App-60x60@3x.png | Bin 0 -> 1674 bytes .../AppIcon.appiconset/Icon-App-76x76@1x.png | Bin 0 -> 762 bytes .../AppIcon.appiconset/Icon-App-76x76@2x.png | Bin 0 -> 1226 bytes .../Icon-App-83.5x83.5@2x.png | Bin 0 -> 1418 bytes .../LaunchImage.imageset/Contents.json | 23 + .../LaunchImage.imageset/LaunchImage.png | Bin 0 -> 68 bytes .../LaunchImage.imageset/LaunchImage@2x.png | Bin 0 -> 68 bytes .../LaunchImage.imageset/LaunchImage@3x.png | Bin 0 -> 68 bytes .../LaunchImage.imageset/README.md | 5 + .../Runner/Base.lproj/LaunchScreen.storyboard | 37 + .../ios/Runner/Base.lproj/Main.storyboard | 26 + .../fluorflow/example/ios/Runner/Info.plist | 51 + .../ios/Runner/Runner-Bridging-Header.h | 1 + .../example/ios/RunnerTests/RunnerTests.swift | 12 + packages/fluorflow/example/justfile | 6 + .../bottom_sheets/greeting_bottom_sheet.dart | 37 + .../example/lib/dialogs/red_dialog.dart | 35 + packages/fluorflow/example/lib/main.dart | 29 + .../fluorflow/example/lib/services/demo.dart | 35 + .../example/lib/views/detail/detail_view.dart | 44 + .../lib/views/detail/detail_viewmodel.dart | 12 + .../example/lib/views/home/home_view.dart | 39 + .../lib/views/home/home_viewmodel.dart | 21 + packages/fluorflow/example/pubspec.yaml | 30 + packages/fluorflow/lib/annotations.dart | 18 + packages/fluorflow/lib/fluorflow.dart | 17 + .../src/annotations/bottom_sheet_config.dart | 23 + .../lib/src/annotations/dialog_config.dart | 22 + .../lib/src/annotations/injectable.dart | 134 ++ .../lib/src/annotations/routable.dart | 46 + .../lib/src/bottom_sheets/bottom_sheet.dart | 28 + .../bottom_sheets/bottom_sheet_service.dart | 32 + .../bottom_sheets/simple_bottom_sheet.dart | 18 + packages/fluorflow/lib/src/cli/base.dart | 9 + packages/fluorflow/lib/src/cli/config.dart | 24 + packages/fluorflow/lib/src/cli/generate.dart | 18 + .../fluorflow/lib/src/cli/generate/view.dart | 228 +++ .../fluorflow/lib/src/dialogs/dialog.dart | 24 + .../lib/src/dialogs/dialog_service.dart | 28 + .../lib/src/dialogs/simple_dialog.dart | 13 + .../fluorflow/lib/src/extensions/library.dart | 10 + .../fluorflow/lib/src/locator/locator.dart | 7 + .../src/navigation/navigation_service.dart | 111 ++ .../src/navigation/page_route_builder.dart | 199 +++ .../lib/src/navigation/route_builder.dart | 38 + .../lib/src/navigation/route_factory.dart | 8 + .../fluorflow/lib/src/overlays/completer.dart | 21 + .../lib/src/overlays/noop_viewmodel.dart | 4 + .../fluorflow/lib/src/overlays/overlay.dart | 12 + .../lib/src/overlays/simple_overlay.dart | 33 + .../lib/src/viewmodels/base_viewmodel.dart | 99 ++ .../lib/src/viewmodels/data_viewmodel.dart | 102 ++ .../lib/src/viewmodels/viewmodel.dart | 28 + .../lib/src/views/fluorflow_view.dart | 65 + packages/fluorflow/pubspec.yaml | 31 + .../test/views/fluorflow_view_test.dart | 36 + packages/fluorflow_generator/.gitignore | 7 + packages/fluorflow_generator/.pubignore | 4 + packages/fluorflow_generator/CHANGELOG.md | 1 + packages/fluorflow_generator/LICENSE | 201 +++ packages/fluorflow_generator/README.md | 161 ++ .../fluorflow_generator/analysis_options.yaml | 15 + packages/fluorflow_generator/build.yaml | 63 + .../lib/fluorflow_generator.dart | 19 + .../lib/src/builder/bottom_sheet_builder.dart | 161 ++ .../lib/src/builder/dialog_builder.dart | 177 +++ .../lib/src/builder/locator_builder.dart | 459 ++++++ .../lib/src/builder/router_builder.dart | 261 ++++ .../lib/src/builder/test_locator_builder.dart | 215 +++ .../fluorflow_generator/lib/src/utils.dart | 66 + packages/fluorflow_generator/pubspec.yaml | 28 + .../builder/bottom_sheet_builder_test.dart | 1192 ++++++++++++++ .../test/builder/dialog_builder_test.dart | 1367 +++++++++++++++++ .../test/builder/locator_builder_test.dart | 1102 +++++++++++++ .../test/builder/router_builder_test.dart | 1232 +++++++++++++++ .../builder/test_locator_builder_test.dart | 1097 +++++++++++++ pubspec.lock | 325 ++++ pubspec.yaml | 8 + 122 files changed, 12042 insertions(+) create mode 100644 .github/test__.__yml create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 .releaserc.json create mode 100644 LICENSE create mode 100644 README.md create mode 100644 melos.yaml create mode 100644 packages/fluorflow/.gitignore create mode 100644 packages/fluorflow/.metadata create mode 100644 packages/fluorflow/.pubignore create mode 100644 packages/fluorflow/CHANGELOG.md create mode 100644 packages/fluorflow/LICENSE create mode 100644 packages/fluorflow/README.md create mode 100644 packages/fluorflow/analysis_options.yaml create mode 100644 packages/fluorflow/bin/fluorflow.dart create mode 100644 packages/fluorflow/example/.gitignore create mode 100644 packages/fluorflow/example/.metadata create mode 100644 packages/fluorflow/example/README.md create mode 100644 packages/fluorflow/example/analysis_options.yaml create mode 100644 packages/fluorflow/example/ios/.gitignore create mode 100644 packages/fluorflow/example/ios/Flutter/AppFrameworkInfo.plist create mode 100644 packages/fluorflow/example/ios/Flutter/Debug.xcconfig create mode 100644 packages/fluorflow/example/ios/Flutter/Release.xcconfig create mode 100644 packages/fluorflow/example/ios/Runner.xcodeproj/project.pbxproj create mode 100644 packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings create mode 100644 packages/fluorflow/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme create mode 100644 packages/fluorflow/example/ios/Runner.xcworkspace/contents.xcworkspacedata create mode 100644 packages/fluorflow/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 packages/fluorflow/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings create mode 100644 packages/fluorflow/example/ios/Runner/AppDelegate.swift create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png create mode 100644 packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md create mode 100644 packages/fluorflow/example/ios/Runner/Base.lproj/LaunchScreen.storyboard create mode 100644 packages/fluorflow/example/ios/Runner/Base.lproj/Main.storyboard create mode 100644 packages/fluorflow/example/ios/Runner/Info.plist create mode 100644 packages/fluorflow/example/ios/Runner/Runner-Bridging-Header.h create mode 100644 packages/fluorflow/example/ios/RunnerTests/RunnerTests.swift create mode 100644 packages/fluorflow/example/justfile create mode 100644 packages/fluorflow/example/lib/bottom_sheets/greeting_bottom_sheet.dart create mode 100644 packages/fluorflow/example/lib/dialogs/red_dialog.dart create mode 100644 packages/fluorflow/example/lib/main.dart create mode 100644 packages/fluorflow/example/lib/services/demo.dart create mode 100644 packages/fluorflow/example/lib/views/detail/detail_view.dart create mode 100644 packages/fluorflow/example/lib/views/detail/detail_viewmodel.dart create mode 100644 packages/fluorflow/example/lib/views/home/home_view.dart create mode 100644 packages/fluorflow/example/lib/views/home/home_viewmodel.dart create mode 100644 packages/fluorflow/example/pubspec.yaml create mode 100644 packages/fluorflow/lib/annotations.dart create mode 100644 packages/fluorflow/lib/fluorflow.dart create mode 100644 packages/fluorflow/lib/src/annotations/bottom_sheet_config.dart create mode 100644 packages/fluorflow/lib/src/annotations/dialog_config.dart create mode 100644 packages/fluorflow/lib/src/annotations/injectable.dart create mode 100644 packages/fluorflow/lib/src/annotations/routable.dart create mode 100644 packages/fluorflow/lib/src/bottom_sheets/bottom_sheet.dart create mode 100644 packages/fluorflow/lib/src/bottom_sheets/bottom_sheet_service.dart create mode 100644 packages/fluorflow/lib/src/bottom_sheets/simple_bottom_sheet.dart create mode 100644 packages/fluorflow/lib/src/cli/base.dart create mode 100644 packages/fluorflow/lib/src/cli/config.dart create mode 100644 packages/fluorflow/lib/src/cli/generate.dart create mode 100644 packages/fluorflow/lib/src/cli/generate/view.dart create mode 100644 packages/fluorflow/lib/src/dialogs/dialog.dart create mode 100644 packages/fluorflow/lib/src/dialogs/dialog_service.dart create mode 100644 packages/fluorflow/lib/src/dialogs/simple_dialog.dart create mode 100644 packages/fluorflow/lib/src/extensions/library.dart create mode 100644 packages/fluorflow/lib/src/locator/locator.dart create mode 100644 packages/fluorflow/lib/src/navigation/navigation_service.dart create mode 100644 packages/fluorflow/lib/src/navigation/page_route_builder.dart create mode 100644 packages/fluorflow/lib/src/navigation/route_builder.dart create mode 100644 packages/fluorflow/lib/src/navigation/route_factory.dart create mode 100644 packages/fluorflow/lib/src/overlays/completer.dart create mode 100644 packages/fluorflow/lib/src/overlays/noop_viewmodel.dart create mode 100644 packages/fluorflow/lib/src/overlays/overlay.dart create mode 100644 packages/fluorflow/lib/src/overlays/simple_overlay.dart create mode 100644 packages/fluorflow/lib/src/viewmodels/base_viewmodel.dart create mode 100644 packages/fluorflow/lib/src/viewmodels/data_viewmodel.dart create mode 100644 packages/fluorflow/lib/src/viewmodels/viewmodel.dart create mode 100644 packages/fluorflow/lib/src/views/fluorflow_view.dart create mode 100644 packages/fluorflow/pubspec.yaml create mode 100644 packages/fluorflow/test/views/fluorflow_view_test.dart create mode 100644 packages/fluorflow_generator/.gitignore create mode 100644 packages/fluorflow_generator/.pubignore create mode 100644 packages/fluorflow_generator/CHANGELOG.md create mode 100644 packages/fluorflow_generator/LICENSE create mode 100644 packages/fluorflow_generator/README.md create mode 100644 packages/fluorflow_generator/analysis_options.yaml create mode 100644 packages/fluorflow_generator/build.yaml create mode 100644 packages/fluorflow_generator/lib/fluorflow_generator.dart create mode 100644 packages/fluorflow_generator/lib/src/builder/bottom_sheet_builder.dart create mode 100644 packages/fluorflow_generator/lib/src/builder/dialog_builder.dart create mode 100644 packages/fluorflow_generator/lib/src/builder/locator_builder.dart create mode 100644 packages/fluorflow_generator/lib/src/builder/router_builder.dart create mode 100644 packages/fluorflow_generator/lib/src/builder/test_locator_builder.dart create mode 100644 packages/fluorflow_generator/lib/src/utils.dart create mode 100644 packages/fluorflow_generator/pubspec.yaml create mode 100644 packages/fluorflow_generator/test/builder/bottom_sheet_builder_test.dart create mode 100644 packages/fluorflow_generator/test/builder/dialog_builder_test.dart create mode 100644 packages/fluorflow_generator/test/builder/locator_builder_test.dart create mode 100644 packages/fluorflow_generator/test/builder/router_builder_test.dart create mode 100644 packages/fluorflow_generator/test/builder/test_locator_builder_test.dart create mode 100644 pubspec.lock create mode 100644 pubspec.yaml diff --git a/.github/test__.__yml b/.github/test__.__yml new file mode 100644 index 0000000..9e2387c --- /dev/null +++ b/.github/test__.__yml @@ -0,0 +1,33 @@ +name: Test Package + +on: + pull_request: + branches: + - '**' + push: + branches: + - main # until proper release is done. + workflow_dispatch: + +jobs: + lint_and_test: + name: Linting and Testing + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: subosito/flutter-action@v2 + with: + channel: stable + - run: flutter pub get + - run: dart format --fix --set-exit-if-changed . + - run: dart analyze + - run: dart test + # - name: Setup LCOV + # uses: hrishikesh-kadam/setup-lcov@v1 + # - name: Report code coverage + # uses: zgosalvez/github-actions-report-lcov@v3 + # with: + # coverage-files: coverage/lcov*.info + # artifact-name: code-coverage-report + # github-token: ${{ secrets.GITHUB_TOKEN }} + # update-comment: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..35aeefb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release Package + +on: + push: + branches: + - main + +jobs: + package_and_publish: + name: Package and Publish + runs-on: ubuntu-latest + permissions: + contents: 'read' + id-token: 'write' + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.DEPLOY_TOKEN }} + - uses: google-github-actions/auth@v2 + with: + credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' + - uses: dart-lang/setup-dart@v1 + with: + sdk: stable + - uses: subosito/flutter-action@v2 + with: + channel: stable + - run: gcloud auth print-identity-token --audiences=https://pub.dev | dart pub token add https://pub.dev + - name: release + uses: cycjimmy/semantic-release-action@v3 + with: + extra_plugins: | + @semantic-release/exec + @semantic-release/git + @semantic-release/changelog + env: + GITHUB_TOKEN: ${{ secrets.DEPLOY_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..70caf70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.dart_tool/ +*.iml +pubspec_overrides.yaml diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..70e4ade --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,43 @@ +{ + "$schema": "https://json.schemastore.org/semantic-release", + "branches": ["main"], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/changelog", + { + "changelogFile": "packages/fluorflow/CHANGELOG.md" + } + ], + [ + "@semantic-release/changelog", + { + "changelogFile": "packages/fluorflow_generator/CHANGELOG.md" + } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "sed -i 's/^version: .*$/version: ${nextRelease.version}/' pubspec.yaml", + "publishCmd": "flutter pub publish -f", + "execCwd": "packages/fluorflow" + } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "sed -i 's/^version: .*$/version: ${nextRelease.version}/' pubspec.yaml", + "publishCmd": "dart pub publish -f", + "execCwd": "packages/fluorflow_generator" + } + ], + [ + "@semantic-release/git", + { + "assets": ["packages/*/CHANGELOG.md", "packages/*/pubspec.yaml"] + } + ], + "@semantic-release/github" + ] +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..03c4b90 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [2024] [smartive AG] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..27c0ac4 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Fluorflow + +This is the repository of "fluorflow". An MVVM framework for Flutter applications. +It is heavily inspired by [Stacked](https://pub.dev/packages/stacked). +(It is actually born out of stacked) + +The name was generated by ChatGPT, there you have it :-D + +This repository is a "melos" monorepo. It contains the following packages: + +- [fluorflow](packages/fluorflow/): the mvvm framework +- [fluorflow_generator](packages/fluorflow_generator/): the code generator for the framework + +In theory, you do not need the generator, however, it is highly recommended to use it. +It generates dependency injection code, routing, bottom sheets, dialogs, everything +you use in the app. Head over to the specific readme files in the packages for more information. + +## Development + +Checkout this repository and use [`melos`](https://melos.invertase.dev/) +to manage the packages. + +- `dart pub global activate melos` +- `melos bootstrap` + +And you are ready to go. diff --git a/melos.yaml b/melos.yaml new file mode 100644 index 0000000..b71ad1d --- /dev/null +++ b/melos.yaml @@ -0,0 +1,44 @@ +name: fluorflow + +repository: https://github.com/smartive/fluorflow + +packages: + - packages/fluorflow + - packages/fluorflow_generator + +scripts: + build_runner: + description: Run build_runner + exec: dart run build_runner build --delete-conflicting-outputs + packageFilters: + dependsOn: + - build_runner + + lint: + description: Run static analysis and code style checks + run: dart analyze && dart format --fix --set-exit-if-changed . + exec: + failFast: true + + test: + run: melos run test:dart && melos run test:flutter + + test:dart: + description: Run dart tests + run: dart test + packageFilters: + flutter: false + exec: + failFast: true + + test:flutter: + description: Run flutter tests + run: flutter test + packageFilters: + flutter: true + exec: + failFast: true + +ide: + intellij: + enabled: false diff --git a/packages/fluorflow/.gitignore b/packages/fluorflow/.gitignore new file mode 100644 index 0000000..15a0a4f --- /dev/null +++ b/packages/fluorflow/.gitignore @@ -0,0 +1,34 @@ +!bin/ + +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +*.mocks.dart + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/packages/fluorflow/.metadata b/packages/fluorflow/.metadata new file mode 100644 index 0000000..fa347fc --- /dev/null +++ b/packages/fluorflow/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + channel: stable + +project_type: package diff --git a/packages/fluorflow/.pubignore b/packages/fluorflow/.pubignore new file mode 100644 index 0000000..f90263b --- /dev/null +++ b/packages/fluorflow/.pubignore @@ -0,0 +1,4 @@ +.dart_tool/ +test/ +pubspec.lock +analysis_options.yaml diff --git a/packages/fluorflow/CHANGELOG.md b/packages/fluorflow/CHANGELOG.md new file mode 100644 index 0000000..8ab98eb --- /dev/null +++ b/packages/fluorflow/CHANGELOG.md @@ -0,0 +1 @@ +# 0.0.0-development diff --git a/packages/fluorflow/LICENSE b/packages/fluorflow/LICENSE new file mode 100644 index 0000000..03c4b90 --- /dev/null +++ b/packages/fluorflow/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [2024] [smartive AG] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/fluorflow/README.md b/packages/fluorflow/README.md new file mode 100644 index 0000000..8551513 --- /dev/null +++ b/packages/fluorflow/README.md @@ -0,0 +1,203 @@ +# FluorFlow + +FluorFlow is a dart / flutter package for +[MVVM UI architecture](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel). +It is heavily inspired by [Stacked](https://pub.dev/packages/stacked). + +## Getting started + +After adding the package to your `pubspec.yaml` file, you can start using it by +modifying your `main.dart` file as follows: + +```dart +void main() async { + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'FluorFlow Demo', + theme: ThemeData( + colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + useMaterial3: true, + ), + // This is the important part for routing + initialRoute: AppRoute.homeView.path, + onGenerateRoute: onGenerateRoute, + navigatorKey: NavigationService.navigatorKey, + navigatorObservers: [NavigationService.observer()], + ); + } +} +``` + +Especially the part for routing is important (if you use FluorFlow views and routing): + +```dart +initialRoute: AppRoute.homeView.path, +onGenerateRoute: onGenerateRoute, +navigatorKey: NavigationService.navigatorKey, +navigatorObservers: [NavigationService.observer()], +``` + +This enables the routing system of FluorFlow (which uses GetX underneath). + +The other parts of the material app can be as you wish. + +## Views + +Creating views with view models has the advantage that you can separate the business logic +from the presentation of the view itself. This makes the code more readable and maintainable. +Further, you can just test your view models without the need of a UI test. +If UI testing is still needed, you can just fire up the whole view and test the UI anyway. +However, most of the time the business logic is the most important part of the app and should +be tested well. + +To create a view with a view model, you can use the following example code: + +```dart +final class HomeViewModel extends BaseViewModel { + final _navService = locator(); + + var _counter = 0; + int get counter => _counter; + + void increment() { + _counter++; + notifyListeners(); + } + + void goToDetail() => _navService.navigateToDetailView(); +} + +@Routable() +final class HomeView extends FluorFlowView { + const HomeView({super.key}); + + @override + Widget builder( + BuildContext context, HomeViewModel viewModel, Widget? child) => + Scaffold( + appBar: AppBar( + title: const Text('Home'), + ), + body: Center( + child: const Text('Show Dialog'), + ), + ); + + @override + HomeViewModel viewModelBuilder(BuildContext context) => HomeViewModel(); +} +``` + +The `@Routable` annotation is important for the routing system of FluorFlow. It is used to +generate the `AppRoute` enum and create extension methods on the `NavigationService`. + +## Dependency Injection + +FluorFlow uses the [get_it](https://pub.dev/packages/get_it) package for dependency injection. +In combination with the FluorFlow generator, you can easily inject your dependencies in a +`setupLocator` method and use them in your app. + +The following example assumes that you use the `fluorflow_generator` (with `build_runner`) +to generate the `app.locator.dart` file. + +```dart +// service.dart + +@LazySingleton() +class Service { + // implementation +} + +// main.dart +import 'app.locator.dart'; + +void main() async { + await setupLocator(); + runApp(const MyApp()); +} +``` + +In your app, you can then use the provided locator via: + +```dart +import 'package:fluorflow/fluorflow.dart'; + +final svc = locator(); +//... +``` + +There are several possible types of injection: + +- Singleton +- LazySingleton +- AsyncSingleton +- Factory (with up to two parameters) +- CustomLocatorFunction (for custom injection and functions) + +## Dialogs / Bottom Sheets + +A bottom sheet can be created with or without a view model. +The simple variant just defaults to a internal `NoopViewModel` that has no +further methods attached. + +An example of a bottom sheet is: + +```dart +final class GreetingBottomSheet extends FluorFlowSimpleBottomSheet { + const GreetingBottomSheet({super.key, required super.completer}); + + @override + Widget build(BuildContext context) => Scaffold( + backgroundColor: Colors.amber[200], + appBar: AppBar( + title: const Text('Bottom Sheet'), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('A Bottom Sheet'), + const SizedBox(height: 36), + ElevatedButton( + onPressed: completer.confirm, + child: const Text('Close'), + ), + ], + ), + ), + ); +} +``` + +Bottom sheets are shown via the `BottomSheetService` that has extension methods +attached for each bottom sheet. Parameters of sheets are taken into account +when used with the fluorflow generator. + +Dialogs work exactly the same way as bottom sheets, but are shown via the +`DialogService` and have another base class. + +## CLI + +FluorFlow comes with a CLI that can be used to generate views and other things. +Use `dart run fluorflow` to see the available commands. + +To change configuration of the CLI (especially the biased options of the generator), +use the `fluorflow` key in your `pubspec.yaml` file. + +```yaml +fluorflow: + view_directory: lib/my_views + test_view_directory: test/my_views +``` + +Defaults are: + +- `view_directory`: `lib/ui/views` +- `test_view_directory`: `test/ui/views` diff --git a/packages/fluorflow/analysis_options.yaml b/packages/fluorflow/analysis_options.yaml new file mode 100644 index 0000000..80cf692 --- /dev/null +++ b/packages/fluorflow/analysis_options.yaml @@ -0,0 +1,15 @@ +include: package:flutter_lints/flutter.yaml + +linter: + rules: + always_declare_return_types: true + avoid_relative_lib_imports: true + eol_at_end_of_file: true + library_private_types_in_public_api: false + lines_longer_than_80_chars: false + prefer_final_fields: true + prefer_final_in_for_each: true + prefer_final_locals: true + prefer_relative_imports: true + prefer_single_quotes: true + prefer_expression_function_bodies: true diff --git a/packages/fluorflow/bin/fluorflow.dart b/packages/fluorflow/bin/fluorflow.dart new file mode 100644 index 0000000..4d9d57b --- /dev/null +++ b/packages/fluorflow/bin/fluorflow.dart @@ -0,0 +1,20 @@ +import 'dart:io'; + +import 'package:args/command_runner.dart'; +import 'package:fluorflow/src/cli/generate.dart'; + +const usageErrorExitCode = 64; + +void main(List args) { + final runner = CommandRunner('fluorflow', 'CLI for the fluorflow framework.') + ..addCommand(Generate()); + + runner.run(args).catchError((error) { + if (error is! UsageException) { + throw error; + } + // ignore: avoid_print + print(error); + exit(usageErrorExitCode); + }); +} diff --git a/packages/fluorflow/example/.gitignore b/packages/fluorflow/example/.gitignore new file mode 100644 index 0000000..fa81acf --- /dev/null +++ b/packages/fluorflow/example/.gitignore @@ -0,0 +1,48 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +app.*.dart + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release + +pubspec.lock diff --git a/packages/fluorflow/example/.metadata b/packages/fluorflow/example/.metadata new file mode 100644 index 0000000..bf1faef --- /dev/null +++ b/packages/fluorflow/example/.metadata @@ -0,0 +1,30 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + channel: stable + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + - platform: ios + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/fluorflow/example/README.md b/packages/fluorflow/example/README.md new file mode 100644 index 0000000..2b3fce4 --- /dev/null +++ b/packages/fluorflow/example/README.md @@ -0,0 +1,16 @@ +# example + +A new Flutter project. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/packages/fluorflow/example/analysis_options.yaml b/packages/fluorflow/example/analysis_options.yaml new file mode 100644 index 0000000..61b6c4d --- /dev/null +++ b/packages/fluorflow/example/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/fluorflow/example/ios/.gitignore b/packages/fluorflow/example/ios/.gitignore new file mode 100644 index 0000000..7a7f987 --- /dev/null +++ b/packages/fluorflow/example/ios/.gitignore @@ -0,0 +1,34 @@ +**/dgph +*.mode1v3 +*.mode2v3 +*.moved-aside +*.pbxuser +*.perspectivev3 +**/*sync/ +.sconsign.dblite +.tags* +**/.vagrant/ +**/DerivedData/ +Icon? +**/Pods/ +**/.symlinks/ +profile +xcuserdata +**/.generated/ +Flutter/App.framework +Flutter/Flutter.framework +Flutter/Flutter.podspec +Flutter/Generated.xcconfig +Flutter/ephemeral/ +Flutter/app.flx +Flutter/app.zip +Flutter/flutter_assets/ +Flutter/flutter_export_environment.sh +ServiceDefinitions.json +Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!default.mode1v3 +!default.mode2v3 +!default.pbxuser +!default.perspectivev3 diff --git a/packages/fluorflow/example/ios/Flutter/AppFrameworkInfo.plist b/packages/fluorflow/example/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 0000000..9625e10 --- /dev/null +++ b/packages/fluorflow/example/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + MinimumOSVersion + 11.0 + + diff --git a/packages/fluorflow/example/ios/Flutter/Debug.xcconfig b/packages/fluorflow/example/ios/Flutter/Debug.xcconfig new file mode 100644 index 0000000..592ceee --- /dev/null +++ b/packages/fluorflow/example/ios/Flutter/Debug.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/packages/fluorflow/example/ios/Flutter/Release.xcconfig b/packages/fluorflow/example/ios/Flutter/Release.xcconfig new file mode 100644 index 0000000..592ceee --- /dev/null +++ b/packages/fluorflow/example/ios/Flutter/Release.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/packages/fluorflow/example/ios/Runner.xcodeproj/project.pbxproj b/packages/fluorflow/example/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000..48f828d --- /dev/null +++ b/packages/fluorflow/example/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,613 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXBuildFile section */ + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 331C8085294A63A400263BE5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 97C146E61CF9000F007C117D /* Project object */; + proxyType = 1; + remoteGlobalIDString = 97C146ED1CF9000F007C117D; + remoteInfo = Runner; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = ""; }; + 331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 331C8082294A63A400263BE5 /* RunnerTests */ = { + isa = PBXGroup; + children = ( + 331C807B294A618700263BE5 /* RunnerTests.swift */, + ); + path = RunnerTests; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + 331C8082294A63A400263BE5 /* RunnerTests */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + 331C8081294A63A400263BE5 /* RunnerTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, + ); + path = Runner; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 331C8080294A63A400263BE5 /* RunnerTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */; + buildPhases = ( + 331C807D294A63A400263BE5 /* Sources */, + 331C807E294A63A400263BE5 /* Frameworks */, + 331C807F294A63A400263BE5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 331C8086294A63A400263BE5 /* PBXTargetDependency */, + ); + name = RunnerTests; + productName = RunnerTests; + productReference = 331C8081294A63A400263BE5 /* RunnerTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1430; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 331C8080294A63A400263BE5 = { + CreatedOnToolsVersion = 14.0; + TestTargetID = 97C146ED1CF9000F007C117D; + }; + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 1100; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + 331C8080294A63A400263BE5 /* RunnerTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 331C807F294A63A400263BE5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 331C807D294A63A400263BE5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 331C8086294A63A400263BE5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 97C146ED1CF9000F007C117D /* Runner */; + targetProxy = 331C8085294A63A400263BE5 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 249021D3217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Profile; + }; + 249021D4217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.example; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Profile; + }; + 331C8088294A63A400263BE5 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = AE0B7B92F70575B8D7E0D07E /* Pods-RunnerTests.debug.xcconfig */; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.example.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Debug; + }; + 331C8089294A63A400263BE5 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 89B67EB44CE7B6631473024E /* Pods-RunnerTests.release.xcconfig */; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.example.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Release; + }; + 331C808A294A63A400263BE5 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 640959BDD8F10B91D80A66BE /* Pods-RunnerTests.profile.xcconfig */; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.example.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Profile; + }; + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.example; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.example; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 331C8088294A63A400263BE5 /* Debug */, + 331C8089294A63A400263BE5 /* Release */, + 331C808A294A63A400263BE5 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + 249021D3217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + 249021D4217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f9b0d7c --- /dev/null +++ b/packages/fluorflow/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/packages/fluorflow/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/fluorflow/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000..87131a0 --- /dev/null +++ b/packages/fluorflow/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/fluorflow/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/packages/fluorflow/example/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..1d526a1 --- /dev/null +++ b/packages/fluorflow/example/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/packages/fluorflow/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/fluorflow/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/packages/fluorflow/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/packages/fluorflow/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/packages/fluorflow/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f9b0d7c --- /dev/null +++ b/packages/fluorflow/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/packages/fluorflow/example/ios/Runner/AppDelegate.swift b/packages/fluorflow/example/ios/Runner/AppDelegate.swift new file mode 100644 index 0000000..70693e4 --- /dev/null +++ b/packages/fluorflow/example/ios/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +import UIKit +import Flutter + +@UIApplicationMain +@objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +} diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d36b1fa --- /dev/null +++ b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,122 @@ +{ + "images" : [ + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@3x.png", + "scale" : "3x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@3x.png", + "scale" : "3x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@3x.png", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@2x.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@3x.png", + "scale" : "3x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@1x.png", + "scale" : "1x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@1x.png", + "scale" : "1x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@1x.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@2x.png", + "scale" : "2x" + }, + { + "size" : "83.5x83.5", + "idiom" : "ipad", + "filename" : "Icon-App-83.5x83.5@2x.png", + "scale" : "2x" + }, + { + "size" : "1024x1024", + "idiom" : "ios-marketing", + "filename" : "Icon-App-1024x1024@1x.png", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png new file mode 100644 index 0000000000000000000000000000000000000000..dc9ada4725e9b0ddb1deab583e5b5102493aa332 GIT binary patch literal 10932 zcmeHN2~<R zh`|8`A_PQ1nSu(UMFx?8j8PC!!VDphaL#`F42fd#7Vlc`zIE4n%Y~eiz4y1j|NDpi z?<@|pSJ-HM`qifhf@m%MamgwK83`XpBA<+azdF#2QsT{X@z0A9Bq>~TVErigKH1~P zRX-!h-f0NJ4Mh++{D}J+K>~~rq}d%o%+4dogzXp7RxX4C>Km5XEI|PAFDmo;DFm6G zzjVoB`@qW98Yl0Kvc-9w09^PrsobmG*Eju^=3f?0o-t$U)TL1B3;sZ^!++3&bGZ!o-*6w?;oOhf z=A+Qb$scV5!RbG+&2S}BQ6YH!FKb0``VVX~T$dzzeSZ$&9=X$3)_7Z{SspSYJ!lGE z7yig_41zpQ)%5dr4ff0rh$@ky3-JLRk&DK)NEIHecf9c*?Z1bUB4%pZjQ7hD!A0r-@NF(^WKdr(LXj|=UE7?gBYGgGQV zidf2`ZT@pzXf7}!NH4q(0IMcxsUGDih(0{kRSez&z?CFA0RVXsVFw3^u=^KMtt95q z43q$b*6#uQDLoiCAF_{RFc{!H^moH_cmll#Fc^KXi{9GDl{>%+3qyfOE5;Zq|6#Hb zp^#1G+z^AXfRKaa9HK;%b3Ux~U@q?xg<2DXP%6k!3E)PA<#4$ui8eDy5|9hA5&{?v z(-;*1%(1~-NTQ`Is1_MGdQ{+i*ccd96ab$R$T3=% zw_KuNF@vI!A>>Y_2pl9L{9h1-C6H8<)J4gKI6{WzGBi<@u3P6hNsXG=bRq5c+z;Gc3VUCe;LIIFDmQAGy+=mRyF++u=drBWV8-^>0yE9N&*05XHZpPlE zxu@?8(ZNy7rm?|<+UNe0Vs6&o?l`Pt>P&WaL~M&#Eh%`rg@Mbb)J&@DA-wheQ>hRV z<(XhigZAT z>=M;URcdCaiO3d^?H<^EiEMDV+7HsTiOhoaMX%P65E<(5xMPJKxf!0u>U~uVqnPN7T!X!o@_gs3Ct1 zlZ_$5QXP4{Aj645wG_SNT&6m|O6~Tsl$q?nK*)(`{J4b=(yb^nOATtF1_aS978$x3 zx>Q@s4i3~IT*+l{@dx~Hst21fR*+5}S1@cf>&8*uLw-0^zK(+OpW?cS-YG1QBZ5q! zgTAgivzoF#`cSz&HL>Ti!!v#?36I1*l^mkrx7Y|K6L#n!-~5=d3;K<;Zqi|gpNUn_ z_^GaQDEQ*jfzh;`j&KXb66fWEk1K7vxQIMQ_#Wu_%3 z4Oeb7FJ`8I>Px;^S?)}2+4D_83gHEq>8qSQY0PVP?o)zAv3K~;R$fnwTmI-=ZLK`= zTm+0h*e+Yfr(IlH3i7gUclNH^!MU>id$Jw>O?2i0Cila#v|twub21@e{S2v}8Z13( zNDrTXZVgris|qYm<0NU(tAPouG!QF4ZNpZPkX~{tVf8xY690JqY1NVdiTtW+NqyRP zZ&;T0ikb8V{wxmFhlLTQ&?OP7 z;(z*<+?J2~z*6asSe7h`$8~Se(@t(#%?BGLVs$p``;CyvcT?7Y!{tIPva$LxCQ&4W z6v#F*);|RXvI%qnoOY&i4S*EL&h%hP3O zLsrFZhv&Hu5tF$Lx!8(hs&?!Kx5&L(fdu}UI5d*wn~A`nPUhG&Rv z2#ixiJdhSF-K2tpVL=)5UkXRuPAFrEW}7mW=uAmtVQ&pGE-&az6@#-(Te^n*lrH^m@X-ftVcwO_#7{WI)5v(?>uC9GG{lcGXYJ~Q8q zbMFl7;t+kV;|;KkBW2!P_o%Czhw&Q(nXlxK9ak&6r5t_KH8#1Mr-*0}2h8R9XNkr zto5-b7P_auqTJb(TJlmJ9xreA=6d=d)CVbYP-r4$hDn5|TIhB>SReMfh&OVLkMk-T zYf%$taLF0OqYF?V{+6Xkn>iX@TuqQ?&cN6UjC9YF&%q{Ut3zv{U2)~$>-3;Dp)*(? zg*$mu8^i=-e#acaj*T$pNowo{xiGEk$%DusaQiS!KjJH96XZ-hXv+jk%ard#fu=@Q z$AM)YWvE^{%tDfK%nD49=PI|wYu}lYVbB#a7wtN^Nml@CE@{Gv7+jo{_V?I*jkdLD zJE|jfdrmVbkfS>rN*+`#l%ZUi5_bMS<>=MBDNlpiSb_tAF|Zy`K7kcp@|d?yaTmB^ zo?(vg;B$vxS|SszusORgDg-*Uitzdi{dUV+glA~R8V(?`3GZIl^egW{a919!j#>f` znL1o_^-b`}xnU0+~KIFLQ)$Q6#ym%)(GYC`^XM*{g zv3AM5$+TtDRs%`2TyR^$(hqE7Y1b&`Jd6dS6B#hDVbJlUXcG3y*439D8MrK!2D~6gn>UD4Imctb z+IvAt0iaW73Iq$K?4}H`7wq6YkTMm`tcktXgK0lKPmh=>h+l}Y+pDtvHnG>uqBA)l zAH6BV4F}v$(o$8Gfo*PB>IuaY1*^*`OTx4|hM8jZ?B6HY;F6p4{`OcZZ(us-RVwDx zUzJrCQlp@mz1ZFiSZ*$yX3c_#h9J;yBE$2g%xjmGF4ca z&yL`nGVs!Zxsh^j6i%$a*I3ZD2SoNT`{D%mU=LKaEwbN(_J5%i-6Va?@*>=3(dQy` zOv%$_9lcy9+(t>qohkuU4r_P=R^6ME+wFu&LA9tw9RA?azGhjrVJKy&8=*qZT5Dr8g--d+S8zAyJ$1HlW3Olryt`yE zFIph~Z6oF&o64rw{>lgZISC6p^CBer9C5G6yq%?8tC+)7*d+ib^?fU!JRFxynRLEZ zj;?PwtS}Ao#9whV@KEmwQgM0TVP{hs>dg(1*DiMUOKHdQGIqa0`yZnHk9mtbPfoLx zo;^V6pKUJ!5#n`w2D&381#5#_t}AlTGEgDz$^;u;-vxDN?^#5!zN9ngytY@oTv!nc zp1Xn8uR$1Z;7vY`-<*?DfPHB;x|GUi_fI9@I9SVRv1)qETbNU_8{5U|(>Du84qP#7 z*l9Y$SgA&wGbj>R1YeT9vYjZuC@|{rajTL0f%N@>3$DFU=`lSPl=Iv;EjuGjBa$Gw zHD-;%YOE@<-!7-Mn`0WuO3oWuL6tB2cpPw~Nvuj|KM@))ixuDK`9;jGMe2d)7gHin zS<>k@!x;!TJEc#HdL#RF(`|4W+H88d4V%zlh(7#{q2d0OQX9*FW^`^_<3r$kabWAB z$9BONo5}*(%kx zOXi-yM_cmB3>inPpI~)duvZykJ@^^aWzQ=eQ&STUa}2uT@lV&WoRzkUoE`rR0)`=l zFT%f|LA9fCw>`enm$p7W^E@U7RNBtsh{_-7vVz3DtB*y#*~(L9+x9*wn8VjWw|Q~q zKFsj1Yl>;}%MG3=PY`$g$_mnyhuV&~O~u~)968$0b2!Jkd;2MtAP#ZDYw9hmK_+M$ zb3pxyYC&|CuAbtiG8HZjj?MZJBFbt`ryf+c1dXFuC z0*ZQhBzNBd*}s6K_G}(|Z_9NDV162#y%WSNe|FTDDhx)K!c(mMJh@h87@8(^YdK$&d*^WQe8Z53 z(|@MRJ$Lk-&ii74MPIs80WsOFZ(NX23oR-?As+*aq6b?~62@fSVmM-_*cb1RzZ)`5$agEiL`-E9s7{GM2?(KNPgK1(+c*|-FKoy}X(D_b#etO|YR z(BGZ)0Ntfv-7R4GHoXp?l5g#*={S1{u-QzxCGng*oWr~@X-5f~RA14b8~B+pLKvr4 zfgL|7I>jlak9>D4=(i(cqYf7#318!OSR=^`xxvI!bBlS??`xxWeg?+|>MxaIdH1U~#1tHu zB{QMR?EGRmQ_l4p6YXJ{o(hh-7Tdm>TAX380TZZZyVkqHNzjUn*_|cb?T? zt;d2s-?B#Mc>T-gvBmQZx(y_cfkXZO~{N zT6rP7SD6g~n9QJ)8F*8uHxTLCAZ{l1Y&?6v)BOJZ)=R-pY=Y=&1}jE7fQ>USS}xP#exo57uND0i*rEk@$;nLvRB@u~s^dwRf?G?_enN@$t* zbL%JO=rV(3Ju8#GqUpeE3l_Wu1lN9Y{D4uaUe`g>zlj$1ER$6S6@{m1!~V|bYkhZA z%CvrDRTkHuajMU8;&RZ&itnC~iYLW4DVkP<$}>#&(`UO>!n)Po;Mt(SY8Yb`AS9lt znbX^i?Oe9r_o=?})IHKHoQGKXsps_SE{hwrg?6dMI|^+$CeC&z@*LuF+P`7LfZ*yr+KN8B4{Nzv<`A(wyR@!|gw{zB6Ha ziwPAYh)oJ(nlqSknu(8g9N&1hu0$vFK$W#mp%>X~AU1ay+EKWcFdif{% z#4!4aoVVJ;ULmkQf!ke2}3hqxLK>eq|-d7Ly7-J9zMpT`?dxo6HdfJA|t)?qPEVBDv z{y_b?4^|YA4%WW0VZd8C(ZgQzRI5(I^)=Ub`Y#MHc@nv0w-DaJAqsbEHDWG8Ia6ju zo-iyr*sq((gEwCC&^TYBWt4_@|81?=B-?#P6NMff(*^re zYqvDuO`K@`mjm_Jd;mW_tP`3$cS?R$jR1ZN09$YO%_iBqh5ftzSpMQQtxKFU=FYmP zeY^jph+g<4>YO;U^O>-NFLn~-RqlHvnZl2yd2A{Yc1G@Ga$d+Q&(f^tnPf+Z7serIU};17+2DU_f4Z z@GaPFut27d?!YiD+QP@)T=77cR9~MK@bd~pY%X(h%L={{OIb8IQmf-!xmZkm8A0Ga zQSWONI17_ru5wpHg3jI@i9D+_Y|pCqVuHJNdHUauTD=R$JcD2K_liQisqG$(sm=k9;L* z!L?*4B~ql7uioSX$zWJ?;q-SWXRFhz2Jt4%fOHA=Bwf|RzhwqdXGr78y$J)LR7&3T zE1WWz*>GPWKZ0%|@%6=fyx)5rzUpI;bCj>3RKzNG_1w$fIFCZ&UR0(7S?g}`&Pg$M zf`SLsz8wK82Vyj7;RyKmY{a8G{2BHG%w!^T|Njr!h9TO2LaP^_f22Q1=l$QiU84ao zHe_#{S6;qrC6w~7{y(hs-?-j?lbOfgH^E=XcSgnwW*eEz{_Z<_xN#0001NP)t-s|Ns9~ z#rXRE|M&d=0au&!`~QyF`q}dRnBDt}*!qXo`c{v z{Djr|@Adh0(D_%#_&mM$D6{kE_x{oE{l@J5@%H*?%=t~i_`ufYOPkAEn!pfkr2$fs z652Tz0001XNklqeeKN4RM4i{jKqmiC$?+xN>3Apn^ z0QfuZLym_5b<*QdmkHjHlj811{If)dl(Z2K0A+ekGtrFJb?g|wt#k#pV-#A~bK=OT ts8>{%cPtyC${m|1#B1A6#u!Q;umknL1chzTM$P~L002ovPDHLkV1lTfnu!1a literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..797d452e458972bab9d994556c8305db4c827017 GIT binary patch literal 406 zcmV;H0crk;P))>cdjpWt&rLJgVp-t?DREyuq1A%0Z4)6_WsQ7{nzjN zo!X zGXV)2i3kcZIL~_j>uIKPK_zib+3T+Nt3Mb&Br)s)UIaA}@p{wDda>7=Q|mGRp7pqY zkJ!7E{MNz$9nOwoVqpFb)}$IP24Wn2JJ=Cw(!`OXJBr45rP>>AQr$6c7slJWvbpNW z@KTwna6d?PP>hvXCcp=4F;=GR@R4E7{4VU^0p4F>v^#A|>07*qoM6N<$f*5nx ACIA2c literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..6ed2d933e1120817fe9182483a228007b18ab6ae GIT binary patch literal 450 zcmV;z0X_bSP)iGWQ_5NJQ_~rNh*z)}eT%KUb z`7gNk0#AwF^#0T0?hIa^`~Ck;!}#m+_uT050aTR(J!bU#|IzRL%^UsMS#KsYnTF*!YeDOytlP4VhV?b} z%rz_<=#CPc)tU1MZTq~*2=8~iZ!lSa<{9b@2Jl;?IEV8)=fG217*|@)CCYgFze-x? zIFODUIA>nWKpE+bn~n7;-89sa>#DR>TSlqWk*!2hSN6D~Qb#VqbP~4Fk&m`@1$JGr zXPIdeRE&b2Thd#{MtDK$px*d3-Wx``>!oimf%|A-&-q*6KAH)e$3|6JV%HX{Hig)k suLT-RhftRq8b9;(V=235Wa|I=027H2wCDra;{X5v07*qoM6N<$f;9x^2LJ#7 literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png new file mode 100644 index 0000000000000000000000000000000000000000..4cd7b0099ca80c806f8fe495613e8d6c69460d76 GIT binary patch literal 282 zcmV+#0p(^bcu7P-R4C8Q z&e;xxFbF_Vrezo%_kH*OKhshZ6BFpG-Y1e10`QXJKbND7AMQ&cMj60B5TNObaZxYybcN07*qoM6N<$g3m;S%K!iX literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..fe730945a01f64a61e2235dbe3f45b08f7729182 GIT binary patch literal 462 zcmV;<0WtoGP)-}iV`2<;=$?g5M=KQbZ{F&YRNy7Nn@%_*5{gvDM0aKI4?ESmw z{NnZg)A0R`+4?NF_RZexyVB&^^ZvN!{I28tr{Vje;QNTz`dG&Jz0~Ek&f2;*Z7>B|cg}xYpxEFY+0YrKLF;^Q+-HreN0P{&i zK~zY`?b7ECf-n?@;d<&orQ*Q7KoR%4|C>{W^h6@&01>0SKS`dn{Q}GT%Qj_{PLZ_& zs`MFI#j-(>?bvdZ!8^xTwlY{qA)T4QLbY@j(!YJ7aXJervHy6HaG_2SB`6CC{He}f zHVw(fJWApwPq!6VY7r1w-Fs)@ox~N+q|w~e;JI~C4Vf^@d>Wvj=fl`^u9x9wd9 zR%3*Q+)t%S!MU_`id^@&Y{y7-r98lZX0?YrHlfmwb?#}^1b{8g&KzmkE(L>Z&)179 zp<)v6Y}pRl100G2FL_t(o!|l{-Q-VMg#&MKg7c{O0 z2wJImOS3Gy*Z2Qifdv~JYOp;v+U)a|nLoc7hNH;I$;lzDt$}rkaFw1mYK5_0Q(Sut zvbEloxON7$+HSOgC9Z8ltuC&0OSF!-mXv5caV>#bc3@hBPX@I$58-z}(ZZE!t-aOG zpjNkbau@>yEzH(5Yj4kZiMH32XI!4~gVXNnjAvRx;Sdg^`>2DpUEwoMhTs_st8pKG z(%SHyHdU&v%f36~uERh!bd`!T2dw;z6PrOTQ7Vt*#9F2uHlUVnb#ev_o^fh}Dzmq} zWtlk35}k=?xj28uO|5>>$yXadTUE@@IPpgH`gJ~Ro4>jd1IF|(+IX>8M4Ps{PNvmI zNj4D+XgN83gPt_Gm}`Ybv{;+&yu-C(Grdiahmo~BjG-l&mWM+{e5M1sm&=xduwgM9 z`8OEh`=F3r`^E{n_;%9weN{cf2%7=VzC@cYj+lg>+3|D|_1C@{hcU(DyQG_BvBWe? zvTv``=%b1zrol#=R`JB)>cdjpWt&rLJgVp-t?DREyuq1A%0Z4)6_WsQ7{nzjN zo!X zGXV)2i3kcZIL~_j>uIKPK_zib+3T+Nt3Mb&Br)s)UIaA}@p{wDda>7=Q|mGRp7pqY zkJ!7E{MNz$9nOwoVqpFb)}$IP24Wn2JJ=Cw(!`OXJBr45rP>>AQr$6c7slJWvbpNW z@KTwna6d?PP>hvXCcp=4F;=GR@R4E7{4VU^0p4F>v^#A|>07*qoM6N<$f*5nx ACIA2c literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..502f463a9bc882b461c96aadf492d1729e49e725 GIT binary patch literal 586 zcmV-Q0=4~#P)+}#`wDE{8-2Mebf5<{{PqV{TgVcv*r8?UZ3{-|G?_}T*&y;@cqf{ z{Q*~+qr%%p!1pS*_Uicl#q9lc(D`!D`LN62sNwq{oYw(Wmhk)k<@f$!$@ng~_5)Ru z0Z)trIA5^j{DIW^c+vT2%lW+2<(RtE2wR;4O@)Tm`Xr*?A(qYoM}7i5Yxw>D(&6ou zxz!_Xr~yNF+waPe00049Nkl*;a!v6h%{rlvIH#gW3s8p;bFr=l}mRqpW2h zw=OA%hdyL~z+UHOzl0eKhEr$YYOL-c-%Y<)=j?(bzDweB7{b+%_ypvm_cG{SvM=DK zhv{K@m>#Bw>2W$eUI#iU)Wdgs8Y3U+A$Gd&{+j)d)BmGKx+43U_!tik_YlN)>$7G! zhkE!s;%oku3;IwG3U^2kw?z+HM)jB{@zFhK8P#KMSytSthr+4!c(5c%+^UBn`0X*2 zy3(k600_CSZj?O$Qu%&$;|TGUJrptR(HzyIx>5E(2r{eA(<6t3e3I0B)7d6s7?Z5J zZ!rtKvA{MiEBm&KFtoifx>5P^Z=vl)95XJn()aS5%ad(s?4-=Tkis9IGu{`Fy8r+H07*qoM6N<$f20Z)wqMt%V?S?~D#06};F zA3KcL`Wb+>5ObvgQIG&ig8(;V04hz?@cqy3{mSh8o!|U|)cI!1_+!fWH@o*8vh^CU z^ws0;(c$gI+2~q^tO#GDHf@=;DncUw00J^eL_t(&-tE|HQ`%4vfZ;WsBqu-$0nu1R zq^Vj;p$clf^?twn|KHO+IGt^q#a3X?w9dXC@*yxhv&l}F322(8Y1&=P&I}~G@#h6; z1CV9ecD9ZEe87{{NtI*)_aJ<`kJa z?5=RBtFF50s;jQLFil-`)m2wrb=6h(&brpj%nG_U&ut~$?8Rokzxi8zJoWr#2dto5 zOX_URcc<1`Iky+jc;A%Vzx}1QU{2$|cKPom2Vf1{8m`vja4{F>HS?^Nc^rp}xo+Nh zxd}eOm`fm3@MQC1< zIk&aCjb~Yh%5+Yq0`)D;q{#-Uqlv*o+Oor zE!I71Z@ASH3grl8&P^L0WpavHoP|UX4e?!igT`4?AZk$hu*@%6WJ;zDOGlw7kj@ zY5!B-0ft0f?Lgb>C;$Ke07*qoM6N<$f~t1N9smFU literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0ec303439225b78712f49115768196d8d76f6790 GIT binary patch literal 862 zcmV-k1EKthP)20Z)wqMt%V?S?~D#06};F zA3KcL`Wb+>5ObvgQIG&ig8(;V04hz?@cqy3{mSh8o!|U|)cI!1_+!fWH@o*8vh^CU z^ws0;(c$gI+2~q^tO#GDHf@=;DncUw00J^eL_t(&-tE|HQ`%4vfZ;WsBqu-$0nu1R zq^Vj;p$clf^?twn|KHO+IGt^q#a3X?w9dXC@*yxhv&l}F322(8Y1&=P&I}~G@#h6; z1CV9ecD9ZEe87{{NtI*)_aJ<`kJa z?5=RBtFF50s;jQLFil-`)m2wrb=6h(&brpj%nG_U&ut~$?8Rokzxi8zJoWr#2dto5 zOX_URcc<1`Iky+jc;A%Vzx}1QU{2$|cKPom2Vf1{8m`vja4{F>HS?^Nc^rp}xo+Nh zxd}eOm`fm3@MQC1< zIk&aCjb~Yh%5+Yq0`)D;q{#-Uqlv*o+Oor zE!I71Z@ASH3grl8&P^L0WpavHoP|UX4e?!igT`4?AZk$hu*@%6WJ;zDOGlw7kj@ zY5!B-0ft0f?Lgb>C;$Ke07*qoM6N<$f~t1N9smFU literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..e9f5fea27c705180eb716271f41b582e76dcbd90 GIT binary patch literal 1674 zcmV;526g#~P){YQnis^a@{&-nmRmq)<&%Mztj67_#M}W?l>kYSliK<%xAp;0j{!}J0!o7b zE>q9${Lb$D&h7k=+4=!ek^n+`0zq>LL1O?lVyea53S5x`Nqqo2YyeuIrQrJj9XjOp z{;T5qbj3}&1vg1VK~#9!?b~^C5-}JC@Pyrv-6dSEqJqT}#j9#dJ@GzT@B8}x zU&J@bBI>f6w6en+CeI)3^kC*U?}X%OD8$Fd$H&LV$H&LV$H&LV#|K5~mLYf|VqzOc zkc7qL~0sOYuM{tG`rYEDV{DWY`Z8&)kW*hc2VkBuY+^Yx&92j&StN}Wp=LD zxoGxXw6f&8sB^u})h@b@z0RBeD`K7RMR9deyL(ZJu#39Z>rT)^>v}Khq8U-IbIvT> z?4pV9qGj=2)TNH3d)=De<+^w;>S7m_eFKTvzeaBeir45xY!^m!FmxnljbSS_3o=g( z->^wC9%qkR{kbGnW8MfFew_o9h3(r55Is`L$8KI@d+*%{=Nx+FXJ98L0PjFIu;rGnnfY zn1R5Qnp<{Jq0M1vX=X&F8gtLmcWv$1*M@4ZfF^9``()#hGTeKeP`1!iED ztNE(TN}M5}3Bbc*d=FIv`DNv&@|C6yYj{sSqUj5oo$#*0$7pu|Dd2TLI>t5%I zIa4Dvr(iayb+5x=j*Vum9&irk)xV1`t509lnPO0%skL8_1c#Xbamh(2@f?4yUI zhhuT5<#8RJhGz4%b$`PJwKPAudsm|at?u;*hGgnA zU1;9gnxVBC)wA(BsB`AW54N{|qmikJR*%x0c`{LGsSfa|NK61pYH(r-UQ4_JXd!Rsz)=k zL{GMc5{h138)fF5CzHEDM>+FqY)$pdN3}Ml+riTgJOLN0F*Vh?{9ESR{SVVg>*>=# zix;VJHPtvFFCRY$Ks*F;VX~%*r9F)W`PmPE9F!(&s#x07n2<}?S{(ygpXgX-&B&OM zONY&BRQ(#%0%jeQs?oJ4P!p*R98>qCy5p8w>_gpuh39NcOlp)(wOoz0sY-Qz55eB~ z7OC-fKBaD1sE3$l-6QgBJO!n?QOTza`!S_YK z_v-lm^7{VO^8Q@M_^8F)09Ki6%=s?2_5eupee(w1FB%aqSweusQ-T+CH0Xt{` zFjMvW{@C&TB)k25()nh~_yJ9coBRL(0oO@HK~z}7?bm5j;y@69;bvlHb2tf!$ReA~x{22wTq550 z?f?Hnw(;m3ip30;QzdV~7pi!wyMYhDtXW#cO7T>|f=bdFhu+F!zMZ2UFj;GUKX7tI z;hv3{q~!*pMj75WP_c}>6)IWvg5_yyg<9Op()eD1hWC19M@?_9_MHec{Z8n3FaF{8 z;u`Mw0ly(uE>*CgQYv{be6ab2LWhlaH1^iLIM{olnag$78^Fd}%dR7;JECQ+hmk|o z!u2&!3MqPfP5ChDSkFSH8F2WVOEf0(E_M(JL17G}Y+fg0_IuW%WQ zG(mG&u?|->YSdk0;8rc{yw2@2Z&GA}z{Wb91Ooz9VhA{b2DYE7RmG zjL}?eq#iX%3#k;JWMx_{^2nNax`xPhByFiDX+a7uTGU|otOvIAUy|dEKkXOm-`aWS z27pUzD{a)Ct<6p{{3)+lq@i`t@%>-wT4r?*S}k)58e09WZYP0{{R3FC5Sl00039P)t-s|Ns9~ z#rP?<_5oL$Q^olD{r_0T`27C={r>*`|Nj71npVa5OTzc(_WfbW_({R{p56NV{r*M2 z_xt?)2V0#0NsfV0u>{42ctGP(8vQj-Btk1n|O0ZD=YLwd&R{Ko41Gr9H= zY@z@@bOAMB5Ltl$E>bJJ{>JP30ZxkmI%?eW{k`b?Wy<&gOo;dS`~CR$Vwb@XWtR|N zi~t=w02?-0&j0TD{>bb6sNwsK*!p?V`RMQUl(*DVjk-9Cx+-z1KXab|Ka2oXhX5f% z`$|e!000AhNklrxs)5QTeTVRiEmz~MKK1WAjCw(c-JK6eox;2O)?`? zTG`AHia671e^vgmp!llKp|=5sVHk#C7=~epA~VAf-~%aPC=%Qw01h8mnSZ|p?hz91 z7p83F3%LVu9;S$tSI$C^%^yud1dfTM_6p2|+5Ejp$bd`GDvbR|xit>i!ZD&F>@CJrPmu*UjD&?DfZs=$@e3FQA(vNiU+$A*%a} z?`XcG2jDxJ_ZQ#Md`H{4Lpf6QBDp81_KWZ6Tk#yCy1)32zO#3<7>b`eT7UyYH1eGz z;O(rH$=QR*L%%ZcBpc=eGua?N55nD^K(8<#gl2+pN_j~b2MHs4#mcLmv%DkspS-3< zpI1F=^9siI0s-;IN_IrA;5xm~3?3!StX}pUv0vkxMaqm+zxrg7X7(I&*N~&dEd0kD z-FRV|g=|QuUsuh>-xCI}vD2imzYIOIdcCVV=$Bz@*u0+Bs<|L^)32nN*=wu3n%Ynw z@1|eLG>!8ruU1pFXUfb`j>(=Gy~?Rn4QJ-c3%3T|(Frd!bI`9u&zAnyFYTqlG#&J7 zAkD(jpw|oZLNiA>;>hgp1KX7-wxC~31II47gc zHcehD6Uxlf%+M^^uN5Wc*G%^;>D5qT{>=uxUhX%WJu^Z*(_Wq9y}npFO{Hhb>s6<9 zNi0pHXWFaVZnb)1+RS&F)xOv6&aeILcI)`k#0YE+?e)5&#r7J#c`3Z7x!LpTc01dx zrdC3{Z;joZ^KN&))zB_i)I9fWedoN>Zl-6_Iz+^G&*ak2jpF07*qoM6N<$f;w%0(f|Me literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0467bf12aa4d28f374bb26596605a46dcbb3e7c8 GIT binary patch literal 1418 zcmV;51$Fv~P)q zKfU)WzW*n(@|xWGCA9ScMt*e9`2kdxPQ&&>|-UCa7_51w+ zLUsW@ZzZSW0y$)Hp~e9%PvP|a03ks1`~K?q{u;6NC8*{AOqIUq{CL&;p56Lf$oQGq z^={4hPQv)y=I|4n+?>7Fim=dxt1 z2H+Dm+1+fh+IF>G0SjJMkQQre1x4|G*Z==(Ot&kCnUrL4I(rf(ucITwmuHf^hXiJT zkdTm&kdTm&kdTm&kdP`esgWG0BcWCVkVZ&2dUwN`cgM8QJb`Z7Z~e<&Yj2(}>Tmf` zm1{eLgw!b{bXkjWbF%dTkTZEJWyWOb##Lfw4EK2}<0d6%>AGS{po>WCOy&f$Tay_> z?NBlkpo@s-O;0V%Y_Xa-G#_O08q5LR*~F%&)}{}r&L%Sbs8AS4t7Y0NEx*{soY=0MZExqA5XHQkqi#4gW3 zqODM^iyZl;dvf)-bOXtOru(s)Uc7~BFx{w-FK;2{`VA?(g&@3z&bfLFyctOH!cVsF z7IL=fo-qBndRUm;kAdXR4e6>k-z|21AaN%ubeVrHl*<|s&Ax@W-t?LR(P-24A5=>a z*R9#QvjzF8n%@1Nw@?CG@6(%>+-0ASK~jEmCV|&a*7-GKT72W<(TbSjf)&Eme6nGE z>Gkj4Sq&2e+-G%|+NM8OOm5zVl9{Z8Dd8A5z3y8mZ=4Bv4%>as_{9cN#bm~;h>62( zdqY93Zy}v&c4n($Vv!UybR8ocs7#zbfX1IY-*w~)p}XyZ-SFC~4w>BvMVr`dFbelV{lLL0bx7@*ZZdebr3`sP;? zVImji)kG)(6Juv0lz@q`F!k1FE;CQ(D0iG$wchPbKZQELlsZ#~rt8#90Y_Xh&3U-< z{s<&cCV_1`^TD^ia9!*mQDq& zn2{r`j};V|uV%_wsP!zB?m%;FeaRe+X47K0e+KE!8C{gAWF8)lCd1u1%~|M!XNRvw zvtqy3iz0WSpWdhn6$hP8PaRBmp)q`#PCA`Vd#Tc$@f1tAcM>f_I@bC)hkI9|o(Iqv zo}Piadq!j76}004RBio<`)70k^`K1NK)q>w?p^C6J2ZC!+UppiK6&y3Kmbv&O!oYF z34$0Z;QO!JOY#!`qyGH<3Pd}Pt@q*A0V=3SVtWKRR8d8Z&@)3qLPA19LPA19LPEUC YUoZo%k(ykuW&i*H07*qoM6N<$f+CH{y8r+H literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json new file mode 100644 index 0000000..0bedcf2 --- /dev/null +++ b/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "LaunchImage.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png new file mode 100644 index 0000000000000000000000000000000000000000..9da19eacad3b03bb08bbddbbf4ac48dd78b3d838 GIT binary patch literal 68 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx0wlM}@Gt=>Zci7-kcv6Uzs@r-FtIZ-&5|)J Q1PU{Fy85}Sb4q9e0B4a5jsO4v literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..9da19eacad3b03bb08bbddbbf4ac48dd78b3d838 GIT binary patch literal 68 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx0wlM}@Gt=>Zci7-kcv6Uzs@r-FtIZ-&5|)J Q1PU{Fy85}Sb4q9e0B4a5jsO4v literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..9da19eacad3b03bb08bbddbbf4ac48dd78b3d838 GIT binary patch literal 68 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx0wlM}@Gt=>Zci7-kcv6Uzs@r-FtIZ-&5|)J Q1PU{Fy85}Sb4q9e0B4a5jsO4v literal 0 HcmV?d00001 diff --git a/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md new file mode 100644 index 0000000..89c2725 --- /dev/null +++ b/packages/fluorflow/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md @@ -0,0 +1,5 @@ +# Launch Screen Assets + +You can customize the launch screen with your own desired assets by replacing the image files in this directory. + +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. \ No newline at end of file diff --git a/packages/fluorflow/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/packages/fluorflow/example/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..f2e259c --- /dev/null +++ b/packages/fluorflow/example/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/fluorflow/example/ios/Runner/Base.lproj/Main.storyboard b/packages/fluorflow/example/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 0000000..f3c2851 --- /dev/null +++ b/packages/fluorflow/example/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/fluorflow/example/ios/Runner/Info.plist b/packages/fluorflow/example/ios/Runner/Info.plist new file mode 100644 index 0000000..7f55346 --- /dev/null +++ b/packages/fluorflow/example/ios/Runner/Info.plist @@ -0,0 +1,51 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Example + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + example + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + + + diff --git a/packages/fluorflow/example/ios/Runner/Runner-Bridging-Header.h b/packages/fluorflow/example/ios/Runner/Runner-Bridging-Header.h new file mode 100644 index 0000000..308a2a5 --- /dev/null +++ b/packages/fluorflow/example/ios/Runner/Runner-Bridging-Header.h @@ -0,0 +1 @@ +#import "GeneratedPluginRegistrant.h" diff --git a/packages/fluorflow/example/ios/RunnerTests/RunnerTests.swift b/packages/fluorflow/example/ios/RunnerTests/RunnerTests.swift new file mode 100644 index 0000000..86a7c3b --- /dev/null +++ b/packages/fluorflow/example/ios/RunnerTests/RunnerTests.swift @@ -0,0 +1,12 @@ +import Flutter +import UIKit +import XCTest + +class RunnerTests: XCTestCase { + + func testExample() { + // If you add code to the Runner application, consider adding tests here. + // See https://developer.apple.com/documentation/xctest for more information about using XCTest. + } + +} diff --git a/packages/fluorflow/example/justfile b/packages/fluorflow/example/justfile new file mode 100644 index 0000000..869807f --- /dev/null +++ b/packages/fluorflow/example/justfile @@ -0,0 +1,6 @@ + +default: build-runner + +# Execute the build runner to generate dart related objects. +build-runner: + dart run build_runner build --delete-conflicting-outputs diff --git a/packages/fluorflow/example/lib/bottom_sheets/greeting_bottom_sheet.dart b/packages/fluorflow/example/lib/bottom_sheets/greeting_bottom_sheet.dart new file mode 100644 index 0000000..76deaf3 --- /dev/null +++ b/packages/fluorflow/example/lib/bottom_sheets/greeting_bottom_sheet.dart @@ -0,0 +1,37 @@ +import 'package:fluorflow/fluorflow.dart'; +import 'package:flutter/material.dart'; + +typedef FancyCallback = void Function(); + +class BottomSheetElement { + late final String stuff; +} + +final class GreetingBottomSheet extends FluorFlowSimpleBottomSheet { + final FancyCallback callback; + final void Function(BottomSheetElement element) onElement; + + const GreetingBottomSheet(this.callback, this.onElement, + {super.key, required super.completer}); + + @override + Widget build(BuildContext context) => Scaffold( + backgroundColor: Colors.amber[200], + appBar: AppBar( + title: const Text('Bottom Sheet'), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('A Bottom Sheet'), + const SizedBox(height: 36), + ElevatedButton( + onPressed: completer.confirm, + child: const Text('Close'), + ), + ], + ), + ), + ); +} diff --git a/packages/fluorflow/example/lib/dialogs/red_dialog.dart b/packages/fluorflow/example/lib/dialogs/red_dialog.dart new file mode 100644 index 0000000..950a05e --- /dev/null +++ b/packages/fluorflow/example/lib/dialogs/red_dialog.dart @@ -0,0 +1,35 @@ +import 'package:fluorflow/annotations.dart'; +import 'package:fluorflow/fluorflow.dart'; +import 'package:flutter/material.dart'; + +class DialogElement { + late final String stuff; +} + +@DialogConfig(routeBuilder: RouteBuilder.fadeIn) +final class RedDialog extends FluorFlowSimpleDialog { + final List elements; + + const RedDialog(this.elements, {super.key, required super.completer}); + + @override + Widget build(BuildContext context) => Scaffold( + backgroundColor: Colors.red[200], + appBar: AppBar( + title: const Text('Dialog'), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('Dialog Page'), + const SizedBox(height: 36), + ElevatedButton( + onPressed: completer.confirm, + child: const Text('Close'), + ), + ], + ), + ), + ); +} diff --git a/packages/fluorflow/example/lib/main.dart b/packages/fluorflow/example/lib/main.dart new file mode 100644 index 0000000..7309711 --- /dev/null +++ b/packages/fluorflow/example/lib/main.dart @@ -0,0 +1,29 @@ +import 'package:example/app.locator.dart'; +import 'package:fluorflow/fluorflow.dart'; +import 'package:flutter/material.dart'; + +import 'app.router.dart'; + +void main() async { + await setupLocator(); + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'FluorFlow Demo', + theme: ThemeData( + colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + useMaterial3: true, + ), + initialRoute: AppRoute.homeView.path, + onGenerateRoute: onGenerateRoute, + navigatorKey: NavigationService.navigatorKey, + navigatorObservers: [NavigationService.observer()], + ); + } +} diff --git a/packages/fluorflow/example/lib/services/demo.dart b/packages/fluorflow/example/lib/services/demo.dart new file mode 100644 index 0000000..993772d --- /dev/null +++ b/packages/fluorflow/example/lib/services/demo.dart @@ -0,0 +1,35 @@ +// ignore_for_file: avoid_print + +import 'package:fluorflow/annotations.dart'; + +@Singleton() +class DemoService { + void doSomething() { + print('Doing something'); + } +} + +@LazySingleton() +class LazyDemoService { + void doSomething() { + print('Doing something'); + } +} + +@AsyncSingleton(factory: AsyncDemoService.create) +class AsyncDemoService { + static Future create() async { + return AsyncDemoService(); + } + + void doSomething() { + print('Doing something'); + } +} + +@AsyncSingleton() +Future createAsyncFactoryDemoService() async { + return AsyncFactoryDemoService(); +} + +class AsyncFactoryDemoService {} diff --git a/packages/fluorflow/example/lib/views/detail/detail_view.dart b/packages/fluorflow/example/lib/views/detail/detail_view.dart new file mode 100644 index 0000000..26bbaa6 --- /dev/null +++ b/packages/fluorflow/example/lib/views/detail/detail_view.dart @@ -0,0 +1,44 @@ +import 'package:fluorflow/annotations.dart'; +import 'package:fluorflow/fluorflow.dart'; +import 'package:flutter/material.dart'; + +import 'detail_viewmodel.dart'; + +@Routable( + replaceWithExtension: false, + rootToExtension: false, + routeBuilder: RouteBuilder.leftToRight) +final class DetailView extends FluorFlowView { + const DetailView({super.key}); + + @override + Widget builder( + BuildContext context, + DetailViewModel viewModel, + Widget? child, + ) => + Scaffold( + appBar: AppBar( + title: const Text('Detail'), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('Detail Page'), + const SizedBox(height: 36), + ElevatedButton( + onPressed: viewModel.back, + child: const Text('Back'), + ), + ElevatedButton( + onPressed: viewModel.showBottomSheet, + child: const Text('Show Bottom Sheet'), + ), + ], + ), + ), + ); + @override + DetailViewModel viewModelBuilder(BuildContext context) => DetailViewModel(); +} diff --git a/packages/fluorflow/example/lib/views/detail/detail_viewmodel.dart b/packages/fluorflow/example/lib/views/detail/detail_viewmodel.dart new file mode 100644 index 0000000..d293770 --- /dev/null +++ b/packages/fluorflow/example/lib/views/detail/detail_viewmodel.dart @@ -0,0 +1,12 @@ +import 'package:example/app.bottom_sheets.dart'; +import 'package:fluorflow/fluorflow.dart'; + +final class DetailViewModel extends BaseViewModel { + final _navService = locator(); + final _sheets = locator(); + + void showBottomSheet() => + _sheets.showGreetingBottomSheet(callback: () {}, onElement: (_) {}); + + void back() => _navService.back(); +} diff --git a/packages/fluorflow/example/lib/views/home/home_view.dart b/packages/fluorflow/example/lib/views/home/home_view.dart new file mode 100644 index 0000000..38b94cd --- /dev/null +++ b/packages/fluorflow/example/lib/views/home/home_view.dart @@ -0,0 +1,39 @@ +import 'package:fluorflow/annotations.dart'; +import 'package:fluorflow/fluorflow.dart'; +import 'package:flutter/material.dart'; + +import 'home_viewmodel.dart'; + +@Routable(navigateToExtension: false, replaceWithExtension: false) +final class HomeView extends FluorFlowView { + const HomeView({super.key}); + + @override + Widget builder( + BuildContext context, HomeViewModel viewModel, Widget? child) => + Scaffold( + appBar: AppBar( + title: const Text('Home'), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('Home Page'), + const SizedBox(height: 36), + ElevatedButton( + onPressed: viewModel.goToDetail, + child: const Text('Navigate to Detail'), + ), + ElevatedButton( + onPressed: viewModel.showTestDialog, + child: const Text('Show Dialog'), + ), + ], + ), + ), + ); + + @override + HomeViewModel viewModelBuilder(BuildContext context) => HomeViewModel(); +} diff --git a/packages/fluorflow/example/lib/views/home/home_viewmodel.dart b/packages/fluorflow/example/lib/views/home/home_viewmodel.dart new file mode 100644 index 0000000..23cabf5 --- /dev/null +++ b/packages/fluorflow/example/lib/views/home/home_viewmodel.dart @@ -0,0 +1,21 @@ +import 'package:example/app.dialogs.dart'; +import 'package:example/app.router.dart'; +import 'package:fluorflow/fluorflow.dart'; + +final class HomeViewModel extends BaseViewModel { + final _dialogService = locator(); + final _navService = locator(); + + var _counter = 0; + + int get counter => _counter; + + void increment() { + _counter++; + notifyListeners(); + } + + void showTestDialog() => _dialogService.showRedDialog(elements: []); + + void goToDetail() => _navService.navigateToDetailView(); +} diff --git a/packages/fluorflow/example/pubspec.yaml b/packages/fluorflow/example/pubspec.yaml new file mode 100644 index 0000000..ce031c2 --- /dev/null +++ b/packages/fluorflow/example/pubspec.yaml @@ -0,0 +1,30 @@ +name: example +description: A new Flutter project. +publish_to: 'none' +version: 1.0.0+1 + +environment: + sdk: '>=3.0.6 <4.0.0' + +dependencies: + fluorflow: + git: + url: https://github.com/smartive/fluorflow.git + path: packages/fluorflow + ref: main + flutter: + sdk: flutter + +dev_dependencies: + build_runner: ^2.4.6 + fluorflow_generator: + git: + url: https://github.com/smartive/fluorflow.git + path: packages/fluorflow_generator + ref: main + flutter_lints: ^2.0.0 + flutter_test: + sdk: flutter + +flutter: + uses-material-design: true diff --git a/packages/fluorflow/lib/annotations.dart b/packages/fluorflow/lib/annotations.dart new file mode 100644 index 0000000..306c4e3 --- /dev/null +++ b/packages/fluorflow/lib/annotations.dart @@ -0,0 +1,18 @@ +/// This library contains all annotations that are needed by the `fluorflow_generator`. +/// Refer to the specific annotations for further documentation. +/// +/// To use the annotations, install `fluorflow` as a dependency and `fluorflow_generator` +/// as a dev_dependency. When done, you want to have `build_runner` as a dev dependency too. +/// +/// When running the build runner, the dependencies and configurations are used to +/// generate dart code. +/// +/// Note: when the build_runner / fluorflow_generator is not used, the annotations are +/// not needed and have no effect. +library annotations; + +export 'src/annotations/bottom_sheet_config.dart'; +export 'src/annotations/dialog_config.dart'; +export 'src/annotations/injectable.dart'; +export 'src/annotations/routable.dart'; +export 'src/navigation/route_builder.dart'; diff --git a/packages/fluorflow/lib/fluorflow.dart b/packages/fluorflow/lib/fluorflow.dart new file mode 100644 index 0000000..2d744e2 --- /dev/null +++ b/packages/fluorflow/lib/fluorflow.dart @@ -0,0 +1,17 @@ +/// Main library for the fluorflow package. +library fluorflow; + +export 'src/bottom_sheets/bottom_sheet.dart'; +export 'src/bottom_sheets/bottom_sheet_service.dart'; +export 'src/bottom_sheets/simple_bottom_sheet.dart'; +export 'src/dialogs/dialog.dart'; +export 'src/dialogs/dialog_service.dart'; +export 'src/dialogs/simple_dialog.dart'; +export 'src/locator/locator.dart'; +export 'src/navigation/navigation_service.dart'; +export 'src/navigation/page_route_builder.dart'; +export 'src/navigation/route_factory.dart'; +export 'src/overlays/completer.dart'; +export 'src/viewmodels/base_viewmodel.dart'; +export 'src/viewmodels/data_viewmodel.dart'; +export 'src/views/fluorflow_view.dart'; diff --git a/packages/fluorflow/lib/src/annotations/bottom_sheet_config.dart b/packages/fluorflow/lib/src/annotations/bottom_sheet_config.dart new file mode 100644 index 0000000..e4e54b5 --- /dev/null +++ b/packages/fluorflow/lib/src/annotations/bottom_sheet_config.dart @@ -0,0 +1,23 @@ +/// Configuration options for a bottom sheet. +/// +/// It specifies the default barrier color, fullscreen mode, and draggable behavior. +class BottomSheetConfig { + /// The default color of the barrier that appears behind the bottom sheet. + /// This is a 32 bit integer value in the format of 0xAARRGGBB. + final int defaultBarrierColor; + + /// Whether the bottom sheet should be displayed in fullscreen mode. + /// If set to true, the bottom sheet will take up the entire screen. + /// If set to false, the bottom sheet will be displayed at the bottom third(-ish) of the screen. + final bool defaultFullscreen; + + /// Whether the bottom sheet can be dragged by the user. + final bool defaultDraggable; + + /// Decorate a bottom sheet or simple bottomsheet with a [BottomSheetConfig]. + const BottomSheetConfig({ + this.defaultBarrierColor = 0x80000000, + this.defaultFullscreen = false, + this.defaultDraggable = true, + }); +} diff --git a/packages/fluorflow/lib/src/annotations/dialog_config.dart b/packages/fluorflow/lib/src/annotations/dialog_config.dart new file mode 100644 index 0000000..ad9bdbe --- /dev/null +++ b/packages/fluorflow/lib/src/annotations/dialog_config.dart @@ -0,0 +1,22 @@ +import '../navigation/route_builder.dart'; + +/// Configuration class for dialogs. +class DialogConfig { + /// The default barrier (background) color for the dialog. + final int defaultBarrierColor; + + /// The page route builder for the dialog. + final Type? pageRouteBuilder; + + /// The route builder for the dialog. + /// The routeBuilder defines the transition animations for the dialog. + /// If set to [RouteBuilder.custom], a [pageRouteBuilder] must be provided. + final RouteBuilder routeBuilder; + + /// Customize the behaviour of a dialog / simple dialog with a [DialogConfig]. + const DialogConfig({ + this.pageRouteBuilder, + this.routeBuilder = RouteBuilder.noTransition, + this.defaultBarrierColor = 0x80000000, + }); +} diff --git a/packages/fluorflow/lib/src/annotations/injectable.dart b/packages/fluorflow/lib/src/annotations/injectable.dart new file mode 100644 index 0000000..f75855c --- /dev/null +++ b/packages/fluorflow/lib/src/annotations/injectable.dart @@ -0,0 +1,134 @@ +/// A class decorator that marks a class as a singleton. +/// +/// Singletons have only one instance throughout the application. +/// +/// The [dependencies] parameter is an optional iterable of types that the singleton +/// depends on. These dependencies will be automatically resolved and injected +/// when the singleton is instantiated. +/// +/// Example usage: +/// ```dart +/// @Singleton(dependencies: [Database]) +/// class UserRepository { +/// // ... +/// } +/// ``` +class Singleton { + final Iterable? dependencies; + + const Singleton({this.dependencies}); +} + +/// Represents an asynchronously created singleton instance. +/// +/// It may contain a factory function that returns a [Future] of the singleton instance. +/// The factory function is invoked only once, and the result is cached for subsequent invocations. +/// +/// The [AsyncSingleton] can also specify a list of dependencies that are required for creating the singleton instance. +/// These dependencies can be other types or classes that need to be instantiated before the singleton can be created. +/// +/// When used on a class, the [factory] param must point to a static method or a top level function that +/// creates the instance of the singleton. +/// +/// Example on a class: +/// ```dart +/// @AsyncSingleton(factory: AsyncDemoService.create) +/// class AsyncDemoService { +/// static Future create() async { +/// return AsyncDemoService(); +/// } +/// } +/// ``` +/// +/// Example as a top level function: +/// ```dart +/// @AsyncSingleton() +/// Future createAsyncFactoryDemoService() async { +/// return AsyncFactoryDemoService(); +/// } +/// +/// class AsyncFactoryDemoService {} +/// ``` +class AsyncSingleton { + final Future Function()? factory; + final Iterable? dependencies; + + const AsyncSingleton({this.factory, this.dependencies}); +} + +/// Annotation used to mark a class as a lazy singleton. +/// +/// A lazy singleton is a class that is instantiated only once and its +/// instance is lazily created when it is first accessed. +/// +/// Usage: +/// ``` +/// @LazySingleton() +/// class MyClass { +/// // class implementation +/// } +/// ``` +/// +/// Note: When this annotation is used, dependencies are automatically resolved and injected. +final class LazySingleton { + const LazySingleton(); +} + +/// Annotation used to mark a function as a dependency factory. +/// +/// Factories are used in dependency injection to create instances of a dependency every +/// time they are called. This is sometimes referenced as "transient" or "non-singleton" instances. +/// +/// When using a factory, a method extension on the `Locator` is generated to provide an +/// easy way to call the factory method. +/// +/// Example usage: +/// +/// ```dart +/// @Factory() +/// MyService createMyService() => MyService(); +/// +/// class MyService { +/// // class implementation +/// } +/// ``` +/// +/// Because of a design decision of the underlying dependency injection library, factories +/// can have a maximum of 2 parameters. If you need more parameters, consider using an object +/// as parameter. +final class Factory { + const Factory(); +} + +/// Annotation used to indicate that a dependency should be ignored by the dependency injection system. +/// +/// The [IgnoreDependency] annotation can be applied to a class/factory to specify that it should +/// not be included in the dependency injection container. +/// By default, the dependency is ignored in both the production and test dependency injection containers. +/// The [inLocator] and [inTestLocator] parameters can be used to control whether +/// the dependency should be included in the production and test dependency injection containers respectively. +/// +/// Example usage: +/// ```dart +/// @IgnoreDependency(inLocator: false) +/// class MyService { +/// // ... +/// } +/// ``` +class IgnoreDependency { + final bool inLocator; + final bool inTestLocator; + + const IgnoreDependency({this.inLocator = true, this.inTestLocator = true}); +} + +/// An annotation used to mark a function as a custom locator function. +/// +/// This function is directly passed to the locator in the setup function. +final class CustomLocatorFunction { + final bool includeInLocator; + final bool includeInTestLocator; + + const CustomLocatorFunction( + {this.includeInLocator = true, this.includeInTestLocator = true}); +} diff --git a/packages/fluorflow/lib/src/annotations/routable.dart b/packages/fluorflow/lib/src/annotations/routable.dart new file mode 100644 index 0000000..6eed8c2 --- /dev/null +++ b/packages/fluorflow/lib/src/annotations/routable.dart @@ -0,0 +1,46 @@ +import '../navigation/route_builder.dart'; + +/// An annotation class used to mark a class / view as routable. +/// +/// The [Routable] class is used to annotate a class that can be navigated to within a routing system. +/// It provides options for configuring the navigation behavior, such as whether to navigate to the view, +/// replace the current route with the view, or make a root navigation to the view. +/// +/// The [path] parameter can be used to specify a custom path for the routable class. +/// The [pageRouteBuilder] parameter can be used to specify a custom page route builder for the routable class. +/// The [routeBuilder] parameter can be used to specify a custom route builder for the routable class. +/// The [navigateToExtension] defines whether the method extension on the navigation service contains a navigateTo method. +/// The [replaceWithExtension] defines whether the method extension on the navigation service contains a replaceWith method. +/// The [rootToExtension] defines whether the method extension on the navigation service contains a rootTo method. +/// +/// Example usage: +/// ```dart +/// @Routable( +/// replaceWithExtension: false, +/// rootToExtension: false, +/// path: '/home', +/// routeBuilder: RouteBuilder.leftToRight, +/// ) +/// class MyRoutableClass extends FluorFlowView { +/// // class implementation +/// } +/// ``` +class Routable { + final bool navigateToExtension; + final bool replaceWithExtension; + final bool rootToExtension; + + final String? path; + + final Type? pageRouteBuilder; + final RouteBuilder routeBuilder; + + const Routable({ + this.navigateToExtension = true, + this.replaceWithExtension = true, + this.rootToExtension = true, + this.path, + this.pageRouteBuilder, + this.routeBuilder = RouteBuilder.noTransition, + }); +} diff --git a/packages/fluorflow/lib/src/bottom_sheets/bottom_sheet.dart b/packages/fluorflow/lib/src/bottom_sheets/bottom_sheet.dart new file mode 100644 index 0000000..df94c79 --- /dev/null +++ b/packages/fluorflow/lib/src/bottom_sheets/bottom_sheet.dart @@ -0,0 +1,28 @@ +import '../overlays/overlay.dart'; +import '../viewmodels/viewmodel.dart'; + +/// An abstract base class for FluorFlow bottom sheets. +/// +/// This class extends [FluorFlowOverlay] and provides a base implementation for bottom sheets in the FluorFlow package. +/// It takes a generic type parameter [TResult] representing the result type of the bottom sheet, +/// and [TViewModel] representing the view model type. +/// +/// The return type can be omitted if no result is required from the bottom sheet. Then the return +/// type defaults to `dynamic`. Further, it can be set to `void` explicitly if no result is required. +/// +/// If no view model is required, a simple version of the bottom sheet can be used. +/// +/// Subclasses of this class should provide their own implementation for the bottom sheet UI and behavior. +/// +/// Example usage: +/// ```dart +/// class MyBottomSheet extends FluorFlowBottomSheet { +/// const MyBottomSheet({super.key, required super.completer}); +/// +/// // Provide implementation for the bottom sheet UI and behavior +/// } +/// ``` +abstract base class FluorFlowBottomSheet + extends FluorFlowOverlay { + const FluorFlowBottomSheet({super.key, required super.completer}); +} diff --git a/packages/fluorflow/lib/src/bottom_sheets/bottom_sheet_service.dart b/packages/fluorflow/lib/src/bottom_sheets/bottom_sheet_service.dart new file mode 100644 index 0000000..3d12979 --- /dev/null +++ b/packages/fluorflow/lib/src/bottom_sheets/bottom_sheet_service.dart @@ -0,0 +1,32 @@ +import 'dart:ui'; + +import 'package:get/get.dart'; + +import '../overlays/overlay.dart'; + +/// A service for showing and closing bottom sheets. +/// Works with [FluorFlowOverlay] instances. +class BottomSheetService { + /// Returns whether a bottom sheet is currently open. + bool get isDialogOpen => Get.isBottomSheetOpen ?? false; + + /// Shows a bottom sheet and returns a future with the result. + /// Use the convenience methods generated by the generator to show a bottom sheet + /// and return the result in an easy way. + Future showBottomSheet( + TSheet sheet, { + Color barrierColor = const Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + }) => + Get.bottomSheet( + sheet, + barrierColor: barrierColor, + isScrollControlled: fullscreen, + enableDrag: draggable, + ); + + /// Closes the currently open bottom sheet. + void closeSheet({bool? confirmed, T? result}) => + Get.back(result: (confirmed, result)); +} diff --git a/packages/fluorflow/lib/src/bottom_sheets/simple_bottom_sheet.dart b/packages/fluorflow/lib/src/bottom_sheets/simple_bottom_sheet.dart new file mode 100644 index 0000000..5809a6f --- /dev/null +++ b/packages/fluorflow/lib/src/bottom_sheets/simple_bottom_sheet.dart @@ -0,0 +1,18 @@ +import '../overlays/simple_overlay.dart'; + +/// A base class for creating simple bottom sheets in FluorFlow. +/// +/// This abstract class extends [FluorFlowSimpleOverlay] and provides a base +/// implementation for creating bottom sheets in FluorFlow. It takes a generic +/// type parameter `TResult` which represents the type of the result that will +/// be returned when the bottom sheet is dismissed. The returntype can be `dynamic` (default) +/// or `void` as well. +/// +/// Subclasses should override this class and provide their own implementation +/// for the bottom sheet content. +/// +/// When more complex UI and behavior is required, use [FluorFlowBottomSheet]. +abstract base class FluorFlowSimpleBottomSheet + extends FluorFlowSimpleOverlay { + const FluorFlowSimpleBottomSheet({super.key, required super.completer}); +} diff --git a/packages/fluorflow/lib/src/cli/base.dart b/packages/fluorflow/lib/src/cli/base.dart new file mode 100644 index 0000000..dadc71a --- /dev/null +++ b/packages/fluorflow/lib/src/cli/base.dart @@ -0,0 +1,9 @@ +import 'package:args/args.dart'; +import 'package:args/command_runner.dart'; + +abstract class BaseCommand extends Command { + ArgResults get args => argResults!; + + // ignore: avoid_print + void log(String msg) => print(msg); +} diff --git a/packages/fluorflow/lib/src/cli/config.dart b/packages/fluorflow/lib/src/cli/config.dart new file mode 100644 index 0000000..9697936 --- /dev/null +++ b/packages/fluorflow/lib/src/cli/config.dart @@ -0,0 +1,24 @@ +import 'dart:io'; + +import 'package:yaml/yaml.dart'; + +const _configFileName = 'pubspec.yaml'; + +final class FluorflowConfig { + final dynamic _config; + final dynamic _pubspec; + + FluorflowConfig._(this._pubspec) : _config = _pubspec?['fluorflow']; + + String get packageName => _pubspec?['name'] ?? 'unknown'; + + String get viewDirectory => _config?['view_directory'] ?? 'lib/ui/views'; + + String get testViewDirectory => + _config?['test_view_directory'] ?? 'test/ui/views'; + + static Future load() async { + final pubspec = loadYaml(await File(_configFileName).readAsString()); + return FluorflowConfig._(pubspec); + } +} diff --git a/packages/fluorflow/lib/src/cli/generate.dart b/packages/fluorflow/lib/src/cli/generate.dart new file mode 100644 index 0000000..b2b1325 --- /dev/null +++ b/packages/fluorflow/lib/src/cli/generate.dart @@ -0,0 +1,18 @@ +import 'base.dart'; +import 'generate/view.dart'; + +class Generate extends BaseCommand { + @override + String get name => 'generate'; + + @override + String get description => + 'Generate code files for your project (aliases: $aliases).'; + + @override + List get aliases => ['g', 'gen']; + + Generate() { + addSubcommand(View()); + } +} diff --git a/packages/fluorflow/lib/src/cli/generate/view.dart b/packages/fluorflow/lib/src/cli/generate/view.dart new file mode 100644 index 0000000..7fa9b75 --- /dev/null +++ b/packages/fluorflow/lib/src/cli/generate/view.dart @@ -0,0 +1,228 @@ +import 'dart:io'; + +import 'package:args/args.dart'; +import 'package:args/command_runner.dart'; +import 'package:code_builder/code_builder.dart'; +import 'package:path/path.dart' as p; +import 'package:recase/recase.dart'; + +import '../../extensions/library.dart'; +import '../base.dart'; +import '../config.dart'; + +extension on ArgResults { + bool get noTests => this['no-tests']; + + bool get stdout => this['stdout']; +} + +class View extends BaseCommand { + View() { + argParser.addFlag('no-tests', + defaultsTo: false, + help: 'Do not generate tests for the view.', + negatable: false); + argParser.addFlag('stdout', + help: 'Print the generated code to stdout instead of writing to file.', + defaultsTo: false, + negatable: false); + } + + @override + String get name => 'view'; + + @override + String get description => [ + 'Generate a view with viewmodel (aliases: $aliases).', + 'The view is - depending on the configuration - generated', + 'in the presented directories (from the arguments)', + 'or if the arguments are omitted, the directories from', + 'the configuration is used.', + ].join('\n'); + + @override + List get aliases => ['v']; + + @override + String get invocation => + '${super.invocation} name '; + + @override + Future run() async { + final config = await FluorflowConfig.load(); + final (name, baseViewDirectory, testDirectory) = switch (args.rest) { + [final name, ...] when args.stdout => (name, 'stdout', 'stdout'), + [final name, final viewDirectory, final testDirectory] => ( + name, + viewDirectory, + testDirectory + ), + [final _, final _] when !args.noTests => throw UsageException( + 'If a view directory is provided, ' + 'the test directory must be provided as well. ' + 'Except when the --no-tests flag is set.', + usage), + [final name, final viewDirectory] when args.noTests => ( + name, + viewDirectory, + null + ), + [final name] => (name, config.viewDirectory, config.testViewDirectory), + _ => throw UsageException( + 'At least the name of the view must be provided.', usage), + }; + + final baseName = name.replaceFirst(RegExp(r'[Vv]iew$'), ''); + final viewName = '${baseName}View'.pascalCase; + final viewFile = '${viewName.snakeCase}.dart'; + final viewModelFile = '${baseName.toLowerCase()}_viewmodel.dart'; + final viewTestFile = p.setExtension(viewFile, '_test.dart'); + final viewModelTestFile = p.setExtension(viewModelFile, '_test.dart'); + + await _output(p.join(baseViewDirectory, baseName.toLowerCase(), viewFile), + _view(viewName, viewModelFile)); + await _output( + p.join(baseViewDirectory, baseName.toLowerCase(), viewModelFile), + _viewModel('${viewName}Model')); + if (!args.noTests && testDirectory != null) { + await _output( + p.join(testDirectory, viewTestFile), + _viewTest(viewName, config.packageName, + p.join(baseViewDirectory, baseName.toLowerCase(), viewFile))); + await _output( + p.join(testDirectory, viewModelTestFile), + _viewModelTest( + '${viewName}Model', + config.packageName, + p.join( + baseViewDirectory, baseName.toLowerCase(), viewModelFile))); + } + } + + Future _output(String filename, Library content) async { + if (args.stdout) { + log(filename); + log(content.toOutput()); + } else { + log('Write $filename.'); + await File(filename) + .create(recursive: true) + .then((f) => f.writeAsString(content.toOutput())); + } + } + + Library _viewModel(String name) => Library((b) => b.body.add(Class((b) => b + ..name = name + ..modifier = ClassModifier.final$ + ..extend = refer('BaseViewModel', 'package:fluorflow/fluorflow.dart')))); + + Library _view(String name, String viewModelFile) => + Library((b) => b.body.add(Class((b) => b + ..name = name + ..modifier = ClassModifier.final$ + ..annotations + .add(refer('Routable()', 'package:fluorflow/annotations.dart')) + ..extend = TypeReference((b) => b + ..symbol = 'FluorFlowView' + ..url = 'package:fluorflow/fluorflow.dart' + ..types.add(TypeReference((b) => b + ..symbol = '${name}Model' + ..url = viewModelFile))) + ..constructors.add(Constructor((b) => b + ..constant = true + ..optionalParameters.add(Parameter((b) => b + ..name = 'key' + ..named = true + ..toSuper = true)))) + ..methods.add(Method((b) => b + ..name = 'builder' + ..annotations.add(refer('override')) + ..returns = refer('Widget', 'package:flutter/widgets.dart') + ..requiredParameters.add(Parameter((b) => b + ..name = 'context' + ..type = refer('BuildContext', 'package:flutter/widgets.dart'))) + ..requiredParameters.add(Parameter((b) => b + ..name = 'viewModel' + ..type = refer('${name}Model'))) + ..requiredParameters.add(Parameter((b) => b + ..name = 'child' + ..type = refer('Widget?', 'package:flutter/widgets.dart'))) + ..lambda = true + ..body = refer('Placeholder', 'package:flutter/widgets.dart') + .constInstance([]).code)) + ..methods.add(Method((b) => b + ..name = 'viewModelBuilder' + ..annotations.add(refer('override')) + ..returns = refer('${name}Model', viewModelFile) + ..requiredParameters.add(Parameter((b) => b + ..name = 'context' + ..type = refer('BuildContext', 'package:flutter/widgets.dart'))) + ..lambda = true + ..body = + refer('${name}Model', viewModelFile).newInstance([]).code))))); + + Library _viewTest(String name, String packageName, String viewFile) => + Library((b) => b + ..body.add(Method((b) => b + ..name = 'main' + ..returns = refer('void') + ..lambda = true + ..body = + refer('group', 'package:flutter_test/flutter_test.dart').call([ + literalString(name), + Method((b) => b.body = Block.of([ + refer('testWidgets', 'package:flutter_test/flutter_test.dart') + .call([ + literalString('should render'), + Method((b) => b + ..requiredParameters + .add(Parameter((b) => b.name = 'tester')) + ..modifier = MethodModifier.async + ..body = Block.of([ + refer('tester') + .property('pumpWidget') + .call([ + refer(name, + 'package:$packageName/${viewFile.replaceFirst("lib/", "")}') + .constInstance([]) + ]) + .awaited + .statement, + refer('expect').call([ + refer('find').property('byType').call([ + refer('Placeholder', 'package:flutter/widgets.dart') + ]), + refer('findsOneWidget') + ]).statement, + ])).closure, + ]).statement, + ])).closure + ]).code))); + + Library _viewModelTest( + String name, String packageName, String viewModelFile) => + Library((b) => b + ..body.add(Method((b) => b + ..name = 'main' + ..returns = refer('void') + ..lambda = true + ..body = + refer('group', 'package:flutter_test/flutter_test.dart').call([ + literalString(name), + Method((b) => b.body = Block.of([ + refer('test', 'package:flutter_test/flutter_test.dart').call([ + literalString('should instantiate'), + Method((b) => b + ..body = Block.of([ + declareFinal('viewModel') + .assign(refer(name, + 'package:$packageName/${viewModelFile.replaceFirst("lib/", "")}') + .newInstance([])) + .statement, + refer('expect').call( + [refer('viewModel'), refer('isNotNull')]).statement, + ])).closure, + ]).statement, + ])).closure + ]).code))); +} diff --git a/packages/fluorflow/lib/src/dialogs/dialog.dart b/packages/fluorflow/lib/src/dialogs/dialog.dart new file mode 100644 index 0000000..2acc1c7 --- /dev/null +++ b/packages/fluorflow/lib/src/dialogs/dialog.dart @@ -0,0 +1,24 @@ +import '../overlays/overlay.dart'; +import '../viewmodels/viewmodel.dart'; + +/// An abstract base class for FluorFlow dialogs. +/// +/// This class extends [FluorFlowOverlay] and provides a base implementation for dialogs in the FluorFlow package. +/// It is intended to be subclassed and customized for specific dialog implementations. +/// +/// The generic type parameters are: +/// - [TResult]: The type of the result that the dialog returns. (Defaults to `dynamic` if not specified) +/// - [TViewModel]: The type of the view model associated with the dialog. +/// +/// If no view model is required, a simple version of the dialog can be used. +/// +/// Example usage: +/// ```dart +/// class MyDialog extends FluorFlowDialog { +/// const MyDialog({super.key, required super.completer}); +/// } +/// ``` +abstract base class FluorFlowDialog + extends FluorFlowOverlay { + const FluorFlowDialog({super.key, required super.completer}); +} diff --git a/packages/fluorflow/lib/src/dialogs/dialog_service.dart b/packages/fluorflow/lib/src/dialogs/dialog_service.dart new file mode 100644 index 0000000..21f2c37 --- /dev/null +++ b/packages/fluorflow/lib/src/dialogs/dialog_service.dart @@ -0,0 +1,28 @@ +import 'package:flutter/widgets.dart'; +import 'package:get/get.dart'; + +/// A service for showing and closing dialogs. +/// Works with route builders. However, it is recommended to use the +/// convenience methods generated by the generator to show a dialog. +class DialogService { + /// Returns whether a dialog is currently open. + bool get isDialogOpen => Get.isDialogOpen ?? false; + + /// Shows a dialog and returns a future with the (possible) result. + /// The [barrierColor] parameter can be used to specify a custom barrier color for the dialog. + Future showDialog({ + required PageRouteBuilder dialogBuilder, + Color barrierColor = const Color(0x80000000), + }) => + Get.generalDialog( + pageBuilder: dialogBuilder.pageBuilder, + barrierColor: barrierColor, + transitionDuration: dialogBuilder.transitionDuration, + routeSettings: dialogBuilder.settings, + transitionBuilder: dialogBuilder.transitionsBuilder, + ); + + /// Closes the currently open dialog. + void closeDialog({bool? confirmed, T? result}) => + Get.back(result: (confirmed, result)); +} diff --git a/packages/fluorflow/lib/src/dialogs/simple_dialog.dart b/packages/fluorflow/lib/src/dialogs/simple_dialog.dart new file mode 100644 index 0000000..faf50b0 --- /dev/null +++ b/packages/fluorflow/lib/src/dialogs/simple_dialog.dart @@ -0,0 +1,13 @@ +import '../overlays/simple_overlay.dart'; + +/// Base class for creating simple dialogs in FluorFlow. +/// +/// This abstract class extends [FluorFlowSimpleOverlay] and provides a base implementation for simple dialogs. +/// It takes a [completer] parameter which is required for handling the result of the dialog. +/// Subclasses should override this class and provide their own implementation. +/// +/// More complex UI and behavior can be achieved by using [FluorFlowDialog]. +abstract base class FluorFlowSimpleDialog + extends FluorFlowSimpleOverlay { + const FluorFlowSimpleDialog({super.key, required super.completer}); +} diff --git a/packages/fluorflow/lib/src/extensions/library.dart b/packages/fluorflow/lib/src/extensions/library.dart new file mode 100644 index 0000000..8af506c --- /dev/null +++ b/packages/fluorflow/lib/src/extensions/library.dart @@ -0,0 +1,10 @@ +import 'package:code_builder/code_builder.dart'; +import 'package:dart_style/dart_style.dart'; + +extension Utilities on Library { + String toOutput() => DartFormatter().format(accept(DartEmitter( + allocator: Allocator(), + useNullSafetySyntax: true, + orderDirectives: true)) + .toString()); +} diff --git a/packages/fluorflow/lib/src/locator/locator.dart b/packages/fluorflow/lib/src/locator/locator.dart new file mode 100644 index 0000000..0217d5d --- /dev/null +++ b/packages/fluorflow/lib/src/locator/locator.dart @@ -0,0 +1,7 @@ +import 'package:get_it/get_it.dart'; + +/// Alias for GetIt. This is the dependency locator (container) for the app. +typedef Locator = GetIt; + +/// The global locator instance. +final locator = GetIt.instance; diff --git a/packages/fluorflow/lib/src/navigation/navigation_service.dart b/packages/fluorflow/lib/src/navigation/navigation_service.dart new file mode 100644 index 0000000..b28f767 --- /dev/null +++ b/packages/fluorflow/lib/src/navigation/navigation_service.dart @@ -0,0 +1,111 @@ +import 'package:flutter/widgets.dart'; +import 'package:get/get.dart'; + +/// A service that provides a set of methods to navigate between routes. +/// One may directly use the [navigateTo] and other methods to navigate dynamically. +/// However, in combination with the `fluorflow_generator`, convenience methods are created +/// as method extensions for this service. +/// +/// To allow navigation with this package/service, the main entrypoint of the app needs +/// to be modified. The properties `initialRoute`, `onGenerateRoute`, `navigatorKey`, and +/// `navigatorObservers` need to be set to the corresponding values of this service. +/// +/// Example entrypoint: +/// ```dart +/// import 'app.router.dart'; +/// +/// void main() async { +/// runApp(const MyApp()); +/// } +/// +/// class MyApp extends StatelessWidget { +/// const MyApp({super.key}); +/// +/// @override +/// Widget build(BuildContext context) { +/// return MaterialApp( +/// title: 'FluorFlow Demo', +/// theme: ThemeData( +/// colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), +/// useMaterial3: true, +/// ), +/// initialRoute: AppRoute.homeView.path, +/// onGenerateRoute: onGenerateRoute, +/// navigatorKey: NavigationService.navigatorKey, +/// navigatorObservers: [NavigationService.observer()], +/// ); +/// } +/// } +/// ``` +class NavigationService { + /// Static navigator key to be used in the main entrypoint of the app. + /// This allows navigation without context of the build method. + static GlobalKey get navigatorKey => Get.key; + + /// Static navigator observer to be used in the main entrypoint of the app. + /// Required for adjusting the navigation stack. + static NavigatorObserver observer() => GetObserver(null, Get.routing); + + /// Returns the previous route name. + String get previousRoute => Get.previousRoute; + + /// Returns the current route name. + String get currentRoute => Get.currentRoute; + + /// Returns the current route arguments (`dynamic` typed). + dynamic get currentArguments => Get.arguments; + + /// Returns the current route arguments (`T` typed). + T typedArguments() => Get.arguments; + + /// Navigate "back" and return an optional result. + void back({T? result}) => Get.back(result: result); + + /// Pops the route stack until the predicate is fulfilled. + void popUntil(RoutePredicate predicate) => Get.until(predicate); + + /// Navigate to a new route and return an optional result + /// when back is called from the new route. This pushes + /// the new route onto the navigation stack. + Future? navigateTo( + String routeName, { + dynamic arguments, + bool preventDuplicates = true, + Map? parameters, + }) => + Get.toNamed( + routeName, + arguments: arguments, + preventDuplicates: preventDuplicates, + parameters: parameters, + ); + + /// Navigate to a new route and replace the current route on the + /// navigation stack. + void replaceWith( + String routeName, { + dynamic arguments, + bool preventDuplicates = true, + Map? parameters, + RouteTransitionsBuilder? transition, + }) => + Get.offNamed( + routeName, + arguments: arguments, + preventDuplicates: preventDuplicates, + parameters: parameters, + ); + + /// Navigate to a new route and remove all previous routes from the + /// navigation stack. + void rootTo( + String routeName, { + dynamic arguments, + Map? parameters, + }) => + Get.offAllNamed( + routeName, + arguments: arguments, + parameters: parameters, + ); +} diff --git a/packages/fluorflow/lib/src/navigation/page_route_builder.dart b/packages/fluorflow/lib/src/navigation/page_route_builder.dart new file mode 100644 index 0000000..f11aee9 --- /dev/null +++ b/packages/fluorflow/lib/src/navigation/page_route_builder.dart @@ -0,0 +1,199 @@ +import 'package:flutter/widgets.dart'; + +/// A custom page route builder that provides a page transition without any animation. +class NoTransitionPageRouteBuilder extends PageRouteBuilder { + NoTransitionPageRouteBuilder({super.settings, required super.pageBuilder}); +} + +/// A custom page route builder that provides a fade-in transition effect. +class FadeInPageRouteBuilder extends PageRouteBuilder { + FadeInPageRouteBuilder({super.settings, required super.pageBuilder}) + : super( + transitionsBuilder: + (context, animation, secondaryAnimation, child) => + FadeTransition(opacity: animation, child: child)); +} + +/// A custom page route builder that provides a left to right fade transition effect. +class LeftToRightFadePageRouteBuilder extends PageRouteBuilder { + LeftToRightFadePageRouteBuilder({super.settings, required super.pageBuilder}) + : super( + transitionsBuilder: + (context, animation, secondaryAnimation, child) => + SlideTransition( + position: Tween( + begin: const Offset(-1.0, 0.0), + end: Offset.zero, + ).animate(animation), + child: FadeTransition( + opacity: animation, + child: SlideTransition( + position: Tween( + begin: Offset.zero, + end: const Offset(1.0, 0.0), + ).animate(secondaryAnimation), + child: child), + ), + )); +} + +/// A custom page route builder that provides a right to left fade transition effect. +class RightToLeftFadePageRouteBuilder extends PageRouteBuilder { + RightToLeftFadePageRouteBuilder({super.settings, required super.pageBuilder}) + : super( + transitionsBuilder: + (context, animation, secondaryAnimation, child) => + SlideTransition( + position: Tween( + begin: const Offset(1.0, 0.0), + end: Offset.zero, + ).animate(animation), + child: FadeTransition( + opacity: animation, + child: SlideTransition( + position: Tween( + begin: Offset.zero, + end: const Offset(-1.0, 0.0), + ).animate(secondaryAnimation), + child: child), + ), + )); +} + +/// A custom page route builder that provides a top to bottom fade transition effect. +class TopToBottomFadePageRouteBuilder extends PageRouteBuilder { + TopToBottomFadePageRouteBuilder({super.settings, required super.pageBuilder}) + : super( + transitionsBuilder: + (context, animation, secondaryAnimation, child) => + SlideTransition( + position: Tween( + begin: const Offset(0.0, -1.0), + end: Offset.zero, + ).animate(animation), + child: FadeTransition( + opacity: animation, + child: SlideTransition( + position: Tween( + begin: Offset.zero, + end: const Offset(0.0, 1.0), + ).animate(secondaryAnimation), + child: child), + ), + )); +} + +/// A custom page route builder that provides a bottom to top fade transition effect. +class BottomToTopFadePageRouteBuilder extends PageRouteBuilder { + BottomToTopFadePageRouteBuilder({super.settings, required super.pageBuilder}) + : super( + transitionsBuilder: + (context, animation, secondaryAnimation, child) => + SlideTransition( + position: Tween( + begin: const Offset(0.0, 1.0), + end: Offset.zero, + ).animate(animation), + child: FadeTransition( + opacity: animation, + child: SlideTransition( + position: Tween( + begin: Offset.zero, + end: const Offset(0.0, -1.0), + ).animate(secondaryAnimation), + child: child), + ), + )); +} + +/// A custom page route builder that provides a left to right transition effect. +class LeftToRightPageRouteBuilder extends PageRouteBuilder { + LeftToRightPageRouteBuilder({super.settings, required super.pageBuilder}) + : super( + transitionsBuilder: + (context, animation, secondaryAnimation, child) => + SlideTransition( + position: Tween( + begin: const Offset(-1.0, 0.0), + end: Offset.zero, + ).animate(animation), + child: SlideTransition( + position: Tween( + begin: Offset.zero, + end: const Offset(1.0, 0.0), + ).animate(secondaryAnimation), + child: child), + )); +} + +/// A custom page route builder that provides a right to left transition effect. +class RightToLeftPageRouteBuilder extends PageRouteBuilder { + RightToLeftPageRouteBuilder({super.settings, required super.pageBuilder}) + : super( + transitionsBuilder: + (context, animation, secondaryAnimation, child) => + SlideTransition( + position: Tween( + begin: const Offset(1.0, 0.0), + end: Offset.zero, + ).animate(animation), + child: SlideTransition( + position: Tween( + begin: Offset.zero, + end: const Offset(-1.0, 0.0), + ).animate(secondaryAnimation), + child: child), + )); +} + +/// A custom page route builder that provides a top to bottom transition effect. +class TopToBottomPageRouteBuilder extends PageRouteBuilder { + TopToBottomPageRouteBuilder({super.settings, required super.pageBuilder}) + : super( + transitionsBuilder: + (context, animation, secondaryAnimation, child) => + SlideTransition( + position: Tween( + begin: const Offset(0.0, -1.0), + end: Offset.zero, + ).animate(animation), + child: SlideTransition( + position: Tween( + begin: Offset.zero, + end: const Offset(0.0, 1.0), + ).animate(secondaryAnimation), + child: child), + )); +} + +/// A custom page route builder that provides a bottom to top transition effect. +class BottomToTopPageRouteBuilder extends PageRouteBuilder { + BottomToTopPageRouteBuilder({super.settings, required super.pageBuilder}) + : super( + transitionsBuilder: + (context, animation, secondaryAnimation, child) => + SlideTransition( + position: Tween( + begin: const Offset(0.0, 1.0), + end: Offset.zero, + ).animate(animation), + child: SlideTransition( + position: Tween( + begin: Offset.zero, + end: const Offset(0.0, -1.0), + ).animate(secondaryAnimation), + child: child), + )); +} + +/// A custom page route builder that provides a zoom-in transition effect. +class ZoomInPageRouteBuilder extends PageRouteBuilder { + ZoomInPageRouteBuilder({super.settings, required super.pageBuilder}) + : super( + transitionsBuilder: + (context, animation, secondaryAnimation, child) => + ScaleTransition( + scale: animation, + child: child, + )); +} diff --git a/packages/fluorflow/lib/src/navigation/route_builder.dart b/packages/fluorflow/lib/src/navigation/route_builder.dart new file mode 100644 index 0000000..b9c272c --- /dev/null +++ b/packages/fluorflow/lib/src/navigation/route_builder.dart @@ -0,0 +1,38 @@ +/// Enum representing different types of route builders for navigation transitions. +enum RouteBuilder { + /// No transition. + noTransition, + + /// Fade in transition. + fadeIn, + + /// Left to right fade transition. + leftToRightFade, + + /// Right to left fade transition. + rightToLeftFade, + + /// Top to bottom fade transition. + topToBottomFade, + + /// Bottom to top fade transition. + bottomToTopFade, + + /// Left to right transition. + leftToRight, + + /// Right to left transition. + rightToLeft, + + /// Top to bottom transition. + topToBottom, + + /// Bottom to top transition. + bottomToTop, + + /// Zoom in transition. + zoomIn, + + /// Custom transition. + custom, +} diff --git a/packages/fluorflow/lib/src/navigation/route_factory.dart b/packages/fluorflow/lib/src/navigation/route_factory.dart new file mode 100644 index 0000000..922e0c0 --- /dev/null +++ b/packages/fluorflow/lib/src/navigation/route_factory.dart @@ -0,0 +1,8 @@ +import 'package:flutter/widgets.dart'; + +/// Map that contains a set of routes (by name) and their corresponding route factories. +typedef RouteMap = Map; + +/// Create a route factory for a given route map. +RouteFactory generateRouteFactory(RouteMap map) => + (settings) => map[settings.name]?.call(settings); diff --git a/packages/fluorflow/lib/src/overlays/completer.dart b/packages/fluorflow/lib/src/overlays/completer.dart new file mode 100644 index 0000000..a9622a2 --- /dev/null +++ b/packages/fluorflow/lib/src/overlays/completer.dart @@ -0,0 +1,21 @@ +/// Function / Callback type for completing overlays. +/// Overlays are dialogs, bottom sheets, snackbars, etc. +/// +/// The Type [T] represents the type of the result that is returned by the overlay. +/// It may be void. +typedef OverlayCompleter = void Function({bool? confirmed, T? result}); + +/// A set of extensions for [OverlayCompleter]. +extension CompleterExtensions on OverlayCompleter { + /// Confirm the dialog and return the result. + /// This sets [confirmed] to true. + void confirm([T? result]) => call(confirmed: true, result: result); + + /// Cancels a dialog and sets [confirmed] to false. + /// This is used when the user actively declines the dialog. + void cancel([T? result]) => call(confirmed: false, result: result); + + /// Aborts the dialog and ignores confirmation and the result. + /// Both values are null. + void abort() => call(); +} diff --git a/packages/fluorflow/lib/src/overlays/noop_viewmodel.dart b/packages/fluorflow/lib/src/overlays/noop_viewmodel.dart new file mode 100644 index 0000000..747f11d --- /dev/null +++ b/packages/fluorflow/lib/src/overlays/noop_viewmodel.dart @@ -0,0 +1,4 @@ +import '../../fluorflow.dart'; + +/// Empty viewmodel. +final class NoopViewModel extends BaseViewModel {} diff --git a/packages/fluorflow/lib/src/overlays/overlay.dart b/packages/fluorflow/lib/src/overlays/overlay.dart new file mode 100644 index 0000000..63dca30 --- /dev/null +++ b/packages/fluorflow/lib/src/overlays/overlay.dart @@ -0,0 +1,12 @@ +import '../overlays/completer.dart'; +import '../viewmodels/viewmodel.dart'; +import '../views/fluorflow_view.dart'; + +/// Base class for fluorflow overlays such as dialogs and bottom sheets. +/// Utilizses a view model for complex UI operations. +abstract base class FluorFlowOverlay + extends FluorFlowView { + final OverlayCompleter completer; + + const FluorFlowOverlay({super.key, required this.completer}); +} diff --git a/packages/fluorflow/lib/src/overlays/simple_overlay.dart b/packages/fluorflow/lib/src/overlays/simple_overlay.dart new file mode 100644 index 0000000..67435c8 --- /dev/null +++ b/packages/fluorflow/lib/src/overlays/simple_overlay.dart @@ -0,0 +1,33 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +import 'noop_viewmodel.dart'; +import 'overlay.dart'; + +/// Simple version of the [FluorFlowOverlay] that does not require a view model. +/// The view model of the UI is defaulted to the [NoopViewModel]. +abstract base class FluorFlowSimpleOverlay + extends FluorFlowOverlay { + const FluorFlowSimpleOverlay({super.key, required super.completer}); + + @override + @nonVirtual + NoopViewModel viewModelBuilder(BuildContext context) => NoopViewModel(); + + @override + @nonVirtual + Widget builder( + BuildContext context, NoopViewModel viewModel, Widget? child) => + child!; + + @override + @nonVirtual + Widget? staticChildBuilder(BuildContext context) => build(context); + + @override + @nonVirtual + void onViewModelCreated(NoopViewModel viewModel) {} + + @protected + Widget build(BuildContext context); +} diff --git a/packages/fluorflow/lib/src/viewmodels/base_viewmodel.dart b/packages/fluorflow/lib/src/viewmodels/base_viewmodel.dart new file mode 100644 index 0000000..49a809c --- /dev/null +++ b/packages/fluorflow/lib/src/viewmodels/base_viewmodel.dart @@ -0,0 +1,99 @@ +import 'dart:async'; + +import 'package:flutter/foundation.dart'; + +import 'viewmodel.dart'; + +/// Base viewmodel that implements [ViewModel] and [ChangeNotifier]. +/// Provides basic functionality for other view models and for the usage with views. +/// +/// To create a new view model, extend this class and override the necessary methods. +/// +/// Example: +/// ```dart +/// final class MyViewModel extends BaseViewModel { +/// var _counter = 0; +/// int get counter => _counter; +/// void increment() { +/// _counter++; +/// notifyListeners(); +/// } +/// } +/// ``` +abstract base class BaseViewModel extends ChangeNotifier implements ViewModel { + var _disposed = false; + var _initialized = false; + var _busy = false; + dynamic _error; + + @nonVirtual + @override + bool get disposed => _disposed; + + @nonVirtual + @override + bool get initialized => _initialized; + + @nonVirtual + @override + bool get busy => _busy; + + @nonVirtual + @protected + set busy(bool value) { + _busy = value; + notifyListeners(); + } + + @nonVirtual + @override + bool get hasError => _error != null; + + @nonVirtual + @override + dynamic get error => _error; + + @nonVirtual + @protected + set error(dynamic value) { + _error = value; + onError(error); + notifyListeners(); + } + + /// Callback for error situations. This + /// is called when [error] is set. + @protected + void onError(dynamic error) {} + + /// Initializes the view model. + /// If overwritten in subclasses, it must call super to + /// set the initialized flag and notify listeners. + @override + @mustCallSuper + FutureOr initialize() { + _initialized = true; + notifyListeners(); + } + + /// Notifies listeners if the view model is not disposed. + /// This must be called if changes in the view model should be + /// reflected in the UI. + @nonVirtual + @override + void notifyListeners() { + if (!_disposed) { + super.notifyListeners(); + } + } + + /// Disposes the view model. + /// If overwritten in a subclass, it must call super to + /// properly dispose the view model. + @override + @mustCallSuper + void dispose() { + _disposed = true; + super.dispose(); + } +} diff --git a/packages/fluorflow/lib/src/viewmodels/data_viewmodel.dart b/packages/fluorflow/lib/src/viewmodels/data_viewmodel.dart new file mode 100644 index 0000000..c96b836 --- /dev/null +++ b/packages/fluorflow/lib/src/viewmodels/data_viewmodel.dart @@ -0,0 +1,102 @@ +import 'dart:async'; + +import 'package:flutter/foundation.dart'; + +import 'base_viewmodel.dart'; + +/// "Data" view model. Contains a data of type [TData] object that is observed for changes. +/// This view model is used to manage complex data operations and to notify the UI when the data changes. +/// The data can be of any type and is stored in a [ValueNotifier]. Since the data +/// is initialized with a call, accessing the data before the initialize method is called +/// results in a state error. +/// +/// It combines well with packages such as "freezed" to manage view state with +/// sealed classes. +/// +/// Example: +/// ```dart +/// sealed class HomeState { +/// const HomeState(); +/// } +/// +/// final class LoadingState extends HomeState { +/// const LoadingState(); +/// } +/// +/// final class LoadedState extends HomeState { +/// final String data; +/// +/// const LoadedState(this.data); +/// } +/// +/// final class HomeViewModel extends DataViewModel { +/// @override +/// FutureOr initializeData() => const LoadingState(); +/// +/// void loadData() async { +/// await Future.delayed(const Duration(seconds: 2)); +/// data = const LoadedState('Hello, World!'); +/// } +/// } +/// ``` +abstract base class DataViewModel extends BaseViewModel { + late final ValueNotifier _data; + + /// Return the data notifier for the view model. This can be used + /// to add additional listeners to data changes. + /// + /// If the view model is not initialized, a state error is thrown. + @nonVirtual + ValueNotifier get dataNotifier => + initialized ? _data : (throw StateError('ViewModel is not initialized.')); + + /// Get the current data value ([TData]). + /// + /// If the view model is not initialized, a state error is thrown. + @nonVirtual + TData get data => initialized + ? _data.value + : (throw StateError('ViewModel is not initialized.')); + + /// Set the data value ([TData]). + /// Setting the data will trigger a [notifyListeners] call. + @nonVirtual + @protected + set data(TData value) { + _data.value = value; + } + + /// Indicates whether the view model should notify listeners when the data changes. + /// This may be overwritten by subclasses to disable the notification. + @protected + bool get notifyOnDataChange => true; + + /// Initializes the data of the view model. It may return a Future or the data directly. + @protected + FutureOr initializeData(); + + /// Callback for error situations when initializing the data. + /// This also triggers the [onError] callback. + @protected + void onDataInitializeError(dynamic error) {} + + /// Initializes the data view model. + /// The data of the view model is initialized and a listener is added to the data + /// (if [notifyOnDataChange] is set). + /// + /// Subclasses that overwrite this method must call super to properly initialize the data. + @override + @mustCallSuper + FutureOr initialize() async { + try { + _data = ValueNotifier(await initializeData()); + if (notifyOnDataChange) { + _data.addListener(notifyListeners); + } + await super.initialize(); + } catch (e) { + error = e; + onDataInitializeError(e); + } + } +} diff --git a/packages/fluorflow/lib/src/viewmodels/viewmodel.dart b/packages/fluorflow/lib/src/viewmodels/viewmodel.dart new file mode 100644 index 0000000..5647020 --- /dev/null +++ b/packages/fluorflow/lib/src/viewmodels/viewmodel.dart @@ -0,0 +1,28 @@ +import 'dart:async'; + +import 'package:flutter/foundation.dart'; + +/// A base view model interface. +/// +/// This interface defines the common properties and methods that a view model should have. +abstract interface class ViewModel implements ChangeNotifier { + /// Indicates whether the view model has been disposed. + bool get disposed; + + /// Indicates whether the view model has been initialized. + bool get initialized; + + /// Indicates whether the view model is currently busy. + bool get busy; + + /// Indicates whether the view model has encountered an error. + bool get hasError; + + /// The error object associated with the view model. + dynamic get error; + + /// Initializes the view model. + /// + /// This method should be called to initialize the view model before using it. + FutureOr initialize(); +} diff --git a/packages/fluorflow/lib/src/views/fluorflow_view.dart b/packages/fluorflow/lib/src/views/fluorflow_view.dart new file mode 100644 index 0000000..cf9402e --- /dev/null +++ b/packages/fluorflow/lib/src/views/fluorflow_view.dart @@ -0,0 +1,65 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/widgets.dart'; + +import '../viewmodels/viewmodel.dart'; + +/// Base class for a view that is managed by a [ViewModel]. +/// The view model is created when the view is initialized and disposed when the view is disposed. +/// +/// When the notifyListeners method is called on the view model, the view is rebuilt. +/// +/// The [staticChildBuilder] allows a non-changing child to be built once and reused. +@immutable +abstract base class FluorFlowView + extends StatefulWidget { + const FluorFlowView({super.key}); + + /// Create the view model for the view. + @protected + TViewModel viewModelBuilder(BuildContext context); + + /// Build the view with the view model and the optional static child. + @protected + Widget builder(BuildContext context, TViewModel viewModel, Widget? child); + + /// Build the static child for the view. + /// This allows a static child, that is not dependent on the view model, to be built once and reused. + @protected + Widget? staticChildBuilder(BuildContext context) => null; + + /// Called when the view model is created. + @protected + void onViewModelCreated(TViewModel viewModel) {} + + @override + @nonVirtual + State createState() => _FluorFlowViewState(); +} + +class _FluorFlowViewState + extends State> { + late final TViewModel viewModel; + + @override + void initState() { + viewModel = widget.viewModelBuilder(context); + widget.onViewModelCreated(viewModel); + SchedulerBinding.instance + .addPostFrameCallback((timeStamp) => viewModel.initialize()); + super.initState(); + } + + @override + void dispose() { + viewModel.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => ListenableBuilder( + listenable: viewModel, + builder: (context, child) => widget.builder(context, viewModel, child), + child: widget.staticChildBuilder(context), + ); +} diff --git a/packages/fluorflow/pubspec.yaml b/packages/fluorflow/pubspec.yaml new file mode 100644 index 0000000..5b36aa2 --- /dev/null +++ b/packages/fluorflow/pubspec.yaml @@ -0,0 +1,31 @@ +name: fluorflow +description: >- + An MVVM framework for Flutter that allows easy to use MVVM based views in + Flutter apps. The package shines in combination with the generator (fluorflow_generator) + to generate extension methods for bottom sheets, routings, dialogs and services. +version: 0.0.0-development +homepage: https://github.com/smartive/fluorflow +repository: https://github.com/smartive/fluorflow.git + +environment: + sdk: '>=3.0.0 <4.0.0' + flutter: '>=1.17.0' + +dependencies: + args: ^2.4.2 + code_builder: ^4.9.0 + dart_style: ^2.3.4 + flutter: + sdk: flutter + get: ^4.6.6 + get_it: ^7.6.4 + path: ^1.8.3 + recase: ^4.1.0 + yaml: ^3.1.2 + +dev_dependencies: + build_runner: ^2.4.7 + flutter_lints: ^3.0.1 + flutter_test: + sdk: flutter + mockito: ^5.4.4 diff --git a/packages/fluorflow/test/views/fluorflow_view_test.dart b/packages/fluorflow/test/views/fluorflow_view_test.dart new file mode 100644 index 0000000..ae8354c --- /dev/null +++ b/packages/fluorflow/test/views/fluorflow_view_test.dart @@ -0,0 +1,36 @@ +import 'package:fluorflow/src/viewmodels/viewmodel.dart'; +import 'package:fluorflow/src/views/fluorflow_view.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; + +import 'fluorflow_view_test.mocks.dart'; + +final class TestView extends FluorFlowView { + final MockViewModel vm; + + const TestView(this.vm, {super.key}); + + @override + Widget builder( + BuildContext context, MockViewModel viewModel, Widget? child) => + const Placeholder(); + + @override + MockViewModel viewModelBuilder(BuildContext context) => vm; +} + +@GenerateNiceMocks([MockSpec()]) +void main() { + group('FluorFlowView', () { + testWidgets('should initialize viewmodel.', (tester) async { + final vm = MockViewModel(); + + await tester.pumpWidget(TestView(vm)); + await tester.pumpAndSettle(); + + verify(vm.initialize()).called(1); + }); + }); +} diff --git a/packages/fluorflow_generator/.gitignore b/packages/fluorflow_generator/.gitignore new file mode 100644 index 0000000..3cceda5 --- /dev/null +++ b/packages/fluorflow_generator/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/packages/fluorflow_generator/.pubignore b/packages/fluorflow_generator/.pubignore new file mode 100644 index 0000000..f90263b --- /dev/null +++ b/packages/fluorflow_generator/.pubignore @@ -0,0 +1,4 @@ +.dart_tool/ +test/ +pubspec.lock +analysis_options.yaml diff --git a/packages/fluorflow_generator/CHANGELOG.md b/packages/fluorflow_generator/CHANGELOG.md new file mode 100644 index 0000000..8ab98eb --- /dev/null +++ b/packages/fluorflow_generator/CHANGELOG.md @@ -0,0 +1 @@ +# 0.0.0-development diff --git a/packages/fluorflow_generator/LICENSE b/packages/fluorflow_generator/LICENSE new file mode 100644 index 0000000..03c4b90 --- /dev/null +++ b/packages/fluorflow_generator/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [2024] [smartive AG] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/fluorflow_generator/README.md b/packages/fluorflow_generator/README.md new file mode 100644 index 0000000..c91aada --- /dev/null +++ b/packages/fluorflow_generator/README.md @@ -0,0 +1,161 @@ +# Fluorflow Generator + +This package contains the code generator for the fluorflow framework. + +## Usage + +Add the dart build runner to your project with `flutter pub add build_runner --dev`. +Then add the fluorflow generator with `flutter pub add fluorflow_generator --dev`. +(Or use the direct git config when not using a published version) + +When the build runner is executed (`dart run build_runner build`), the code will be generated. + +Examples for the usage of the generators can be found in the `fluorflow` package. + +## Configuration + +To configure the generator, use the technique of the "build_runner". In your `build.yaml` file, +you can use `global_options` or specific options for the generators. + +Such a config file can look like this: + +```yaml +# build.yaml +global_options: + fluorflow_generator:locator: + options: + output: 'lib/app/app.locator.dart' + + fluorflow_generator:testLocator: + options: + output: 'test/helpers/test.locator.dart' + + fluorflow_generator:router: + options: + output: 'lib/app/app.router.dart' + + fluorflow_generator:dialog: + options: + output: 'lib/app/app.dialogs.dart' + + fluorflow_generator:bottomSheet: + options: + output: 'lib/app/app.bottom_sheets.dart' +``` + +### Locator Options + +- `output` (String): The file path for the generated locator file. Default: `lib/app.locator.dart`. +- `emitAllReady` (bool): Whether to emit the `await allReady()` method call in the locator setup method. Default: `true`. +- `register_services`: Whether to register services in the locator. + - `bottomSheet` (bool): Whether to register the bottom sheet service. Default: `true`. + - `dialog` (bool): Whether to register the dialog service. Default: `true`. + - `navigation` (bool): Whether to register the navigation service. Default: `true`. + +### Test Locator Options + +- `output` (String): The file path for the generated locator file. Default: `test/test.locator.dart`. +- `register_services`: Whether to register services in the locator. + - `bottomSheet` (bool): Whether to register the mock bottom sheet service. Default: `true`. + - `dialog` (bool): Whether to register the mock dialog service. Default: `true`. + - `navigation` (bool): Whether to register the mock navigation service. Default: `true`. + +### Router Options + +- `output` (String): The file path for the generated file. Default: `lib/app.router.dart`. + +### Dialog Options + +- `output` (String): The file path for the generated file. Default: `lib/app.dialogs.dart`. + +### Bottom Sheet Options + +- `output` (String): The file path for the generated file. Default: `lib/app.bottom_sheets.dart`. + +## Generators + +Currently the following generators are supported: + +- Dependency Injection +- Routing +- Dialogs +- Bottom Sheets + +### Dependency Injection + +The generator for DI uses the "GetIt" library underneath. It generates the setup method +for the GetIt locator and the locator itself. + +There are several annotations that enable dependency injection. Some of them are: + +- Singleton / LazySingleton / AsyncSingleton +- Factory + +Other annotations exist to configure the generated code. + +The generator also creates mocks if you have the `mockito` package installed. Then it +will generate a setup method that sets up all mocked services to be used in tests. + +### Routing + +When using fluorflow views, the `@Routable` annotation will generate a route for the given view. +The path will be added to the `AppRoute` enum and an extension method is generated for the +`NavigationService` of fluorflow. So a given route (`@Routable class DetailView ...`) will generate the following +code: + +```dart +enum AppRoute { + detailView('/detail-view'); + + const AppRoute(this.path); + + final String path; +} + +// some other boilerplate + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToDetailView({ + bool preventDuplicates = true, + }) => + navigateTo( + AppRoute.detailView.path, + preventDuplicates: preventDuplicates, + ); +} +``` + +The behavior of the generated extensions can be configured with the routable annotation. + +### Dialogs / Bottom Sheets + +Both of these work the same way. You just extend the `FluorFlowDialog`, `FluorFlowSimpleDialog`, +`FluorFlowBottomSheet` or `FluorFlowSimpleBottomSheet` classes. There are special annotations +for configuration of the generated code - if needed. + +When such extended classes are found, method extensions for the `DialogService` respectively +`BottomSheetService` are generated. + +An example of such a dialog method: + +```dart +extension Dialogs on _i1.DialogService { + Future<(bool?, int?)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + }) => + showDialog<(bool?, int?)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i4.MyDialog( + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +``` + +Refer to the documentation of the respective classes to see other examples and usage. diff --git a/packages/fluorflow_generator/analysis_options.yaml b/packages/fluorflow_generator/analysis_options.yaml new file mode 100644 index 0000000..794e29e --- /dev/null +++ b/packages/fluorflow_generator/analysis_options.yaml @@ -0,0 +1,15 @@ +include: package:lints/recommended.yaml + +linter: + rules: + always_declare_return_types: true + avoid_relative_lib_imports: true + eol_at_end_of_file: true + library_private_types_in_public_api: false + lines_longer_than_80_chars: false + prefer_final_fields: true + prefer_final_in_for_each: true + prefer_final_locals: true + prefer_relative_imports: true + prefer_single_quotes: true + prefer_expression_function_bodies: true diff --git a/packages/fluorflow_generator/build.yaml b/packages/fluorflow_generator/build.yaml new file mode 100644 index 0000000..106aade --- /dev/null +++ b/packages/fluorflow_generator/build.yaml @@ -0,0 +1,63 @@ +builders: + locator: + import: 'package:fluorflow_generator/fluorflow_generator.dart' + builder_factories: ['locatorBuilder'] + build_extensions: { 'lib/$lib$': ['lib/app.locator.dart'] } + auto_apply: root_package + build_to: source + defaults: + options: + emitAllReady: true + output: 'lib/app.locator.dart' + register_services: + bottomSheet: true + dialog: true + navigation: true + + testLocator: + import: 'package:fluorflow_generator/fluorflow_generator.dart' + builder_factories: ['testLocatorBuilder'] + build_extensions: { 'lib/$lib$': ['test/test.locator.dart'] } + auto_apply: root_package + build_to: source + applies_builders: + - 'mockito:mockBuilder' + runs_before: + - 'mockito:mockBuilder' + defaults: + options: + output: 'test/test.locator.dart' + services: + bottomSheet: true + dialog: true + navigation: true + + router: + import: 'package:fluorflow_generator/fluorflow_generator.dart' + builder_factories: ['routerBuilder'] + build_extensions: { 'lib/$lib$': ['lib/app.router.dart'] } + auto_apply: root_package + build_to: source + defaults: + options: + output: 'lib/app.router.dart' + + dialog: + import: 'package:fluorflow_generator/fluorflow_generator.dart' + builder_factories: ['dialogBuilder'] + build_extensions: { 'lib/$lib$': ['lib/app.dialogs.dart'] } + auto_apply: root_package + build_to: source + defaults: + options: + output: 'lib/app.dialogs.dart' + + bottomSheet: + import: 'package:fluorflow_generator/fluorflow_generator.dart' + builder_factories: ['bottomSheetBuilder'] + build_extensions: { 'lib/$lib$': ['lib/app.bottom_sheets.dart'] } + auto_apply: root_package + build_to: source + defaults: + options: + output: 'lib/app.bottom_sheets.dart' diff --git a/packages/fluorflow_generator/lib/fluorflow_generator.dart b/packages/fluorflow_generator/lib/fluorflow_generator.dart new file mode 100644 index 0000000..dbfc2b0 --- /dev/null +++ b/packages/fluorflow_generator/lib/fluorflow_generator.dart @@ -0,0 +1,19 @@ +import 'package:build/build.dart'; + +import 'src/builder/bottom_sheet_builder.dart'; +import 'src/builder/dialog_builder.dart'; +import 'src/builder/locator_builder.dart'; +import 'src/builder/router_builder.dart'; +import 'src/builder/test_locator_builder.dart'; + +Builder locatorBuilder(BuilderOptions options) => LocatorBuilder(options); + +Builder testLocatorBuilder(BuilderOptions options) => + TestLocatorBuilder(options); + +Builder routerBuilder(BuilderOptions options) => RouterBuilder(options); + +Builder dialogBuilder(BuilderOptions options) => DialogBuilder(options); + +Builder bottomSheetBuilder(BuilderOptions options) => + BottomSheetBuilder(options); diff --git a/packages/fluorflow_generator/lib/src/builder/bottom_sheet_builder.dart b/packages/fluorflow_generator/lib/src/builder/bottom_sheet_builder.dart new file mode 100644 index 0000000..a2ff431 --- /dev/null +++ b/packages/fluorflow_generator/lib/src/builder/bottom_sheet_builder.dart @@ -0,0 +1,161 @@ +import 'dart:async'; + +import 'package:analyzer/dart/element/type.dart' as analyzer; +import 'package:build/build.dart'; +import 'package:code_builder/code_builder.dart'; +import 'package:dart_style/dart_style.dart'; +import 'package:fluorflow/annotations.dart'; +import 'package:glob/glob.dart'; +import 'package:source_gen/source_gen.dart'; + +import '../utils.dart'; + +extension on BuilderOptions { + String get output => config['output'] ?? 'lib/app.bottom_sheets.dart'; +} + +class BottomSheetBuilder implements Builder { + static final _allDartFilesInLib = Glob('{lib/*.dart,lib/**/*.dart}'); + + final BuilderOptions options; + + const BottomSheetBuilder(this.options); + + @override + FutureOr build(BuildStep buildStep) async { + final output = AssetId(buildStep.inputId.package, options.output); + final resolver = buildStep.resolver; + final configChecker = TypeChecker.fromRuntime(BottomSheetConfig); + const sheetSuperTypes = [ + 'FluorFlowSimpleBottomSheet', + 'FluorFlowBottomSheet', + ]; + + var extension = Extension((b) => b + ..name = 'BottomSheets' + ..on = refer('BottomSheetService', 'package:fluorflow/fluorflow.dart')); + + await for (final assetId in buildStep.findAssets(_allDartFilesInLib)) { + if (!await resolver.isLibrary(assetId)) { + continue; + } + + final lib = LibraryReader(await resolver.libraryFor(assetId)); + + for (final (sheetClass, superType) in lib.classes + .where((c) => c.allSupertypes + .map((s) => s.element.name) + .any((s) => sheetSuperTypes.contains(s))) + .map((c) => ( + c, + c.allSupertypes + .firstWhere((s) => sheetSuperTypes.contains(s.element.name)) + ))) { + final configAnnotation = + configChecker.hasAnnotationOf(sheetClass, throwOnUnresolved: false) + ? ConstantReader(configChecker.firstAnnotationOf(sheetClass, + throwOnUnresolved: false)) + : null; + + final sheetReturnType = superType.typeArguments.first; + final methodTupleRef = RecordType((b) => b + ..isNullable = false + ..positionalFieldTypes.add(refer('bool?')) + ..positionalFieldTypes.add(recursiveTypeReference( + lib, sheetReturnType, + typeRefUpdates: (b) => b.isNullable = true))); + final params = sheetClass.constructors.first.parameters + .where( + (p) => p.displayName != 'key' && p.displayName != 'completer') + .toList(growable: false); + + extension = extension.rebuild((b) => b.methods.add(Method((b) => b + ..name = 'show${sheetClass.displayName}' + ..returns = TypeReference((b) => b + ..symbol = 'Future' + ..types.add(methodTupleRef)) + ..lambda = true + ..optionalParameters.add(Parameter((b) => b + ..name = 'barrierColor' + ..type = refer('Color', 'dart:ui') + ..named = true + ..defaultTo = refer('Color', 'dart:ui').constInstance([ + CodeExpression(Code( + '0x${(configAnnotation?.read('defaultBarrierColor').intValue ?? 0x80000000).toRadixString(16).padLeft(8, '0')}')) + ]).code)) + ..optionalParameters.add(Parameter((b) => b + ..name = 'fullscreen' + ..type = refer('bool') + ..named = true + ..defaultTo = literalBool( + configAnnotation?.read('defaultFullscreen').boolValue ?? + false) + .code)) + ..optionalParameters.add(Parameter((b) => b + ..name = 'draggable' + ..type = refer('bool') + ..named = true + ..defaultTo = literalBool( + configAnnotation?.read('defaultDraggable').boolValue ?? + true) + .code)) + ..optionalParameters.addAll(params.map((p) => Parameter((b) => b + ..name = p.name + ..type = recursiveTypeReference(lib, p.type) + ..required = p.isRequired + ..defaultTo = p.hasDefaultValue ? Code(p.defaultValueCode!) : null + ..named = true))) + ..body = refer('showBottomSheet') + .call([ + refer(sheetClass.displayName, assetId.uri.toString()) + .newInstance( + params + .where((p) => p.isPositional) + .map((p) => refer(p.name)), + { + 'completer': refer('closeSheet'), + for (final p in params.where((p) => p.isNamed)) + p.name: refer(p.name) + }), + ], { + 'barrierColor': refer('barrierColor'), + 'fullscreen': refer('fullscreen'), + 'draggable': refer('draggable'), + }, [ + methodTupleRef, + refer(sheetClass.displayName, assetId.uri.toString()), + ]) + .property('then') + .call([ + Method((b) => b + ..requiredParameters.add(Parameter((b) => b.name = 'r')) + ..lambda = true + ..body = Code( + '(r?.\$1, ${sheetReturnType is analyzer.VoidType ? 'null' : r'r?.$2'})')) + .closure + ]) + .code))); + } + } + + if (extension.methods.isEmpty) { + return; + } + + final outputLib = Library((b) => b + ..ignoreForFile.add('type=lint') + ..body.add(extension)); + + buildStep.writeAsString( + output, + DartFormatter().format(outputLib + .accept(DartEmitter.scoped( + useNullSafetySyntax: true, orderDirectives: true)) + .toString())); + } + + @override + Map> get buildExtensions => { + r'lib/$lib$': [options.output], + }; +} diff --git a/packages/fluorflow_generator/lib/src/builder/dialog_builder.dart b/packages/fluorflow_generator/lib/src/builder/dialog_builder.dart new file mode 100644 index 0000000..b1a293b --- /dev/null +++ b/packages/fluorflow_generator/lib/src/builder/dialog_builder.dart @@ -0,0 +1,177 @@ +import 'dart:async'; + +import 'package:analyzer/dart/element/type.dart' as analyzer; +import 'package:build/build.dart'; +import 'package:code_builder/code_builder.dart'; +import 'package:dart_style/dart_style.dart'; +import 'package:fluorflow/annotations.dart'; +import 'package:glob/glob.dart'; +import 'package:recase/recase.dart'; +import 'package:source_gen/source_gen.dart'; + +import '../utils.dart'; + +extension on BuilderOptions { + String get output => config['output'] ?? 'lib/app.dialogs.dart'; +} + +class DialogBuilder implements Builder { + static final _allDartFilesInLib = Glob('{lib/*.dart,lib/**/*.dart}'); + + final BuilderOptions options; + + const DialogBuilder(this.options); + + @override + FutureOr build(BuildStep buildStep) async { + final output = AssetId(buildStep.inputId.package, options.output); + final resolver = buildStep.resolver; + final configChecker = TypeChecker.fromRuntime(DialogConfig); + const dialogSuperTypes = [ + 'FluorFlowSimpleDialog', + 'FluorFlowDialog', + ]; + + var extension = Extension((b) => b + ..name = 'Dialogs' + ..on = refer('DialogService', 'package:fluorflow/fluorflow.dart')); + + await for (final assetId in buildStep.findAssets(_allDartFilesInLib)) { + if (!await resolver.isLibrary(assetId)) { + continue; + } + + final lib = LibraryReader(await resolver.libraryFor(assetId)); + + for (final (dialogClass, superType) in lib.classes + .where((c) => c.allSupertypes + .map((s) => s.element.name) + .any((s) => dialogSuperTypes.contains(s))) + .map((c) => ( + c, + c.allSupertypes.firstWhere( + (s) => dialogSuperTypes.contains(s.element.name)) + ))) { + final configAnnotation = + configChecker.hasAnnotationOf(dialogClass, throwOnUnresolved: false) + ? ConstantReader(configChecker.firstAnnotationOf(dialogClass, + throwOnUnresolved: false)) + : null; + + final dialogReturnType = superType.typeArguments.first; + final methodTupleRef = RecordType((b) => b + ..isNullable = false + ..positionalFieldTypes.add(refer('bool?')) + ..positionalFieldTypes.add(recursiveTypeReference( + lib, dialogReturnType, + typeRefUpdates: (b) => b.isNullable = true))); + final params = dialogClass.constructors.first.parameters + .where( + (p) => p.displayName != 'key' && p.displayName != 'completer') + .toList(growable: false); + final dialogBuilder = configAnnotation == null + ? refer('NoTransitionPageRouteBuilder', + 'package:fluorflow/fluorflow.dart') + : switch (( + getEnumFromAnnotation( + RouteBuilder.values, + configAnnotation.read('routeBuilder').objectValue, + RouteBuilder.noTransition), + configAnnotation.read('pageRouteBuilder').isNull + )) { + (RouteBuilder.custom, true) => throw InvalidGenerationSourceError( + 'You must provide a pageRouteBuilder when using a custom routeBuilder.', + element: dialogClass), + (RouteBuilder.custom, false) => refer( + configAnnotation + .read('pageRouteBuilder') + .typeValue + .getDisplayString(withNullability: false), + lib + .pathToElement(configAnnotation + .read('pageRouteBuilder') + .typeValue + .element!) + .toString()), + (final t, _) => refer('${t.name.pascalCase}PageRouteBuilder', + 'package:fluorflow/fluorflow.dart'), + }; + + extension = extension.rebuild((b) => b.methods.add(Method((b) => b + ..name = 'show${dialogClass.displayName}' + ..returns = TypeReference((b) => b + ..symbol = 'Future' + ..types.add(methodTupleRef)) + ..lambda = true + ..optionalParameters.add(Parameter((b) => b + ..name = 'barrierColor' + ..type = refer('Color', 'dart:ui') + ..named = true + ..defaultTo = refer('Color', 'dart:ui').constInstance([ + CodeExpression(Code( + '0x${(configAnnotation?.read('defaultBarrierColor').intValue ?? 0x80000000).toRadixString(16).padLeft(8, '0')}')) + ]).code)) + ..optionalParameters.addAll(params.map((p) => Parameter((b) => b + ..name = p.name + ..type = recursiveTypeReference(lib, p.type) + ..required = p.isRequired + ..defaultTo = p.hasDefaultValue ? Code(p.defaultValueCode!) : null + ..named = true))) + ..body = refer('showDialog') + .call([], { + 'barrierColor': refer('barrierColor'), + 'dialogBuilder': dialogBuilder.newInstance([], { + 'pageBuilder': Method((b) => b + ..requiredParameters.add(Parameter((b) => b.name = '_')) + ..requiredParameters.add(Parameter((b) => b.name = '__')) + ..requiredParameters.add(Parameter((b) => b.name = '___')) + ..lambda = true + ..body = + refer(dialogClass.displayName, assetId.uri.toString()) + .newInstance( + params + .where((p) => p.isPositional) + .map((p) => refer(p.name)), + { + 'completer': refer('closeDialog'), + for (final p in params.where((p) => p.isNamed)) + p.name: refer(p.name) + }).code).closure + }) + }, [ + methodTupleRef + ]) + .property('then') + .call([ + Method((b) => b + ..requiredParameters.add(Parameter((b) => b.name = 'r')) + ..lambda = true + ..body = Code( + '(r?.\$1, ${dialogReturnType is analyzer.VoidType ? 'null' : r'r?.$2'})')) + .closure + ]) + .code))); + } + } + + if (extension.methods.isEmpty) { + return; + } + + final outputLib = Library((b) => b + ..ignoreForFile.add('type=lint') + ..body.add(extension)); + + buildStep.writeAsString( + output, + DartFormatter().format(outputLib + .accept(DartEmitter.scoped( + useNullSafetySyntax: true, orderDirectives: true)) + .toString())); + } + + @override + Map> get buildExtensions => { + r'lib/$lib$': [options.output], + }; +} diff --git a/packages/fluorflow_generator/lib/src/builder/locator_builder.dart b/packages/fluorflow_generator/lib/src/builder/locator_builder.dart new file mode 100644 index 0000000..d3bae26 --- /dev/null +++ b/packages/fluorflow_generator/lib/src/builder/locator_builder.dart @@ -0,0 +1,459 @@ +import 'dart:async'; + +import 'package:analyzer/dart/element/element.dart'; +import 'package:build/build.dart'; +import 'package:code_builder/code_builder.dart'; +import 'package:dart_style/dart_style.dart'; +import 'package:fluorflow/annotations.dart'; +import 'package:glob/glob.dart'; +import 'package:source_gen/source_gen.dart'; + +extension on BuilderOptions { + String get output => config['output'] ?? 'lib/app.locator.dart'; + + bool get emitAllReady => config['emitAllReady'] ?? true; + + Map get registerServices => + config['register_services'] ?? {}; + + bool get registerNavigationService => registerServices['navigation'] ?? true; + + bool get registerDialogService => registerServices['dialog'] ?? true; + + bool get registerBottomSheetService => + registerServices['bottomSheet'] ?? true; +} + +class LocatorBuilder implements Builder { + static final _allDartFilesInLib = Glob('{lib/*.dart,lib/**/*.dart}'); + static final _singletonAnnotation = TypeChecker.fromRuntime(Singleton); + static final _lazySingletonAnnotation = + TypeChecker.fromRuntime(LazySingleton); + static final _asyncSingletonAnnotation = + TypeChecker.fromRuntime(AsyncSingleton); + static final _factoryAnnotation = TypeChecker.fromRuntime(Factory); + static final _ignoreAnnotation = TypeChecker.fromRuntime(IgnoreDependency); + static final _customLocatorAnnotation = + TypeChecker.fromRuntime(CustomLocatorFunction); + + final BuilderOptions options; + + const LocatorBuilder(this.options); + + @override + FutureOr build(BuildStep buildStep) async { + final output = AssetId(buildStep.inputId.package, options.output); + final resolver = buildStep.resolver; + + final locatorRef = refer('locator', 'package:fluorflow/fluorflow.dart'); + + var setupLocatorBlock = Block(); + var factoryExtension = Extension((b) => b + ..name = 'Factories' + ..on = refer('Locator', 'package:fluorflow/fluorflow.dart')); + + await for (final assetId in buildStep.findAssets(_allDartFilesInLib)) { + if (!await resolver.isLibrary(assetId)) { + continue; + } + + final lib = LibraryReader(await resolver.libraryFor(assetId)); + + setupLocatorBlock = + _handleClassSingletons(assetId, lib, locatorRef, setupLocatorBlock); + setupLocatorBlock = _handleFunctionSingletons( + assetId, lib, locatorRef, setupLocatorBlock); + setupLocatorBlock = _handleClassLazySingletons( + assetId, lib, locatorRef, setupLocatorBlock); + setupLocatorBlock = _handleFunctionLazySingletons( + assetId, lib, locatorRef, setupLocatorBlock); + setupLocatorBlock = _handleClassAsyncSingletons( + assetId, lib, locatorRef, setupLocatorBlock); + setupLocatorBlock = _handleFunctionAsyncSingletons( + assetId, lib, locatorRef, setupLocatorBlock); + (setupLocatorBlock, factoryExtension) = _handleClassFactories( + assetId, lib, locatorRef, setupLocatorBlock, factoryExtension); + setupLocatorBlock = _handleCustomLocatorFunction( + assetId, lib, locatorRef, setupLocatorBlock); + } + + if (options.registerNavigationService) { + setupLocatorBlock = setupLocatorBlock.rebuild((b) => b + ..addExpression(locatorRef.property('registerLazySingleton').call([ + Method((b) => b + ..body = + refer('NavigationService', 'package:fluorflow/fluorflow.dart') + .newInstance([]).code).closure, + ]))); + } + + if (options.registerDialogService) { + setupLocatorBlock = setupLocatorBlock.rebuild((b) => b + ..addExpression(locatorRef.property('registerLazySingleton').call([ + Method((b) => b + ..body = refer('DialogService', 'package:fluorflow/fluorflow.dart') + .newInstance([]).code).closure, + ]))); + } + + if (options.registerBottomSheetService) { + setupLocatorBlock = setupLocatorBlock.rebuild((b) => b + ..addExpression(locatorRef.property('registerLazySingleton').call([ + Method((b) => b + ..body = + refer('BottomSheetService', 'package:fluorflow/fluorflow.dart') + .newInstance([]).code).closure, + ]))); + } + + if (setupLocatorBlock.statements.isEmpty) { + return; + } + + if (options.emitAllReady) { + setupLocatorBlock = setupLocatorBlock.rebuild((b) => + b.addExpression(locatorRef.property('allReady').call([]).awaited)); + } + + var outputLib = Library((b) => b + ..ignoreForFile.add('type=lint') + ..body.add(Method((b) => b + ..name = 'setupLocator' + ..modifier = MethodModifier.async + ..body = setupLocatorBlock + ..returns = refer('Future')))); + + if (factoryExtension.methods.isNotEmpty) { + outputLib = outputLib.rebuild((b) => b..body.add(factoryExtension)); + } + + buildStep.writeAsString( + output, + DartFormatter().format(outputLib + .accept(DartEmitter.scoped( + useNullSafetySyntax: true, orderDirectives: true)) + .toString())); + } + + @override + Map> get buildExtensions => { + r'lib/$lib$': [options.output], + }; + + bool _hasIgnoreAnnotation(AnnotatedElement e) => + ConstantReader(_ignoreAnnotation.firstAnnotationOf(e.element, + throwOnUnresolved: false)) + .peek('inLocator') + ?.boolValue == + true; + + Block _handleClassSingletons(AssetId assetId, LibraryReader lib, + Reference locatorRef, Block setupLocatorBlock) { + var block = setupLocatorBlock; + + for (final AnnotatedElement(:annotation, :element) in lib + .annotatedWith(_singletonAnnotation) + .where((element) => element.element is ClassElement) + .where((element) => !_hasIgnoreAnnotation(element))) { + if (annotation.read('dependencies').isNull) { + block = block.rebuild((b) => b + ..addExpression(locatorRef.property('registerSingleton').call([ + refer(element.displayName, assetId.uri.toString()).newInstance([]), + ]))); + } else { + final deps = annotation.read('dependencies').listValue; + + block = block.rebuild((b) => b + ..addExpression( + locatorRef.property('registerSingletonWithDependencies').call([ + Method((b) => b + ..body = refer(element.displayName, assetId.uri.toString()) + .newInstance([]).code).closure, + ], { + 'dependsOn': literalList(deps + .map((d) => d.toTypeValue()?.element) + .nonNulls + .map((d) => + refer(d.displayName, lib.pathToElement(d).toString()))) + }))); + } + } + + return block; + } + + Block _handleFunctionSingletons(AssetId assetId, LibraryReader lib, + Reference locatorRef, Block setupLocatorBlock) { + var block = setupLocatorBlock; + + for (final AnnotatedElement(:annotation, :element) in lib + .annotatedWith(_singletonAnnotation) + .where((element) => element.element is FunctionElement) + .where((element) => !_hasIgnoreAnnotation(element))) { + if (annotation.read('dependencies').isNull) { + block = block.rebuild((b) => b + ..addExpression(locatorRef.property('registerSingleton').call([ + refer(element.displayName, assetId.uri.toString()).call([]), + ]))); + } else { + final deps = annotation.read('dependencies').listValue; + + block = block.rebuild((b) => b + ..addExpression( + locatorRef.property('registerSingletonWithDependencies').call([ + Method((b) => b + ..body = refer(element.displayName, assetId.uri.toString()) + .call([]).code).closure, + ], { + 'dependsOn': literalList(deps + .map((d) => d.toTypeValue()?.element) + .nonNulls + .map((d) => + refer(d.displayName, lib.pathToElement(d).toString()))) + }))); + } + } + + return block; + } + + Block _handleClassLazySingletons(AssetId assetId, LibraryReader lib, + Reference locatorRef, Block setupLocatorBlock) { + var block = setupLocatorBlock; + + for (final AnnotatedElement(element: Element(:displayName)) in lib + .annotatedWith(_lazySingletonAnnotation) + .where((element) => element.element is ClassElement) + .where((element) => !_hasIgnoreAnnotation(element))) { + block = block.rebuild((b) => b + ..addExpression(locatorRef.property('registerLazySingleton').call([ + Method((b) => b + ..body = refer(displayName, assetId.uri.toString()) + .newInstance([]).code).closure, + ]))); + } + + return block; + } + + Block _handleFunctionLazySingletons(AssetId assetId, LibraryReader lib, + Reference locatorRef, Block setupLocatorBlock) { + var block = setupLocatorBlock; + + for (final AnnotatedElement(element: Element(:displayName)) in lib + .annotatedWith(_lazySingletonAnnotation) + .where((element) => element.element is FunctionElement) + .where((element) => !_hasIgnoreAnnotation(element))) { + block = block.rebuild((b) => b + ..addExpression(locatorRef + .property('registerLazySingleton') + .call([refer(displayName, assetId.uri.toString())]))); + } + + return block; + } + + Block _handleClassAsyncSingletons(AssetId assetId, LibraryReader lib, + Reference locatorRef, Block setupLocatorBlock) { + var block = setupLocatorBlock; + + for (final AnnotatedElement(:annotation, :element) in lib + .annotatedWith(_asyncSingletonAnnotation) + .where((element) => element.element is ClassElement) + .where((element) => !_hasIgnoreAnnotation(element))) { + if (annotation.read('factory').isNull) { + throw InvalidGenerationSourceError( + 'AsyncSingleton must have a factory method if used on a class', + element: element); + } + + final factory = annotation.read('factory').objectValue.toFunctionValue(); + + var named = {}; + + if (!annotation.read('dependencies').isNull) { + final deps = annotation.read('dependencies').listValue; + + named = { + 'dependsOn': literalList(deps + .map((d) => d.toTypeValue()?.element) + .nonNulls + .map( + (d) => refer(d.displayName, lib.pathToElement(d).toString()))) + }; + } + + if (factory + case MethodElement( + displayName: final methodName, + enclosingElement: ClassElement(displayName: final className) + )) { + block = block.rebuild((b) => b + ..addExpression(locatorRef.property('registerSingletonAsync').call([ + refer(className, assetId.uri.toString()).property(methodName), + ], named))); + } else if (factory case FunctionElement(:final displayName)) { + block = block.rebuild((b) => b + ..addExpression(locatorRef.property('registerSingletonAsync').call([ + refer(displayName, assetId.uri.toString()), + ], named))); + } + } + + return block; + } + + Block _handleFunctionAsyncSingletons(AssetId assetId, LibraryReader lib, + Reference locatorRef, Block setupLocatorBlock) { + var block = setupLocatorBlock; + + for (final AnnotatedElement(:annotation, :element) in lib + .annotatedWith(_asyncSingletonAnnotation) + .where((element) => element.element is FunctionElement) + .where((element) => !_hasIgnoreAnnotation(element))) { + final factory = element as FunctionElement; + + var named = {}; + + if (!annotation.read('dependencies').isNull) { + final deps = annotation.read('dependencies').listValue; + + named = { + 'dependsOn': literalList(deps + .map((d) => d.toTypeValue()?.element) + .nonNulls + .map( + (d) => refer(d.displayName, lib.pathToElement(d).toString()))) + }; + } + + block = block.rebuild((b) => b + ..addExpression(locatorRef.property('registerSingletonAsync').call([ + refer(factory.displayName, assetId.uri.toString()), + ], named))); + } + + return block; + } + + (Block, Extension) _handleClassFactories( + AssetId assetId, + LibraryReader lib, + Reference locatorRef, + Block setupLocatorBlock, + Extension locatorExtension) { + var block = setupLocatorBlock; + var factoryExtension = locatorExtension; + + for (final AnnotatedElement(:element) in lib + .annotatedWith(_factoryAnnotation) + .where((element) => element.element is FunctionElement) + .where((element) => !_hasIgnoreAnnotation(element))) { + final func = element as FunctionElement; + + if (func.isPrivate) { + throw InvalidGenerationSourceError('Factories cannot be private.', + element: element); + } + + if (func.parameters.isEmpty) { + // when there are no params, we just register the factory. + block = block.rebuild((b) => b + ..addExpression(locatorRef.property('registerFactory').call([ + Method((b) => b + ..body = refer(element.displayName, assetId.uri.toString()) + .call([]).code).closure, + ]))); + } else if (func.parameters.length > 2) { + throw InvalidGenerationSourceError( + 'Factories can only have 0, 1 or 2 parameters.', + element: element); + } else { + // when there are params, we register the factory with the params. + block = block.rebuild((b) => b + ..addExpression(locatorRef.property('registerFactoryParam').call( + [ + Method((b) => b + ..requiredParameters.add(Parameter((b) => b..name = 'p1')) + ..requiredParameters.add(Parameter( + (b) => b..name = func.parameters.length == 1 ? '_' : 'p2')) + ..body = + refer(element.displayName, assetId.uri.toString()).call([ + if (func.parameters.isNotEmpty) refer('p1'), + if (func.parameters.length == 2) refer('p2'), + ]).code).closure, + ], + {}, + [ + refer(func.returnType.getDisplayString(withNullability: true), + lib.pathToElement(func.returnType.element!).toString()), + if (func.parameters.isNotEmpty) + refer( + func.parameters.first.type.element!.displayName, + lib + .pathToElement(func.parameters.first.type.element!) + .toString()), + if (func.parameters.length == 1) refer('void'), + if (func.parameters.length == 2) + refer( + func.parameters[1].type.element!.displayName, + lib + .pathToElement(func.parameters[1].type.element!) + .toString()), + ], + ))); + + // add the factory to the Locator extension for convenience + var ext = Method((b) => b + ..name = 'get${func.returnType.toString()}' + ..returns = refer( + func.returnType.getDisplayString(withNullability: true), + lib.pathToElement(func.returnType.element!).toString()) + ..body = refer('get').call([], { + 'param1': refer(func.parameters.first.displayName), + ...func.parameters.length == 2 + ? {'param2': refer(func.parameters[1].displayName)} + : {} + }).code + ..requiredParameters.add(Parameter((b) => b + ..name = func.parameters.first.displayName + ..type = refer( + func.parameters.first.type.element!.displayName, + lib + .pathToElement(func.parameters.first.type.element!) + .toString())))); + if (func.parameters.length == 2) { + ext = ext.rebuild((b) => b + ..requiredParameters.add(Parameter((b) => b + ..name = func.parameters[1].displayName + ..type = refer( + func.parameters[1].type.element!.displayName, + lib + .pathToElement(func.parameters[1].type.element!) + .toString())))); + } + + factoryExtension = factoryExtension.rebuild((b) => b..methods.add(ext)); + } + } + + return (block, factoryExtension); + } + + Block _handleCustomLocatorFunction(AssetId assetId, LibraryReader lib, + Reference locatorRef, Block setupLocatorBlock) { + var block = setupLocatorBlock; + + for (final AnnotatedElement(:element) in lib + .annotatedWith(_customLocatorAnnotation) + .where((element) => element.element is FunctionElement) + .where((element) => + element.annotation.read('includeInLocator').boolValue)) { + block = block.rebuild((b) => b + ..addExpression( + refer(element.displayName, assetId.uri.toString()).call([]))); + } + + return block; + } +} diff --git a/packages/fluorflow_generator/lib/src/builder/router_builder.dart b/packages/fluorflow_generator/lib/src/builder/router_builder.dart new file mode 100644 index 0000000..a1b8473 --- /dev/null +++ b/packages/fluorflow_generator/lib/src/builder/router_builder.dart @@ -0,0 +1,261 @@ +import 'dart:async'; + +import 'package:analyzer/dart/element/element.dart'; +import 'package:build/build.dart'; +import 'package:code_builder/code_builder.dart'; +import 'package:dart_style/dart_style.dart'; +import 'package:fluorflow/annotations.dart'; +import 'package:glob/glob.dart'; +import 'package:recase/recase.dart'; +import 'package:source_gen/source_gen.dart'; + +import '../utils.dart'; + +extension on BuilderOptions { + String get output => config['output'] ?? 'lib/app.router.dart'; +} + +class RouterBuilder implements Builder { + static final _allDartFilesInLib = Glob('{lib/*.dart,lib/**/*.dart}'); + + final BuilderOptions options; + + const RouterBuilder(this.options); + + @override + FutureOr build(BuildStep buildStep) async { + final output = AssetId(buildStep.inputId.package, options.output); + final resolver = buildStep.resolver; + + var routeEnum = Enum((b) => b + ..name = 'AppRoute' + ..fields.add(Field((b) => b + ..modifier = FieldModifier.final$ + ..name = 'path' + ..type = refer('String'))) + ..constructors.add(Constructor((b) => b + ..constant = true + ..requiredParameters.add(Parameter((b) => b + ..name = 'path' + ..toThis = true))))); + + final pages = {}; + + final routeArgs = []; + + var navExtension = Extension((b) => b + ..name = 'RouteNavigation' + ..on = refer('NavigationService', 'package:fluorflow/fluorflow.dart')); + + await for (final assetId in buildStep.findAssets(_allDartFilesInLib)) { + if (!await resolver.isLibrary(assetId)) { + continue; + } + + final lib = LibraryReader(await resolver.libraryFor(assetId)); + + for (final AnnotatedElement(:annotation, :element) in lib + .annotatedWith(TypeChecker.fromRuntime(Routable)) + .where((element) => element.element is ClassElement)) { + final path = annotation.read('path').isNull + ? '/${element.displayName.paramCase}' + : annotation.read('path').stringValue; + + // Add the route to the enum. + routeEnum = routeEnum.rebuild((b) => b + ..values.add(EnumValue((b) => b + ..name = element.displayName.camelCase + ..arguments.add(literalString(path))))); + + final ctor = element.children.cast().firstWhere( + (element) => element is ConstructorElement, + orElse: () => null) as ConstructorElement?; + + final params = ctor?.parameters + .where((p) => p.displayName != 'key') + .toList(growable: false) ?? + []; + + if (params.isNotEmpty) { + // There are non "key" parameters, we need to generate route arguments. + routeArgs.add(Class((b) => b + ..name = '${element.displayName.pascalCase}Arguments' + ..fields.addAll(params.map((p) => Field((b) => b + ..name = p.displayName + ..modifier = FieldModifier.final$ + ..type = refer(p.type.getDisplayString(withNullability: true), + lib.pathToElement(p.type.element!).toString())))) + ..constructors.add(Constructor((b) => b + ..constant = true + ..optionalParameters.addAll(params.map((p) => Parameter((b) => b + ..name = p.name + ..toThis = true + ..required = p.isRequired + ..defaultTo = + p.hasDefaultValue ? Code(p.defaultValueCode!) : null + ..named = true))))))); + } + + // Create the navigation to extension. + if (annotation.read('navigateToExtension').boolValue) { + navExtension = _addExtension(navExtension, lib, + prefix: 'navigateTo', + displayName: element.displayName, + params: params); + } + + if (annotation.read('replaceWithExtension').boolValue) { + navExtension = _addExtension(navExtension, lib, + prefix: 'replaceWith', + displayName: element.displayName, + params: params, + withReturnFuture: false); + } + + if (annotation.read('rootToExtension').boolValue) { + navExtension = _addExtension(navExtension, lib, + prefix: 'rootTo', + displayName: element.displayName, + params: params, + withPreventDuplicates: false, + withReturnFuture: false); + } + + // Add the route object to the pages map. + final builder = switch (( + getEnumFromAnnotation( + RouteBuilder.values, + annotation.read('routeBuilder').objectValue, + RouteBuilder.noTransition), + annotation.read('pageRouteBuilder').isNull + )) { + (RouteBuilder.custom, true) => throw InvalidGenerationSourceError( + 'You must provide a pageRouteBuilder when using a custom routeBuilder.', + element: element), + (RouteBuilder.custom, false) => refer( + annotation + .read('pageRouteBuilder') + .typeValue + .getDisplayString(withNullability: false), + lib + .pathToElement( + annotation.read('pageRouteBuilder').typeValue.element!) + .toString()), + (final t, _) => refer('${t.name.pascalCase}PageRouteBuilder', + 'package:fluorflow/fluorflow.dart'), + }; + + pages[refer(routeEnum.name) + .property(element.displayName.camelCase) + .property('path')] = Method((b) => b + ..requiredParameters.add(Parameter((b) => b.name = 'data')) + ..body = builder.newInstance([], { + 'settings': refer('data'), + 'pageBuilder': Method((b) => b + ..requiredParameters.add(Parameter((b) => b.name = '_')) + ..requiredParameters.add(Parameter((b) => b.name = '__')) + ..requiredParameters.add(Parameter((b) => b.name = '___')) + ..lambda = params.isEmpty + ..body = params.isEmpty + ? refer(element.displayName, assetId.uri.toString()) + .constInstance([]).code + : Block.of([ + declareFinal('args') + .assign(refer('data') + .property('arguments') + .asA(refer('${element.displayName}Arguments'))) + .statement, + refer(element.displayName, assetId.uri.toString()) + .newInstance( + params + .where((p) => p.isPositional) + .map((p) => refer('args').property(p.name)), + { + for (final p in params.where((p) => p.isNamed)) + p.name: refer('args').property(p.name) + }) + .returned + .statement + ])).closure, + }).code + ..lambda = true); + } + } + + if (pages.isEmpty) { + return; + } + + final outputLib = Library((b) => b + ..ignoreForFile.add('type=lint') + ..body.add(routeEnum) + ..body.add(declareFinal('_pages') + .assign(literalMap(pages, refer('String'), + refer('RouteFactory', 'package:flutter/widgets.dart'))) + .statement) + ..body.addAll(routeArgs) + ..body.add(declareFinal('onGenerateRoute') + .assign( + refer('generateRouteFactory', 'package:fluorflow/fluorflow.dart') + .call([refer('_pages')])) + .statement) + ..body.add(navExtension)); + + buildStep.writeAsString( + output, + DartFormatter().format(outputLib + .accept(DartEmitter.scoped( + useNullSafetySyntax: true, orderDirectives: true)) + .toString())); + } + + @override + Map> get buildExtensions => { + r'lib/$lib$': [options.output], + }; + + Extension _addExtension(Extension ext, LibraryReader lib, + {required String prefix, + required String displayName, + required Iterable params, + bool withReturnFuture = true, + bool withPreventDuplicates = true}) => + ext.rebuild((b) => b + ..methods.add(Method((b) => b + ..name = '$prefix${displayName.pascalCase}' + ..returns = refer(withReturnFuture ? 'Future?' : 'void') + ..types.addAll([ + if (withReturnFuture) refer('T'), + ]) + ..optionalParameters.addAll(params.map((p) => Parameter((b) => b + ..name = p.name + ..type = refer(p.type.getDisplayString(withNullability: true), + lib.pathToElement(p.type.element!).toString()) + ..required = p.isRequired + ..defaultTo = p.hasDefaultValue ? Code(p.defaultValueCode!) : null + ..named = true))) + ..optionalParameters.addAll([ + if (withPreventDuplicates) + Parameter((b) => b + ..name = 'preventDuplicates' + ..type = refer('bool') + ..named = true + ..defaultTo = literalTrue.code), + ]) + ..body = refer(prefix).call([ + refer('AppRoute.${displayName.camelCase}.path'), + ], { + ...withPreventDuplicates + ? { + 'preventDuplicates': refer('preventDuplicates'), + } + : {}, + ...params.isNotEmpty + ? { + 'arguments': refer('${displayName.pascalCase}Arguments') + .newInstance([], + {for (final p in params) p.name: refer(p.name)}), + } + : {}, + }).code))); +} diff --git a/packages/fluorflow_generator/lib/src/builder/test_locator_builder.dart b/packages/fluorflow_generator/lib/src/builder/test_locator_builder.dart new file mode 100644 index 0000000..6dfeb28 --- /dev/null +++ b/packages/fluorflow_generator/lib/src/builder/test_locator_builder.dart @@ -0,0 +1,215 @@ +import 'dart:async'; + +import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/dart/element/type.dart'; +import 'package:build/build.dart'; +import 'package:code_builder/code_builder.dart'; +import 'package:dart_style/dart_style.dart'; +import 'package:fluorflow/annotations.dart'; +import 'package:glob/glob.dart'; +import 'package:path/path.dart' as p; +import 'package:source_gen/source_gen.dart'; + +extension on BuilderOptions { + String get output => config['output'] ?? 'test/test.locator.dart'; + + Map get services => config['services'] ?? {}; + + bool get mockNavService => services['navigation'] ?? true; + + bool get mockDialogService => services['dialog'] ?? true; + + bool get mockBottomSheetService => services['bottomSheet'] ?? true; +} + +class TestLocatorBuilder implements Builder { + static final _allDartFilesInLib = + Glob('{lib/*.dart,lib/**/*.dart,test/*.dart,test/**/*.dart}'); + static final _ignoreAnnotation = TypeChecker.fromRuntime(IgnoreDependency); + static final _customLocatorAnnotation = + TypeChecker.fromRuntime(CustomLocatorFunction); + static final _isFactory = TypeChecker.fromRuntime(Factory); + static final _nonFactory = TypeChecker.any([ + TypeChecker.fromRuntime(Singleton), + TypeChecker.fromRuntime(AsyncSingleton), + TypeChecker.fromRuntime(LazySingleton), + ]); + + final BuilderOptions options; + + const TestLocatorBuilder(this.options); + + @override + FutureOr build(BuildStep buildStep) async { + final packageConfig = await buildStep.packageConfig; + if (!packageConfig.packages.any((p) => p.name == 'mockito')) { + // do not run the builder when mockito is not installed. + log.info('Mockito is not installed, skipping builder.'); + return; + } + + final output = AssetId(buildStep.inputId.package, options.output); + final resolver = buildStep.resolver; + final locatorRef = refer('locator', 'package:fluorflow/fluorflow.dart'); + final mocksUri = '${p.basenameWithoutExtension(options.output)}.mocks.dart'; + + var outputLib = Library((b) => b..ignoreForFile.add('type=lint')); + var setupTestLocatorMethodBody = Block(); + var setupTestLocatorMethod = Method((b) => b + ..name = 'setupTestLocator' + ..returns = refer('void')); + + final mockedTypes = List.empty(growable: true); + + void addNonFactoryMock(Reference originalType, Reference mockType) { + outputLib = outputLib.rebuild((b) => b.body.add(Method((b) => b + ..name = 'get${mockType.symbol}' + ..returns = mockType + ..body = Block.of([ + Code.scope( + (a) => 'if (${a(locatorRef)}.isRegistered<${a(originalType)}>())' + '{${a(locatorRef)}.unregister<${a(originalType)}>();}'), + declareFinal('service').assign(mockType.newInstance([])).statement, + locatorRef + .property('registerSingleton') + .call([refer('service')], {}, [originalType]).statement, + refer('service').returned.statement, + ])))); + } + + void addInternalType(Reference internalType) { + final mockType = refer('Mock${internalType.symbol}', mocksUri); + mockedTypes.add(internalType); + addNonFactoryMock(internalType, mockType); + setupTestLocatorMethodBody = setupTestLocatorMethodBody.rebuild( + (b) => b.addExpression(refer('get${mockType.symbol}').call([]))); + } + + await for (final assetId in buildStep.findAssets(_allDartFilesInLib)) { + if (!await resolver.isLibrary(assetId)) { + continue; + } + + final lib = LibraryReader(await resolver.libraryFor(assetId)); + + for (final AnnotatedElement(:annotation, :element) in lib + .annotatedWith(TypeChecker.any([ + _nonFactory, + _isFactory, + ])) + .where((element) => !_hasIgnoreAnnotation(element))) { + // For all annotations (except Factory), the mocked element is either + // the annotated class or the returnvalue of the factory function. + // For all factories (Factory annotations), the mocked element is the + // return value regardless of params. But the factory is still registered. + final originalType = switch (element) { + final ClassElement e => + refer(e.displayName, lib.pathToElement(e).toString()), + FunctionElement(returnType: final InterfaceType rt) + when (rt.isDartAsyncFuture || rt.isDartAsyncFutureOr) => + refer( + rt.typeArguments.first.getDisplayString(withNullability: true), + lib.pathToElement(rt.typeArguments.first.element!).toString()), + FunctionElement(:final returnType) => refer( + returnType.getDisplayString(withNullability: true), + lib.pathToElement(returnType.element!).toString()), + _ => throw InvalidGenerationSourceError('Invalid element type.', + element: element), + }; + final mockType = refer('Mock${originalType.symbol}', mocksUri); + mockedTypes.add(originalType); + + if (annotation.instanceOf(_nonFactory)) { + addNonFactoryMock(originalType, mockType); + } else { + outputLib = outputLib.rebuild((b) => b.body.add(Method((b) => b + ..name = 'get${mockType.symbol}' + ..returns = mockType + ..body = Block.of([ + Code.scope((a) => + 'if (${a(locatorRef)}.isRegistered<${a(originalType)}>())' + '{${a(locatorRef)}.unregister<${a(originalType)}>();}'), + declareFinal('service') + .assign(mockType.newInstance([])) + .statement, + locatorRef.property('registerFactory').call( + [Method((b) => b.body = refer('service').code).closure], + {}, + [originalType]).statement, + refer('service').returned.statement, + ])))); + } + + setupTestLocatorMethodBody = setupTestLocatorMethodBody.rebuild( + (b) => b.addExpression(refer('get${mockType.symbol}').call([]))); + } + + for (final AnnotatedElement(:element) in lib + .annotatedWith(_customLocatorAnnotation) + .where((element) => element.element is FunctionElement) + .where((element) => + element.annotation.read('includeInTestLocator').boolValue)) { + setupTestLocatorMethodBody = setupTestLocatorMethodBody.rebuild((b) => + b.addExpression(refer( + element.displayName, lib.pathToElement(element).toString()) + .call([]))); + } + } + + if (options.mockNavService) { + addInternalType( + refer('NavigationService', 'package:fluorflow/fluorflow.dart')); + } + + if (options.mockDialogService) { + addInternalType( + refer('DialogService', 'package:fluorflow/fluorflow.dart')); + } + + if (options.mockBottomSheetService) { + addInternalType( + refer('BottomSheetService', 'package:fluorflow/fluorflow.dart')); + } + + setupTestLocatorMethod = setupTestLocatorMethod.rebuild((b) => b + ..body = setupTestLocatorMethodBody + ..annotations.add( + refer('GenerateNiceMocks', 'package:mockito/annotations.dart').call([ + literalList(mockedTypes.map((t) => + refer('MockSpec', 'package:mockito/annotations.dart') + .newInstance([], { + 'onMissingStub': + refer('OnMissingStub', 'package:mockito/annotations.dart') + .property('returnDefault') + }, [ + t + ]))) + ]))); + outputLib = outputLib.rebuild((b) => b + ..body.add(setupTestLocatorMethod) + ..body.add(Method((b) => b + ..name = 'tearDownLocator' + ..returns = refer('void') + ..lambda = true + ..body = locatorRef.property('reset').call([]).code))); + + buildStep.writeAsString( + output, + DartFormatter().format(outputLib + .accept(DartEmitter.scoped( + useNullSafetySyntax: true, orderDirectives: true)) + .toString())); + } + + @override + Map> get buildExtensions => { + r'lib/$lib$': [options.output], + }; + + bool _hasIgnoreAnnotation(AnnotatedElement e) => + ConstantReader(_ignoreAnnotation.firstAnnotationOf(e.element, + throwOnUnresolved: false)) + .peek('inTestLocator') + ?.boolValue == + true; +} diff --git a/packages/fluorflow_generator/lib/src/utils.dart b/packages/fluorflow_generator/lib/src/utils.dart new file mode 100644 index 0000000..3abe075 --- /dev/null +++ b/packages/fluorflow_generator/lib/src/utils.dart @@ -0,0 +1,66 @@ +import 'package:analyzer/dart/constant/value.dart'; +import 'package:analyzer/dart/element/nullability_suffix.dart'; +import 'package:analyzer/dart/element/type.dart'; +import 'package:code_builder/code_builder.dart' as cb; +import 'package:source_gen/source_gen.dart'; + +TEnum getEnumFromAnnotation( + List values, DartObject enumField, + [TEnum? defaultValue]) { + final index = enumField.getField('index')?.toIntValue(); + if (index == null && defaultValue != null) { + return defaultValue; + } + return values[index ?? 0]; +} + +cb.Reference recursiveTypeReference( + LibraryReader lib, + DartType t, { + dynamic Function(cb.TypeReferenceBuilder)? typeRefUpdates, +}) { + cb.Reference mapRef(DartType t) => recursiveTypeReference(lib, t); + + return switch (t) { + VoidType() || + DynamicType() => + cb.refer(t.getDisplayString(withNullability: false)), + DartType(alias: InstantiatedTypeAliasElement(:final element)) => + cb.refer(element.name, lib.pathToElement(element).toString()), + final FunctionType f => cb.FunctionType((b) => b + ..returnType = mapRef(f.returnType) + ..requiredParameters.addAll(f.parameters + .where((p) => p.isRequiredPositional) + .map((p) => p.type) + .map(mapRef)) + ..optionalParameters.addAll(f.parameters + .where((p) => p.isOptionalPositional) + .map((p) => p.type) + .map(mapRef)) + ..namedRequiredParameters.addAll({ + for (final p in f.parameters.where((p) => p.isRequiredNamed)) + p.name: mapRef(p.type) + }) + ..namedParameters.addAll({ + for (final p in f.parameters.where((p) => p.isOptionalNamed)) + p.name: mapRef(p.type) + }) + ..types.addAll(f.typeFormals + .where((tf) => tf.bound != null) + .map((tf) => tf.bound!) + .map(mapRef))), + _ => cb.TypeReference((b) => b + ..isNullable = t.nullabilitySuffix == NullabilitySuffix.question + ..symbol = + t.element?.name ?? t.getDisplayString(withNullability: false) + ..types.addAll(switch (t) { + ParameterizedType(:final typeArguments) => + typeArguments.map(mapRef).toList(), + _ => [], + }) + ..url = t.element == null + ? null + : lib.pathToElement(t.element!).toString()) + .rebuild(typeRefUpdates ?? (b) => b), + }; +} diff --git a/packages/fluorflow_generator/pubspec.yaml b/packages/fluorflow_generator/pubspec.yaml new file mode 100644 index 0000000..9de85df --- /dev/null +++ b/packages/fluorflow_generator/pubspec.yaml @@ -0,0 +1,28 @@ +name: fluorflow_generator +description: >- + Generator (build runner generator) for the fluorflow package. This is + the companion package that helps with generating extension methods for + bottom sheets, routings, dialogs and services. +version: 0.0.0-development +homepage: https://github.com/smartive/fluorflow +repository: https://github.com/smartive/fluorflow.git + +environment: + sdk: '>=3.0.0 <4.0.0' + +dependencies: + analyzer: ^6.2.0 + build: ^2.4.1 + code_builder: ^4.10.0 + dart_style: ^2.3.4 + fluorflow: ^0.0.0-development + glob: ^2.1.2 + path: ^1.9.0 + recase: ^4.1.0 + source_gen: ^1.5.0 + +dev_dependencies: + build_test: ^2.2.2 + lints: ^3.0.0 + mockito: ^5.4.4 + test: ^1.25.2 diff --git a/packages/fluorflow_generator/test/builder/bottom_sheet_builder_test.dart b/packages/fluorflow_generator/test/builder/bottom_sheet_builder_test.dart new file mode 100644 index 0000000..1ebdcda --- /dev/null +++ b/packages/fluorflow_generator/test/builder/bottom_sheet_builder_test.dart @@ -0,0 +1,1192 @@ +import 'package:build/build.dart'; +import 'package:build_test/build_test.dart'; +import 'package:fluorflow_generator/src/builder/bottom_sheet_builder.dart'; +import 'package:test/test.dart'; + +void main() { + group('BottomSheetBuilder', () { + test( + 'should not generate something when no input is given.', + () => testBuilder(BottomSheetBuilder(BuilderOptions.empty), {}, + outputs: {})); + + test( + 'should not generate something when no subclasses for bottom sheets are present.', + () => testBuilder(BottomSheetBuilder(BuilderOptions.empty), { + 'a|lib/a.dart': ''' + class View {} + ''' + }, outputs: {})); + + group('for FluorFlowSimpleBottomSheet', () { + test( + 'should generate sheet method for dynamic return type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + const MySheet({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet(completer: closeSheet), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method for void return type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + const MySheet({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, void)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + }) => + showBottomSheet<(bool?, void), _i3.MySheet>( + _i3.MySheet(completer: closeSheet), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, null)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method for core return type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + const MySheet({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, String?)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + }) => + showBottomSheet<(bool?, String?), _i3.MySheet>( + _i3.MySheet(completer: closeSheet), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method for library return type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + import 'b.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + const MySheet({super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class DialogResultType {} + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i3; + +import 'package:a/a.dart' as _i4; +import 'package:a/b.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, _i2.DialogResultType?)> showMySheet({ + _i3.Color barrierColor = const _i3.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + }) => + showBottomSheet<(bool?, _i2.DialogResultType?), _i4.MySheet>( + _i4.MySheet(completer: closeSheet), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for FluorFlowBottomSheet', () { + test( + 'should generate sheet method for dynamic return type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowBottomSheet { + const MySheet({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet(completer: closeSheet), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method for void return type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowBottomSheet { + const MySheet({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, void)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + }) => + showBottomSheet<(bool?, void), _i3.MySheet>( + _i3.MySheet(completer: closeSheet), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, null)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method for core return type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowBottomSheet { + const MySheet({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, String?)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + }) => + showBottomSheet<(bool?, String?), _i3.MySheet>( + _i3.MySheet(completer: closeSheet), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method for library return type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + import 'b.dart'; + + class MySheet extends FluorFlowBottomSheet { + const MySheet({super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class DialogResultType {} + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i3; + +import 'package:a/a.dart' as _i4; +import 'package:a/b.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, _i2.DialogResultType?)> showMySheet({ + _i3.Color barrierColor = const _i3.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + }) => + showBottomSheet<(bool?, _i2.DialogResultType?), _i4.MySheet>( + _i4.MySheet(completer: closeSheet), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for Bottom Sheet with parameters', () { + test( + 'should generate sheet method with required positional argument.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + final String pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required String pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with required nullable positional argument.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + final String? pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required String? pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with required named argument.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + final String pos; + const MySheet({required this.pos, super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required String pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + completer: closeSheet, + pos: pos, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with an optional named argument.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + final String? pos; + const MySheet({this.pos, super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + String? pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + completer: closeSheet, + pos: pos, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with a defaulted named argument.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + final String pos; + const MySheet({this.pos = 'default', super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + String pos = 'default', + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + completer: closeSheet, + pos: pos, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with external referenced argument.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + import 'b.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + final MySheetRef pos; + const MySheet({required this.pos, super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class MySheetRef {} + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i4; +import 'package:a/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required _i3.MySheetRef pos, + }) => + showBottomSheet<(bool?, dynamic), _i4.MySheet>( + _i4.MySheet( + completer: closeSheet, + pos: pos, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for Bottom Sheet with special parameter types', () { + test( + 'should generate sheet method with generic list of primitive type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + final List pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required List pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with generic list of complex type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class Foobar {} + + class MySheet extends FluorFlowSimpleBottomSheet { + final List pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required List<_i3.Foobar> pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with recursive generic type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart'; + + class Foo {} + class Bar {} + + class MySheet extends FluorFlowSimpleBottomSheet { + final Foo> pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Baz {} + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required _i3.Foo<_i3.Bar<_i4.Baz, int>> pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with aliased import type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart' as b; + + class Foo {} + + class MySheet extends FluorFlowSimpleBottomSheet { + final Foo pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Baz {} + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required _i3.Foo<_i4.Baz> pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with function type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + final void Function() pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required void Function() pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with complex function type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart'; + + class Foo {} + + class Bar {} + + class MySheet extends FluorFlowSimpleBottomSheet { + final Foo Function(Bar i) pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Baz {} + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required _i3.Foo Function(_i3.Bar<_i4.Baz>) pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with complex function named parameters type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart'; + + class Foo {} + + class Bar {} + + class MySheet extends FluorFlowSimpleBottomSheet { + final Foo Function(Bar i, { required Foo f, Baz? b }) pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Baz {} + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required _i3.Foo Function( + _i3.Bar<_i4.Baz>, { + required _i3.Foo f, + _i4.Baz? b, + }) pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with complex function optional parameters type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart'; + + class Foo {} + + class Bar {} + + class MySheet extends FluorFlowSimpleBottomSheet { + final Foo Function(Bar i, [Foo? f]) pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Baz {} + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required _i3.Foo Function( + _i3.Bar<_i4.Baz>, [ + _i3.Foo?, + ]) pos, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate sheet method with aliased type.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + final MyCallback pos; + const MySheet(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Foobar {} + + typedef MyCallback = void Function(Foobar); + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i4; +import 'package:a/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + required _i3.MyCallback pos, + }) => + showBottomSheet<(bool?, dynamic), _i4.MySheet>( + _i4.MySheet( + pos, + completer: closeSheet, + ), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('with @BottomSheetConfig()', () { + test( + 'should generate sheet method with custom default options.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:fluorflow/fluorflow.dart'; + + @BottomSheetConfig( + defaultBarrierColor: 0x34ff0000, + defaultFullscreen: true, + defaultDraggable: false, + ) + class MySheet extends FluorFlowSimpleBottomSheet { + const MySheet({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.bottom_sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x34ff0000), + bool fullscreen = true, + bool draggable = false, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet(completer: closeSheet), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('with Builder Configuration', () { + test( + 'should use custom output if configured.', + () async => await testBuilder( + BottomSheetBuilder(BuilderOptions({ + 'output': 'lib/app/my.sheets.dart', + })), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MySheet extends FluorFlowSimpleBottomSheet { + const MySheet({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app/my.sheets.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension BottomSheets on _i1.BottomSheetService { + Future<(bool?, dynamic)> showMySheet({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + bool fullscreen = false, + bool draggable = true, + }) => + showBottomSheet<(bool?, dynamic), _i3.MySheet>( + _i3.MySheet(completer: closeSheet), + barrierColor: barrierColor, + fullscreen: fullscreen, + draggable: draggable, + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + }); +} diff --git a/packages/fluorflow_generator/test/builder/dialog_builder_test.dart b/packages/fluorflow_generator/test/builder/dialog_builder_test.dart new file mode 100644 index 0000000..f43ea7a --- /dev/null +++ b/packages/fluorflow_generator/test/builder/dialog_builder_test.dart @@ -0,0 +1,1367 @@ +import 'package:build/build.dart'; +import 'package:build_test/build_test.dart'; +import 'package:fluorflow/annotations.dart'; +import 'package:fluorflow_generator/src/builder/dialog_builder.dart'; +import 'package:recase/recase.dart'; +import 'package:source_gen/source_gen.dart'; +import 'package:test/test.dart'; + +void main() { + group('DialogBuilder', () { + test( + 'should not generate something when no input is given.', + () => + testBuilder(DialogBuilder(BuilderOptions.empty), {}, outputs: {})); + + test( + 'should not generate something when no subclasses for dialogs are present.', + () => testBuilder(DialogBuilder(BuilderOptions.empty), { + 'a|lib/a.dart': ''' + class View {} + ''' + }, outputs: {})); + + group('for FluorFlowSimpleDialog', () { + test( + 'should generate dialog method for dynamic return type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + const MyDialog({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog( + {_i2.Color barrierColor = const _i2.Color(0x80000000)}) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method for void return type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + const MyDialog({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, void)> showMyDialog( + {_i2.Color barrierColor = const _i2.Color(0x80000000)}) => + showDialog<(bool?, void)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, null)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method for core return type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + const MyDialog({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, String?)> showMyDialog( + {_i2.Color barrierColor = const _i2.Color(0x80000000)}) => + showDialog<(bool?, String?)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method for library return type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + import 'b.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + const MyDialog({super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class DialogResultType {} + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i3; + +import 'package:a/a.dart' as _i4; +import 'package:a/b.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, _i2.DialogResultType?)> showMyDialog( + {_i3.Color barrierColor = const _i3.Color(0x80000000)}) => + showDialog<(bool?, _i2.DialogResultType?)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i4.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for FluorFlowDialog', () { + test( + 'should generate dialog method for dynamic return type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowDialog { + const MyDialog({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog( + {_i2.Color barrierColor = const _i2.Color(0x80000000)}) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method for void return type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowDialog { + const MyDialog({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, void)> showMyDialog( + {_i2.Color barrierColor = const _i2.Color(0x80000000)}) => + showDialog<(bool?, void)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, null)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method for core return type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowDialog { + const MyDialog({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, String?)> showMyDialog( + {_i2.Color barrierColor = const _i2.Color(0x80000000)}) => + showDialog<(bool?, String?)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method for library return type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + import 'b.dart'; + + class MyDialog extends FluorFlowDialog { + const MyDialog({super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class DialogResultType {} + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i3; + +import 'package:a/a.dart' as _i4; +import 'package:a/b.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, _i2.DialogResultType?)> showMyDialog( + {_i3.Color barrierColor = const _i3.Color(0x80000000)}) => + showDialog<(bool?, _i2.DialogResultType?)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i4.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for Dialog with parameters', () { + test( + 'should generate dialog method with required positional argument.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + final String pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required String pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with required nullable positional argument.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + final String? pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required String? pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with required named argument.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + final String pos; + const MyDialog({required this.pos, super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required String pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + completer: closeDialog, + pos: pos, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with an optional named argument.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + final String? pos; + const MyDialog({this.pos, super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + String? pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + completer: closeDialog, + pos: pos, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with a defaulted named argument.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + final String pos; + const MyDialog({this.pos = 'default', super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + String pos = 'default', + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + completer: closeDialog, + pos: pos, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with external referenced argument.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + import 'b.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + final MyDialogRef pos; + const MyDialog({required this.pos, super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class MyDialogRef {} + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i4; +import 'package:a/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required _i3.MyDialogRef pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i4.MyDialog( + completer: closeDialog, + pos: pos, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for Dialog with special parameter types', () { + test( + 'should generate dialog method with generic list of primitive type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + final List pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required List pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with generic list of complex type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class Foobar {} + + class MyDialog extends FluorFlowSimpleDialog { + final List pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required List<_i3.Foobar> pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with recursive generic type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart'; + + class Foo {} + class Bar {} + + class MyDialog extends FluorFlowSimpleDialog { + final Foo> pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Baz {} + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required _i3.Foo<_i3.Bar<_i4.Baz, int>> pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with aliased import type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart' as b; + + class Foo {} + + class MyDialog extends FluorFlowSimpleDialog { + final Foo pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Baz {} + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required _i3.Foo<_i4.Baz> pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with function type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + final void Function() pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required void Function() pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with complex function type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart'; + + class Foo {} + + class Bar {} + + class MyDialog extends FluorFlowSimpleDialog { + final Foo Function(Bar i) pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Baz {} + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required _i3.Foo Function(_i3.Bar<_i4.Baz>) pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with complex function named parameters type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart'; + + class Foo {} + + class Bar {} + + class MyDialog extends FluorFlowSimpleDialog { + final Foo Function(Bar i, { required Foo f, Baz? b }) pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Baz {} + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required _i3.Foo Function( + _i3.Bar<_i4.Baz>, { + required _i3.Foo f, + _i4.Baz? b, + }) pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with complex function optional parameters type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart'; + + class Foo {} + + class Bar {} + + class MyDialog extends FluorFlowSimpleDialog { + final Foo Function(Bar i, [Foo? f]) pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Baz {} + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required _i3.Foo Function( + _i3.Bar<_i4.Baz>, [ + _i3.Foo?, + ]) pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with aliased type.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + import 'b.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + final MyCallback pos; + const MyDialog(this.pos, {super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + class Foobar {} + + typedef MyCallback = void Function(Foobar); + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i4; +import 'package:a/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog({ + _i2.Color barrierColor = const _i2.Color(0x80000000), + required _i3.MyCallback pos, + }) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i4.MyDialog( + pos, + completer: closeDialog, + )), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('with @DialogConfig()', () { + test( + 'should generate dialog method with custom default barrier color.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:fluorflow/fluorflow.dart'; + + @DialogConfig( + defaultBarrierColor: 0x34ff0000, + ) + class MyDialog extends FluorFlowSimpleDialog { + const MyDialog({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog( + {_i2.Color barrierColor = const _i2.Color(0x34ff0000)}) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate dialog method with custom page builder.', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:fluorflow/fluorflow.dart'; + + import 'b.dart'; + + @DialogConfig( + routeBuilder: RouteBuilder.custom, + pageRouteBuilder: CustomBuilder, + ) + class MyDialog extends FluorFlowSimpleDialog { + const MyDialog({super.key, required this.completer}); + } + ''', + 'a|lib/b.dart': ''' + import 'package:flutter/material.dart'; + + class CustomBuilder extends PageRouteBuilder {} + ''' + }, + outputs: { + 'a|lib/app.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i4; +import 'package:a/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog( + {_i2.Color barrierColor = const _i2.Color(0x80000000)}) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i3.CustomBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i4.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should throw when custom page is requested, but no page builder is provided.', + () async { + try { + await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:fluorflow/fluorflow.dart'; + import 'package:flutter/material.dart'; + + @DialogConfig( + routeBuilder: RouteBuilder.custom, + ) + class MyDialog extends FluorFlowSimpleDialog { + const MyDialog({super.key, required this.completer}); + } + + class CustomBuilder extends PageRouteBuilder {} + ''' + }, + reader: await PackageAssetReader.currentIsolate()); + fail('Should have thrown'); + } catch (e) { + expect(e, isA()); + } + }); + + for (final (transition, resultBuilder) in RouteBuilder.values + .where((t) => t != RouteBuilder.custom) + .map((t) => (t, '${t.name.pascalCase}PageRouteBuilder'))) { + test( + 'should use correct page route builder ' + '($resultBuilder) for transition (${transition.name}).', + () async => await testBuilder( + DialogBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:fluorflow/fluorflow.dart'; + import 'package:flutter/material.dart'; + + @DialogConfig( + routeBuilder: RouteBuilder.${transition.name}, + ) + class MyDialog extends FluorFlowSimpleDialog { + const MyDialog({super.key, required this.completer}); + } + ''', + }, + outputs: { + 'a|lib/app.dialogs.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog( + {_i2.Color barrierColor = const _i2.Color(0x80000000)}) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.$resultBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog(completer: closeDialog)), + ).then((r) => (r?.\$1, r?.\$2)); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + } + }); + + group('with Builder Configuration', () { + test( + 'should use custom output if configured.', + () async => await testBuilder( + DialogBuilder(BuilderOptions({ + 'output': 'lib/app/my.dialogs.dart', + })), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/fluorflow.dart'; + + class MyDialog extends FluorFlowSimpleDialog { + const MyDialog({super.key, required this.completer}); + } + ''' + }, + outputs: { + 'a|lib/app/my.dialogs.dart': r''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:ui' as _i2; + +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +extension Dialogs on _i1.DialogService { + Future<(bool?, dynamic)> showMyDialog( + {_i2.Color barrierColor = const _i2.Color(0x80000000)}) => + showDialog<(bool?, dynamic)>( + barrierColor: barrierColor, + dialogBuilder: _i1.NoTransitionPageRouteBuilder( + pageBuilder: ( + _, + __, + ___, + ) => + _i3.MyDialog(completer: closeDialog)), + ).then((r) => (r?.$1, r?.$2)); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + }); +} diff --git a/packages/fluorflow_generator/test/builder/locator_builder_test.dart b/packages/fluorflow_generator/test/builder/locator_builder_test.dart new file mode 100644 index 0000000..8cc57d1 --- /dev/null +++ b/packages/fluorflow_generator/test/builder/locator_builder_test.dart @@ -0,0 +1,1102 @@ +import 'package:build/build.dart'; +import 'package:build_test/build_test.dart'; +import 'package:fluorflow_generator/src/builder/locator_builder.dart'; +import 'package:source_gen/source_gen.dart'; +import 'package:test/test.dart'; + +void main() { + group('LocatorBuilder', () { + test( + 'should not generate something when no input is given.', + () => + testBuilder(LocatorBuilder(BuilderOptions.empty), {}, outputs: {})); + + test( + 'should register the services when no other things are registered.', + () => testBuilder(LocatorBuilder(BuilderOptions.empty), { + 'a|lib/a.dart': ''' + class Service {} + ''' + }, outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + })); + + group('for Singletons', () { + test( + 'should generate registration for a singleton service.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class ServiceA {} + ''', + 'a|lib/sub/b.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class ServiceB {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:a/sub/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingleton(_i2.ServiceA()); + _i1.locator.registerSingleton(_i3.ServiceB()); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate registration for a singleton service with dependencies.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + import 'sub/b.dart'; + + @Singleton(dependencies: [ServiceB]) + class ServiceA {} + ''', + 'a|lib/sub/b.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class ServiceB {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:a/sub/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingletonWithDependencies( + () => _i2.ServiceA(), + dependsOn: [_i3.ServiceB], + ); + _i1.locator.registerSingleton(_i3.ServiceB()); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate registration for a singleton service function.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class Svc {} + + @Singleton() + Svc factory() => Svc(); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingleton(_i2.factory()); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate registration for a singleton service function with dependencies.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class SvcA {} + + class SvcB {} + + @Singleton(dependencies: [SvcA]) + SvcB factory() => SvcB(); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingleton(_i2.SvcA()); + _i1.locator.registerSingletonWithDependencies( + () => _i2.factory(), + dependsOn: [_i2.SvcA], + ); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for LazySingletons', () { + test( + 'should generate registration for a lazy singleton service.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @LazySingleton() + class ServiceA {} + ''', + 'a|lib/sub/b.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @LazySingleton() + class ServiceB {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:a/sub/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerLazySingleton(() => _i2.ServiceA()); + _i1.locator.registerLazySingleton(() => _i3.ServiceB()); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate registration for a lazy singleton service function.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class Svc {} + + @LazySingleton() + Svc factory() => Svc(); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerLazySingleton(_i2.factory); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for AsyncSingletons', () { + test( + 'should generate registration for an async singleton service.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @AsyncSingleton(factory: AsyncSingletonServiceA.create) + class AsyncSingletonServiceA { + static Future create() async => + AsyncSingletonServiceA(); + } + ''', + 'a|lib/sub/b.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @AsyncSingleton(factory: createService) + class AsyncSingletonServiceB {} + + Future createService() async => + AsyncSingletonServiceB(); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:a/sub/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingletonAsync(_i2.AsyncSingletonServiceA.create); + _i1.locator.registerSingletonAsync(_i3.createService); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test('should throw when an async singleton on a class has no factory.', + () async { + try { + await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @AsyncSingleton() + class Svc {} + ''' + }, + reader: await PackageAssetReader.currentIsolate()); + fail('should throw'); + } catch (e) { + expect(e, isA()); + } + }); + + test( + 'should generate registration for an async singleton service with dependencies.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + import 'sub/b.dart'; + + @AsyncSingleton( + factory: AsyncSingletonServiceA.create, + dependencies: [AsyncSingletonServiceB]) + class AsyncSingletonServiceA { + static Future create() async => + AsyncSingletonServiceA(); + } + ''', + 'a|lib/sub/b.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @AsyncSingleton(factory: createService) + class AsyncSingletonServiceB {} + + Future createService() async => + AsyncSingletonServiceB(); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:a/sub/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingletonAsync( + _i2.AsyncSingletonServiceA.create, + dependsOn: [_i3.AsyncSingletonServiceB], + ); + _i1.locator.registerSingletonAsync(_i3.createService); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate registration for an async singleton service function.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class Svc {} + + @AsyncSingleton() + Future factory() async => Svc(); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingletonAsync(_i2.factory); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate registration for an async singleton service function with dependencies.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class SvcA {} + + class SvcB {} + + @AsyncSingleton(dependencies: [SvcA]) + Future factory() async => SvcB(); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingleton(_i2.SvcA()); + _i1.locator.registerSingletonAsync( + _i2.factory, + dependsOn: [_i2.SvcA], + ); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for Factories', () { + test( + 'should generate registration for a factory without params.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class Svc {} + + @Factory() + Svc factory() => Svc(); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerFactory(() => _i2.factory()); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + test( + 'should generate registration for a factory without params and external return value.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + import 'b.dart'; + + @Factory() + Svc factory() => Svc(); + ''', + 'a|lib/b.dart': ''' + class Svc {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerFactory(() => _i2.factory()); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate registration and locator extension for factory with 1 param.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class Svc { + final String p1; + Svc(this.p1); + } + + @Factory() + Svc factory(String p1) => Svc(p1); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerFactoryParam<_i2.Svc, String, void>(( + p1, + _, + ) => + _i2.factory(p1)); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} + +extension Factories on _i1.Locator { + _i2.Svc getSvc(String p1) => get(param1: p1); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate registration and locator extension for factory with 1 param and external return value.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + import 'b.dart'; + + @Factory() + Svc factory(String p1) => Svc(p1); + ''', + 'a|lib/b.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class Svc { + final String p1; + Svc(this.p1); + } + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerFactoryParam<_i2.Svc, String, void>(( + p1, + _, + ) => + _i3.factory(p1)); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} + +extension Factories on _i1.Locator { + _i2.Svc getSvc(String p1) => get(param1: p1); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate registration and locator extension for factory with 2 params.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class Ref {} + + class Svc { + final String p1; + final Ref p2; + Svc(this.p1, this.p2); + } + + @Factory() + Svc factory(String p1, Ref p2) => Svc(p1, p2); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerFactoryParam<_i2.Svc, String, _i2.Ref>(( + p1, + p2, + ) => + _i2.factory( + p1, + p2, + )); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} + +extension Factories on _i1.Locator { + _i2.Svc getSvc( + String p1, + _i2.Ref p2, + ) => + get( + param1: p1, + param2: p2, + ); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate registration and locator extension for factory with 2 params and external return value.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + import 'b.dart'; + + @Factory() + Svc factory(String p1, Ref p2) => Svc(p1, p2); + ''', + 'a|lib/b.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class Ref {} + + class Svc { + final String p1; + final Ref p2; + Svc(this.p1, this.p2); + } + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerFactoryParam<_i2.Svc, String, _i2.Ref>(( + p1, + p2, + ) => + _i3.factory( + p1, + p2, + )); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} + +extension Factories on _i1.Locator { + _i2.Svc getSvc( + String p1, + _i2.Ref p2, + ) => + get( + param1: p1, + param2: p2, + ); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test('should throw when factory method is private.', () async { + try { + await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class Svc {} + + @Factory() + Svc _factory() => Svc(); + ''' + }, + reader: await PackageAssetReader.currentIsolate()); + fail('should throw'); + } catch (e) { + expect(e, isA()); + } + }); + + test('should throw when factory method has more than 2 params.', + () async { + try { + await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class Svc {} + + @Factory() + Svc _factory(String p1, String p2, String p3) => Svc(); + ''' + }, + reader: await PackageAssetReader.currentIsolate()); + fail('should throw'); + } catch (e) { + expect(e, isA()); + } + }); + }); + + group('with IgnoreDependency', () { + for (final ca in ['Singleton', 'LazySingleton', 'AsyncSingleton']) { + test( + 'should ignore the dependency when annotation is present on $ca.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @$ca() + @IgnoreDependency() + class ServiceA {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + } + + for (final ca in [ + 'Singleton', + 'LazySingleton', + 'AsyncSingleton', + 'Factory' + ]) { + test( + 'should ignore the dependency factory when annotation is present on $ca.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class ServiceA {} + + @$ca() + @IgnoreDependency() + ServiceA factory() => ServiceA(); + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + } + }); + + group('for CustomLocatorFunctions', () { + test( + 'should not include the custom function if not allowed to.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @CustomLocatorFunction(includeInLocator: false) + void customFunc() {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should include the custom function.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @CustomLocatorFunction() + void customFunc() {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i1; +import 'package:fluorflow/fluorflow.dart' as _i2; + +Future setupLocator() async { + _i1.customFunc(); + _i2.locator.registerLazySingleton(() => _i2.NavigationService()); + _i2.locator.registerLazySingleton(() => _i2.DialogService()); + _i2.locator.registerLazySingleton(() => _i2.BottomSheetService()); + await _i2.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('with Builder Configuration', () { + test( + 'should not generate something when no services are registered and all default services are disabled.', + () => testBuilder( + LocatorBuilder(BuilderOptions({ + 'register_services': { + 'navigation': false, + 'dialog': false, + 'bottomSheet': false + } + })), + { + 'a|lib/a.dart': ''' + class Service {} + ''' + }, + outputs: {})); + + test( + 'should not emit allReady when configured.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions({ + 'emitAllReady': false, + })), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class ServiceA {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingleton(_i2.ServiceA()); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should use custom output if configured.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions({ + 'output': 'lib/app/my.locator.dart', + })), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class ServiceA {} + ''' + }, + outputs: { + 'a|lib/app/my.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingleton(_i2.ServiceA()); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should not register NavigationService when disabled.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions({ + 'register_services': {'navigation': false}, + })), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class ServiceA {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingleton(_i2.ServiceA()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should not register DialogService when disabled.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions({ + 'register_services': {'dialog': false}, + })), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class ServiceA {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingleton(_i2.ServiceA()); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.BottomSheetService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should not register BottomSheetService when disabled.', + () async => await testBuilder( + LocatorBuilder(BuilderOptions({ + 'register_services': {'bottomSheet': false}, + })), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class ServiceA {} + ''' + }, + outputs: { + 'a|lib/app.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i1; + +Future setupLocator() async { + _i1.locator.registerSingleton(_i2.ServiceA()); + _i1.locator.registerLazySingleton(() => _i1.NavigationService()); + _i1.locator.registerLazySingleton(() => _i1.DialogService()); + await _i1.locator.allReady(); +} +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + }); +} diff --git a/packages/fluorflow_generator/test/builder/router_builder_test.dart b/packages/fluorflow_generator/test/builder/router_builder_test.dart new file mode 100644 index 0000000..711a874 --- /dev/null +++ b/packages/fluorflow_generator/test/builder/router_builder_test.dart @@ -0,0 +1,1232 @@ +import 'package:build/build.dart'; +import 'package:build_test/build_test.dart'; +import 'package:fluorflow/annotations.dart'; +import 'package:fluorflow_generator/src/builder/router_builder.dart'; +import 'package:recase/recase.dart'; +import 'package:source_gen/source_gen.dart'; +import 'package:test/test.dart'; + +void main() { + group('RouterBuilder', () { + test( + 'should not generate something when no input is given.', + () => + testBuilder(RouterBuilder(BuilderOptions.empty), {}, outputs: {})); + + test( + 'should not generate something when no injectable annotations are present.', + () => testBuilder(RouterBuilder(BuilderOptions.empty), { + 'a|lib/a.dart': ''' + class View {} + ''' + }, outputs: {})); + + group('for Routable()', () { + test( + 'should generate route, pageBuilder, onGeneratedRoute, and extension methods for a route.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable() + class View extends StatelessWidget {} + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) => + const _i3.View(), + ) +}; +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({bool preventDuplicates = true}) => navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void replaceWithView({bool preventDuplicates = true}) => replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void rootToView() => rootTo(AppRoute.view.path); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate custom route path.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable(path: '/fooBarBaz') + class View extends StatelessWidget {} + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/fooBarBaz'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) => + const _i3.View(), + ) +}; +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({bool preventDuplicates = true}) => navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void replaceWithView({bool preventDuplicates = true}) => replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void rootToView() => rootTo(AppRoute.view.path); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should not generate navigateTo extension if disabled.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable(navigateToExtension: false) + class View extends StatelessWidget {} + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) => + const _i3.View(), + ) +}; +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + void replaceWithView({bool preventDuplicates = true}) => replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void rootToView() => rootTo(AppRoute.view.path); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should not generate a replaceWith extension if disabled.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable(replaceWithExtension: false) + class View extends StatelessWidget {} + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) => + const _i3.View(), + ) +}; +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({bool preventDuplicates = true}) => navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void rootToView() => rootTo(AppRoute.view.path); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should not generate a rootTo extension if disabled.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable(rootToExtension: false) + class View extends StatelessWidget {} + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) => + const _i3.View(), + ) +}; +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({bool preventDuplicates = true}) => navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void replaceWithView({bool preventDuplicates = true}) => replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should use custom page route builder if provided.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + import 'b.dart'; + + @Routable(routeBuilder: RouteBuilder.custom, pageRouteBuilder: CustomBuilder) + class View extends StatelessWidget {} + ''', + 'a|lib/b.dart': ''' + import 'package:flutter/material.dart'; + + class CustomBuilder extends PageRouteBuilder {} + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i2; +import 'package:fluorflow/fluorflow.dart' as _i4; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.CustomBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) => + const _i3.View(), + ) +}; +final onGenerateRoute = _i4.generateRouteFactory(_pages); + +extension RouteNavigation on _i4.NavigationService { + Future? navigateToView({bool preventDuplicates = true}) => navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void replaceWithView({bool preventDuplicates = true}) => replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void rootToView() => rootTo(AppRoute.view.path); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should throw when custom page is requested, but no page builder is provided.', + () async { + try { + await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + import 'b.dart'; + + @Routable(routeBuilder: RouteBuilder.custom) + class View extends StatelessWidget {} + ''', + 'a|lib/b.dart': ''' + import 'package:flutter/material.dart'; + + class CustomBuilder extends PageRouteBuilder {} + ''' + }, + reader: await PackageAssetReader.currentIsolate()); + fail('Should have thrown'); + } catch (e) { + expect(e, isA()); + } + }); + + for (final (transition, resultBuilder) in RouteBuilder.values + .where((t) => t != RouteBuilder.custom) + .map((t) => (t, '${t.name.pascalCase}PageRouteBuilder'))) { + test( + 'should use correct page route builder ' + '($resultBuilder) for transition (${transition.name}).', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable(routeBuilder: RouteBuilder.${transition.name}) + class View extends StatelessWidget {} + ''', + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.$resultBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) => + const _i3.View(), + ) +}; +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({bool preventDuplicates = true}) => navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void replaceWithView({bool preventDuplicates = true}) => replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void rootToView() => rootTo(AppRoute.view.path); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + } + + test( + 'should not generate route arguments for only "key" argument.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable() + class View extends StatelessWidget { + const View({super.key}); + } + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) => + const _i3.View(), + ) +}; +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({bool preventDuplicates = true}) => navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void replaceWithView({bool preventDuplicates = true}) => replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void rootToView() => rootTo(AppRoute.view.path); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should not generate route arguments for only "key" argument.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable() + class View extends StatelessWidget { + const View({super.key}); + } + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) => + const _i3.View(), + ) +}; +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({bool preventDuplicates = true}) => navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void replaceWithView({bool preventDuplicates = true}) => replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void rootToView() => rootTo(AppRoute.view.path); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate route arguments for a required positional argument.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable() + class View extends StatelessWidget { + final String arg; + View(this.arg, {super.key}); + } + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) { + final args = (data.arguments as ViewArguments); + return _i3.View(args.arg); + }, + ) +}; + +class ViewArguments { + const ViewArguments({required this.arg}); + + final String arg; +} + +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({ + required String arg, + bool preventDuplicates = true, + }) => + navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void replaceWithView({ + required String arg, + bool preventDuplicates = true, + }) => + replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void rootToView({required String arg}) => rootTo( + AppRoute.view.path, + arguments: ViewArguments(arg: arg), + ); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate route arguments for a required nullable positional argument.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable() + class View extends StatelessWidget { + final String? arg; + View(this.arg, {super.key}); + } + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) { + final args = (data.arguments as ViewArguments); + return _i3.View(args.arg); + }, + ) +}; + +class ViewArguments { + const ViewArguments({required this.arg}); + + final String? arg; +} + +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({ + required String? arg, + bool preventDuplicates = true, + }) => + navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void replaceWithView({ + required String? arg, + bool preventDuplicates = true, + }) => + replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void rootToView({required String? arg}) => rootTo( + AppRoute.view.path, + arguments: ViewArguments(arg: arg), + ); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate route arguments for an optional positional argument.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable() + class View extends StatelessWidget { + final String arg; + View([this.arg = 'default']); + } + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) { + final args = (data.arguments as ViewArguments); + return _i3.View(args.arg); + }, + ) +}; + +class ViewArguments { + const ViewArguments({this.arg = 'default'}); + + final String arg; +} + +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({ + String arg = 'default', + bool preventDuplicates = true, + }) => + navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void replaceWithView({ + String arg = 'default', + bool preventDuplicates = true, + }) => + replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void rootToView({String arg = 'default'}) => rootTo( + AppRoute.view.path, + arguments: ViewArguments(arg: arg), + ); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate route arguments for a required named argument.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable() + class View extends StatelessWidget { + final String arg; + View({super.key, required this.arg}); + } + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) { + final args = (data.arguments as ViewArguments); + return _i3.View(arg: args.arg); + }, + ) +}; + +class ViewArguments { + const ViewArguments({required this.arg}); + + final String arg; +} + +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({ + required String arg, + bool preventDuplicates = true, + }) => + navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void replaceWithView({ + required String arg, + bool preventDuplicates = true, + }) => + replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void rootToView({required String arg}) => rootTo( + AppRoute.view.path, + arguments: ViewArguments(arg: arg), + ); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate route arguments for an optional named argument.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable() + class View extends StatelessWidget { + final String? arg; + View({super.key, this.arg}); + } + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) { + final args = (data.arguments as ViewArguments); + return _i3.View(arg: args.arg); + }, + ) +}; + +class ViewArguments { + const ViewArguments({this.arg}); + + final String? arg; +} + +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({ + String? arg, + bool preventDuplicates = true, + }) => + navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void replaceWithView({ + String? arg, + bool preventDuplicates = true, + }) => + replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void rootToView({String? arg}) => rootTo( + AppRoute.view.path, + arguments: ViewArguments(arg: arg), + ); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate route arguments for a defaulted named argument.', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable() + class View extends StatelessWidget { + final String arg; + View({super.key, this.arg = 'default'}); + } + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) { + final args = (data.arguments as ViewArguments); + return _i3.View(arg: args.arg); + }, + ) +}; + +class ViewArguments { + const ViewArguments({this.arg = 'default'}); + + final String arg; +} + +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({ + String arg = 'default', + bool preventDuplicates = true, + }) => + navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void replaceWithView({ + String arg = 'default', + bool preventDuplicates = true, + }) => + replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void rootToView({String arg = 'default'}) => rootTo( + AppRoute.view.path, + arguments: ViewArguments(arg: arg), + ); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate correct arguments for referenced arguments (custom).', + () async => await testBuilder( + RouterBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + import 'b.dart'; + + @Routable() + class View extends StatelessWidget { + final Arg arg; + View(this.arg, {super.key}); + } + ''', + 'a|lib/b.dart': ''' + class Arg {} + ''' + }, + outputs: { + 'a|lib/app.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:a/b.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) { + final args = (data.arguments as ViewArguments); + return _i3.View(args.arg); + }, + ) +}; + +class ViewArguments { + const ViewArguments({required this.arg}); + + final _i4.Arg arg; +} + +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({ + required _i4.Arg arg, + bool preventDuplicates = true, + }) => + navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void replaceWithView({ + required _i4.Arg arg, + bool preventDuplicates = true, + }) => + replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + arguments: ViewArguments(arg: arg), + ); + void rootToView({required _i4.Arg arg}) => rootTo( + AppRoute.view.path, + arguments: ViewArguments(arg: arg), + ); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('with Builder Configuration', () { + test( + 'should use custom output if configured.', + () async => await testBuilder( + RouterBuilder(BuilderOptions({ + 'output': 'lib/app/my.router.dart', + })), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + import 'package:flutter/material.dart'; + + @Routable() + class View extends StatelessWidget {} + ''' + }, + outputs: { + 'a|lib/app/my.router.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:flutter/widgets.dart' as _i1; + +enum AppRoute { + view('/view'); + + const AppRoute(this.path); + + final String path; +} + +final _pages = { + AppRoute.view.path: (data) => _i2.NoTransitionPageRouteBuilder( + settings: data, + pageBuilder: ( + _, + __, + ___, + ) => + const _i3.View(), + ) +}; +final onGenerateRoute = _i2.generateRouteFactory(_pages); + +extension RouteNavigation on _i2.NavigationService { + Future? navigateToView({bool preventDuplicates = true}) => navigateTo( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void replaceWithView({bool preventDuplicates = true}) => replaceWith( + AppRoute.view.path, + preventDuplicates: preventDuplicates, + ); + void rootToView() => rootTo(AppRoute.view.path); +} +''', + }, + reader: await PackageAssetReader.currentIsolate())); + }); + }); +} diff --git a/packages/fluorflow_generator/test/builder/test_locator_builder_test.dart b/packages/fluorflow_generator/test/builder/test_locator_builder_test.dart new file mode 100644 index 0000000..b68dcd9 --- /dev/null +++ b/packages/fluorflow_generator/test/builder/test_locator_builder_test.dart @@ -0,0 +1,1097 @@ +import 'package:build/build.dart'; +import 'package:build_test/build_test.dart'; +import 'package:fluorflow_generator/src/builder/test_locator_builder.dart'; +import 'package:test/test.dart'; + +void main() { + group('TestLocatorBuilder', () { + final noSvcs = BuilderOptions({ + 'services': {'navigation': false, 'dialog': false, 'bottomSheet': false}, + }); + + test('should not run when mockito is not installed.', () async { + final logs = List.empty(growable: true); + + await testBuilder( + TestLocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + class View {} + ''' + }, + outputs: {}, + reader: StubAssetReader(), + onLog: (l) => logs.add(l.toString())); + + expect( + logs, + contains( + '[INFO] testBuilder: Mockito is not installed, skipping builder.')); + }, + skip: + 'This test does not work, since I dont know how to mock the packageConfig correctly.'); + + test( + 'should not generate something when no input is given.', + () => testBuilder(TestLocatorBuilder(BuilderOptions.empty), {}, + outputs: {})); + + test( + 'should generate the default for fluorflow services if no other serivces are given.', + () async => await testBuilder( + TestLocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + class View {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i3; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockNavigationService getMockNavigationService() { + if (_i2.locator.isRegistered<_i2.NavigationService>()) { + _i2.locator.unregister<_i2.NavigationService>(); + } + final service = _i1.MockNavigationService(); + _i2.locator.registerSingleton<_i2.NavigationService>(service); + return service; +} + +_i1.MockDialogService getMockDialogService() { + if (_i2.locator.isRegistered<_i2.DialogService>()) { + _i2.locator.unregister<_i2.DialogService>(); + } + final service = _i1.MockDialogService(); + _i2.locator.registerSingleton<_i2.DialogService>(service); + return service; +} + +_i1.MockBottomSheetService getMockBottomSheetService() { + if (_i2.locator.isRegistered<_i2.BottomSheetService>()) { + _i2.locator.unregister<_i2.BottomSheetService>(); + } + final service = _i1.MockBottomSheetService(); + _i2.locator.registerSingleton<_i2.BottomSheetService>(service); + return service; +} + +@_i3.GenerateNiceMocks([ + _i3.MockSpec<_i2.NavigationService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.DialogService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.BottomSheetService>( + onMissingStub: _i3.OnMissingStub.returnDefault), +]) +void setupTestLocator() { + getMockNavigationService(); + getMockDialogService(); + getMockBottomSheetService(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + group('for Singletons', () { + test( + 'should generate a mock for a class singleton.', + () async => await testBuilder( + TestLocatorBuilder(noSvcs), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class Svc {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i4; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockSvc getMockSvc() { + if (_i2.locator.isRegistered<_i3.Svc>()) { + _i2.locator.unregister<_i3.Svc>(); + } + final service = _i1.MockSvc(); + _i2.locator.registerSingleton<_i3.Svc>(service); + return service; +} + +@_i4.GenerateNiceMocks( + [_i4.MockSpec<_i3.Svc>(onMissingStub: _i4.OnMissingStub.returnDefault)]) +void setupTestLocator() { + getMockSvc(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate a mock for a factory singleton.', + () async => await testBuilder( + TestLocatorBuilder(noSvcs), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + import 'b.dart'; + + @Singleton() + Svc getSvc() => Svc(); + ''', + 'a|lib/b.dart': ''' + class Svc {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i4; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockSvc getMockSvc() { + if (_i2.locator.isRegistered<_i3.Svc>()) { + _i2.locator.unregister<_i3.Svc>(); + } + final service = _i1.MockSvc(); + _i2.locator.registerSingleton<_i3.Svc>(service); + return service; +} + +@_i4.GenerateNiceMocks( + [_i4.MockSpec<_i3.Svc>(onMissingStub: _i4.OnMissingStub.returnDefault)]) +void setupTestLocator() { + getMockSvc(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate a mock for a class singleton in test directory.', + () async => await testBuilder( + TestLocatorBuilder(noSvcs), + { + 'a|test/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @Singleton() + class Svc {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i4; + +import 'a.dart' as _i3; +import 'test.locator.mocks.dart' as _i1; + +_i1.MockSvc getMockSvc() { + if (_i2.locator.isRegistered<_i3.Svc>()) { + _i2.locator.unregister<_i3.Svc>(); + } + final service = _i1.MockSvc(); + _i2.locator.registerSingleton<_i3.Svc>(service); + return service; +} + +@_i4.GenerateNiceMocks( + [_i4.MockSpec<_i3.Svc>(onMissingStub: _i4.OnMissingStub.returnDefault)]) +void setupTestLocator() { + getMockSvc(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for AsyncSingletons', () { + test( + 'should generate a mock for a class singleton.', + () async => await testBuilder( + TestLocatorBuilder(noSvcs), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @AsyncSingleton(factory: Svc.create) + class Svc { + static Future create() async => Svc(); + } + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i4; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockSvc getMockSvc() { + if (_i2.locator.isRegistered<_i3.Svc>()) { + _i2.locator.unregister<_i3.Svc>(); + } + final service = _i1.MockSvc(); + _i2.locator.registerSingleton<_i3.Svc>(service); + return service; +} + +@_i4.GenerateNiceMocks( + [_i4.MockSpec<_i3.Svc>(onMissingStub: _i4.OnMissingStub.returnDefault)]) +void setupTestLocator() { + getMockSvc(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate a mock for a factory singleton.', + () async => await testBuilder( + TestLocatorBuilder(noSvcs), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + import 'b.dart'; + + @AsyncSingleton() + Future getSvc() async => Svc(); + ''', + 'a|lib/b.dart': ''' + class Svc {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i4; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockSvc getMockSvc() { + if (_i2.locator.isRegistered<_i3.Svc>()) { + _i2.locator.unregister<_i3.Svc>(); + } + final service = _i1.MockSvc(); + _i2.locator.registerSingleton<_i3.Svc>(service); + return service; +} + +@_i4.GenerateNiceMocks( + [_i4.MockSpec<_i3.Svc>(onMissingStub: _i4.OnMissingStub.returnDefault)]) +void setupTestLocator() { + getMockSvc(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for LazySingletons', () { + test( + 'should generate a mock for a class singleton.', + () async => await testBuilder( + TestLocatorBuilder(noSvcs), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @LazySingleton() + class Svc {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i4; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockSvc getMockSvc() { + if (_i2.locator.isRegistered<_i3.Svc>()) { + _i2.locator.unregister<_i3.Svc>(); + } + final service = _i1.MockSvc(); + _i2.locator.registerSingleton<_i3.Svc>(service); + return service; +} + +@_i4.GenerateNiceMocks( + [_i4.MockSpec<_i3.Svc>(onMissingStub: _i4.OnMissingStub.returnDefault)]) +void setupTestLocator() { + getMockSvc(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should generate a mock for a factory singleton.', + () async => await testBuilder( + TestLocatorBuilder(noSvcs), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + import 'b.dart'; + + @LazySingleton() + Svc getSvc() => Svc(); + ''', + 'a|lib/b.dart': ''' + class Svc {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i4; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockSvc getMockSvc() { + if (_i2.locator.isRegistered<_i3.Svc>()) { + _i2.locator.unregister<_i3.Svc>(); + } + final service = _i1.MockSvc(); + _i2.locator.registerSingleton<_i3.Svc>(service); + return service; +} + +@_i4.GenerateNiceMocks( + [_i4.MockSpec<_i3.Svc>(onMissingStub: _i4.OnMissingStub.returnDefault)]) +void setupTestLocator() { + getMockSvc(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('for Factories', () { + test( + 'should generate a mock for a factory.', + () async => await testBuilder( + TestLocatorBuilder(noSvcs), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + import 'b.dart'; + + @Factory() + Svc getSvc() => Svc(); + ''', + 'a|lib/b.dart': ''' + class Svc {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/b.dart' as _i3; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i4; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockSvc getMockSvc() { + if (_i2.locator.isRegistered<_i3.Svc>()) { + _i2.locator.unregister<_i3.Svc>(); + } + final service = _i1.MockSvc(); + _i2.locator.registerFactory<_i3.Svc>(() => service); + return service; +} + +@_i4.GenerateNiceMocks( + [_i4.MockSpec<_i3.Svc>(onMissingStub: _i4.OnMissingStub.returnDefault)]) +void setupTestLocator() { + getMockSvc(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('with Builder Config', () { + test( + 'should use custom output if configured.', + () async => await testBuilder( + TestLocatorBuilder(BuilderOptions({ + 'output': 'test/helpers/test.locator.dart', + })), + { + 'a|lib/a.dart': ''' + class View {} + ''' + }, + outputs: { + 'a|test/helpers/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i3; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockNavigationService getMockNavigationService() { + if (_i2.locator.isRegistered<_i2.NavigationService>()) { + _i2.locator.unregister<_i2.NavigationService>(); + } + final service = _i1.MockNavigationService(); + _i2.locator.registerSingleton<_i2.NavigationService>(service); + return service; +} + +_i1.MockDialogService getMockDialogService() { + if (_i2.locator.isRegistered<_i2.DialogService>()) { + _i2.locator.unregister<_i2.DialogService>(); + } + final service = _i1.MockDialogService(); + _i2.locator.registerSingleton<_i2.DialogService>(service); + return service; +} + +_i1.MockBottomSheetService getMockBottomSheetService() { + if (_i2.locator.isRegistered<_i2.BottomSheetService>()) { + _i2.locator.unregister<_i2.BottomSheetService>(); + } + final service = _i1.MockBottomSheetService(); + _i2.locator.registerSingleton<_i2.BottomSheetService>(service); + return service; +} + +@_i3.GenerateNiceMocks([ + _i3.MockSpec<_i2.NavigationService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.DialogService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.BottomSheetService>( + onMissingStub: _i3.OnMissingStub.returnDefault), +]) +void setupTestLocator() { + getMockNavigationService(); + getMockDialogService(); + getMockBottomSheetService(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should not mock navigation service when disabled.', + () async => await testBuilder( + TestLocatorBuilder(BuilderOptions({ + 'services': {'navigation': false}, + })), + { + 'a|lib/a.dart': ''' + class View {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i3; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockDialogService getMockDialogService() { + if (_i2.locator.isRegistered<_i2.DialogService>()) { + _i2.locator.unregister<_i2.DialogService>(); + } + final service = _i1.MockDialogService(); + _i2.locator.registerSingleton<_i2.DialogService>(service); + return service; +} + +_i1.MockBottomSheetService getMockBottomSheetService() { + if (_i2.locator.isRegistered<_i2.BottomSheetService>()) { + _i2.locator.unregister<_i2.BottomSheetService>(); + } + final service = _i1.MockBottomSheetService(); + _i2.locator.registerSingleton<_i2.BottomSheetService>(service); + return service; +} + +@_i3.GenerateNiceMocks([ + _i3.MockSpec<_i2.DialogService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.BottomSheetService>( + onMissingStub: _i3.OnMissingStub.returnDefault), +]) +void setupTestLocator() { + getMockDialogService(); + getMockBottomSheetService(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should not mock dialog service when disabled.', + () async => await testBuilder( + TestLocatorBuilder(BuilderOptions({ + 'services': {'dialog': false}, + })), + { + 'a|lib/a.dart': ''' + class View {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i3; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockNavigationService getMockNavigationService() { + if (_i2.locator.isRegistered<_i2.NavigationService>()) { + _i2.locator.unregister<_i2.NavigationService>(); + } + final service = _i1.MockNavigationService(); + _i2.locator.registerSingleton<_i2.NavigationService>(service); + return service; +} + +_i1.MockBottomSheetService getMockBottomSheetService() { + if (_i2.locator.isRegistered<_i2.BottomSheetService>()) { + _i2.locator.unregister<_i2.BottomSheetService>(); + } + final service = _i1.MockBottomSheetService(); + _i2.locator.registerSingleton<_i2.BottomSheetService>(service); + return service; +} + +@_i3.GenerateNiceMocks([ + _i3.MockSpec<_i2.NavigationService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.BottomSheetService>( + onMissingStub: _i3.OnMissingStub.returnDefault), +]) +void setupTestLocator() { + getMockNavigationService(); + getMockBottomSheetService(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should not mock buttom sheet service when disabled.', + () async => await testBuilder( + TestLocatorBuilder(BuilderOptions({ + 'services': {'bottomSheet': false}, + })), + { + 'a|lib/a.dart': ''' + class View {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i3; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockNavigationService getMockNavigationService() { + if (_i2.locator.isRegistered<_i2.NavigationService>()) { + _i2.locator.unregister<_i2.NavigationService>(); + } + final service = _i1.MockNavigationService(); + _i2.locator.registerSingleton<_i2.NavigationService>(service); + return service; +} + +_i1.MockDialogService getMockDialogService() { + if (_i2.locator.isRegistered<_i2.DialogService>()) { + _i2.locator.unregister<_i2.DialogService>(); + } + final service = _i1.MockDialogService(); + _i2.locator.registerSingleton<_i2.DialogService>(service); + return service; +} + +@_i3.GenerateNiceMocks([ + _i3.MockSpec<_i2.NavigationService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.DialogService>( + onMissingStub: _i3.OnMissingStub.returnDefault), +]) +void setupTestLocator() { + getMockNavigationService(); + getMockDialogService(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should still generate setup function if no services are registered at all.', + () async => await testBuilder( + TestLocatorBuilder(noSvcs), + { + 'a|lib/a.dart': ''' + class View {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i1; + +@_i1.GenerateNiceMocks([]) +void setupTestLocator() {} +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + + group('with IgnoreDependency', () { + for (final ca in ['Singleton', 'LazySingleton', 'AsyncSingleton']) { + test( + 'should ignore the dependency when annotation is present on $ca.', + () async => await testBuilder( + TestLocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @$ca() + @IgnoreDependency() + class ServiceA {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i3; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockNavigationService getMockNavigationService() { + if (_i2.locator.isRegistered<_i2.NavigationService>()) { + _i2.locator.unregister<_i2.NavigationService>(); + } + final service = _i1.MockNavigationService(); + _i2.locator.registerSingleton<_i2.NavigationService>(service); + return service; +} + +_i1.MockDialogService getMockDialogService() { + if (_i2.locator.isRegistered<_i2.DialogService>()) { + _i2.locator.unregister<_i2.DialogService>(); + } + final service = _i1.MockDialogService(); + _i2.locator.registerSingleton<_i2.DialogService>(service); + return service; +} + +_i1.MockBottomSheetService getMockBottomSheetService() { + if (_i2.locator.isRegistered<_i2.BottomSheetService>()) { + _i2.locator.unregister<_i2.BottomSheetService>(); + } + final service = _i1.MockBottomSheetService(); + _i2.locator.registerSingleton<_i2.BottomSheetService>(service); + return service; +} + +@_i3.GenerateNiceMocks([ + _i3.MockSpec<_i2.NavigationService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.DialogService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.BottomSheetService>( + onMissingStub: _i3.OnMissingStub.returnDefault), +]) +void setupTestLocator() { + getMockNavigationService(); + getMockDialogService(); + getMockBottomSheetService(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + } + + for (final ca in [ + 'Singleton', + 'LazySingleton', + 'AsyncSingleton', + 'Factory' + ]) { + test( + 'should ignore the dependency factory when annotation is present on $ca.', + () async => await testBuilder( + TestLocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + class ServiceA {} + + @$ca() + @IgnoreDependency() + ServiceA factory() => ServiceA(); + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i3; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockNavigationService getMockNavigationService() { + if (_i2.locator.isRegistered<_i2.NavigationService>()) { + _i2.locator.unregister<_i2.NavigationService>(); + } + final service = _i1.MockNavigationService(); + _i2.locator.registerSingleton<_i2.NavigationService>(service); + return service; +} + +_i1.MockDialogService getMockDialogService() { + if (_i2.locator.isRegistered<_i2.DialogService>()) { + _i2.locator.unregister<_i2.DialogService>(); + } + final service = _i1.MockDialogService(); + _i2.locator.registerSingleton<_i2.DialogService>(service); + return service; +} + +_i1.MockBottomSheetService getMockBottomSheetService() { + if (_i2.locator.isRegistered<_i2.BottomSheetService>()) { + _i2.locator.unregister<_i2.BottomSheetService>(); + } + final service = _i1.MockBottomSheetService(); + _i2.locator.registerSingleton<_i2.BottomSheetService>(service); + return service; +} + +@_i3.GenerateNiceMocks([ + _i3.MockSpec<_i2.NavigationService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.DialogService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.BottomSheetService>( + onMissingStub: _i3.OnMissingStub.returnDefault), +]) +void setupTestLocator() { + getMockNavigationService(); + getMockDialogService(); + getMockBottomSheetService(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + } + }); + + group('for CustomLocatorFunctions', () { + test( + 'should not include the custom function if not allowed to.', + () async => await testBuilder( + TestLocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @CustomLocatorFunction(includeInTestLocator: false) + void customFunc() {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i3; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockNavigationService getMockNavigationService() { + if (_i2.locator.isRegistered<_i2.NavigationService>()) { + _i2.locator.unregister<_i2.NavigationService>(); + } + final service = _i1.MockNavigationService(); + _i2.locator.registerSingleton<_i2.NavigationService>(service); + return service; +} + +_i1.MockDialogService getMockDialogService() { + if (_i2.locator.isRegistered<_i2.DialogService>()) { + _i2.locator.unregister<_i2.DialogService>(); + } + final service = _i1.MockDialogService(); + _i2.locator.registerSingleton<_i2.DialogService>(service); + return service; +} + +_i1.MockBottomSheetService getMockBottomSheetService() { + if (_i2.locator.isRegistered<_i2.BottomSheetService>()) { + _i2.locator.unregister<_i2.BottomSheetService>(); + } + final service = _i1.MockBottomSheetService(); + _i2.locator.registerSingleton<_i2.BottomSheetService>(service); + return service; +} + +@_i3.GenerateNiceMocks([ + _i3.MockSpec<_i2.NavigationService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.DialogService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.BottomSheetService>( + onMissingStub: _i3.OnMissingStub.returnDefault), +]) +void setupTestLocator() { + getMockNavigationService(); + getMockDialogService(); + getMockBottomSheetService(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should include the custom function.', + () async => await testBuilder( + TestLocatorBuilder(BuilderOptions.empty), + { + 'a|lib/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @CustomLocatorFunction() + void customFunc() {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:a/a.dart' as _i4; +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i3; + +import 'test.locator.mocks.dart' as _i1; + +_i1.MockNavigationService getMockNavigationService() { + if (_i2.locator.isRegistered<_i2.NavigationService>()) { + _i2.locator.unregister<_i2.NavigationService>(); + } + final service = _i1.MockNavigationService(); + _i2.locator.registerSingleton<_i2.NavigationService>(service); + return service; +} + +_i1.MockDialogService getMockDialogService() { + if (_i2.locator.isRegistered<_i2.DialogService>()) { + _i2.locator.unregister<_i2.DialogService>(); + } + final service = _i1.MockDialogService(); + _i2.locator.registerSingleton<_i2.DialogService>(service); + return service; +} + +_i1.MockBottomSheetService getMockBottomSheetService() { + if (_i2.locator.isRegistered<_i2.BottomSheetService>()) { + _i2.locator.unregister<_i2.BottomSheetService>(); + } + final service = _i1.MockBottomSheetService(); + _i2.locator.registerSingleton<_i2.BottomSheetService>(service); + return service; +} + +@_i3.GenerateNiceMocks([ + _i3.MockSpec<_i2.NavigationService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.DialogService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.BottomSheetService>( + onMissingStub: _i3.OnMissingStub.returnDefault), +]) +void setupTestLocator() { + _i4.customFunc(); + getMockNavigationService(); + getMockDialogService(); + getMockBottomSheetService(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + + test( + 'should include the custom function from test files.', + () async => await testBuilder( + TestLocatorBuilder(BuilderOptions.empty), + { + 'a|test/a.dart': ''' + import 'package:fluorflow/annotations.dart'; + + @CustomLocatorFunction() + void customFunc() {} + ''' + }, + outputs: { + 'a|test/test.locator.dart': ''' +// ignore_for_file: type=lint + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:fluorflow/fluorflow.dart' as _i2; +import 'package:mockito/annotations.dart' as _i3; + +import 'a.dart' as _i4; +import 'test.locator.mocks.dart' as _i1; + +_i1.MockNavigationService getMockNavigationService() { + if (_i2.locator.isRegistered<_i2.NavigationService>()) { + _i2.locator.unregister<_i2.NavigationService>(); + } + final service = _i1.MockNavigationService(); + _i2.locator.registerSingleton<_i2.NavigationService>(service); + return service; +} + +_i1.MockDialogService getMockDialogService() { + if (_i2.locator.isRegistered<_i2.DialogService>()) { + _i2.locator.unregister<_i2.DialogService>(); + } + final service = _i1.MockDialogService(); + _i2.locator.registerSingleton<_i2.DialogService>(service); + return service; +} + +_i1.MockBottomSheetService getMockBottomSheetService() { + if (_i2.locator.isRegistered<_i2.BottomSheetService>()) { + _i2.locator.unregister<_i2.BottomSheetService>(); + } + final service = _i1.MockBottomSheetService(); + _i2.locator.registerSingleton<_i2.BottomSheetService>(service); + return service; +} + +@_i3.GenerateNiceMocks([ + _i3.MockSpec<_i2.NavigationService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.DialogService>( + onMissingStub: _i3.OnMissingStub.returnDefault), + _i3.MockSpec<_i2.BottomSheetService>( + onMissingStub: _i3.OnMissingStub.returnDefault), +]) +void setupTestLocator() { + _i4.customFunc(); + getMockNavigationService(); + getMockDialogService(); + getMockBottomSheetService(); +} + +void tearDownLocator() => _i2.locator.reset(); +''' + }, + reader: await PackageAssetReader.currentIsolate())); + }); + }); +} diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 0000000..96dc219 --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,325 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + ansi_styles: + dependency: transitive + description: + name: ansi_styles + sha256: "9c656cc12b3c27b17dd982b2cc5c0cfdfbdabd7bc8f3ae5e8542d9867b47ce8a" + url: "https://pub.dev" + source: hosted + version: "0.3.2+1" + args: + dependency: transitive + description: + name: args + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" + source: hosted + version: "2.4.2" + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + charcode: + dependency: transitive + description: + name: charcode + sha256: fb98c0f6d12c920a02ee2d998da788bca066ca5f148492b7085ee23372b12306 + url: "https://pub.dev" + source: hosted + version: "1.3.1" + cli_launcher: + dependency: transitive + description: + name: cli_launcher + sha256: "5e7e0282b79e8642edd6510ee468ae2976d847a0a29b3916e85f5fa1bfe24005" + url: "https://pub.dev" + source: hosted + version: "0.3.1" + cli_util: + dependency: transitive + description: + name: cli_util + sha256: c05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19 + url: "https://pub.dev" + source: hosted + version: "0.4.1" + collection: + dependency: transitive + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + conventional_commit: + dependency: transitive + description: + name: conventional_commit + sha256: dec15ad1118f029c618651a4359eb9135d8b88f761aa24e4016d061cd45948f2 + url: "https://pub.dev" + source: hosted + version: "0.6.0+1" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + url: "https://pub.dev" + source: hosted + version: "2.3.1" + http: + dependency: transitive + description: + name: http + sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba + url: "https://pub.dev" + source: hosted + version: "1.2.0" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 + url: "https://pub.dev" + source: hosted + version: "4.8.1" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + melos: + dependency: "direct dev" + description: + name: melos + sha256: "7266e9fc9fee5f4a0c075e5cec375c00736dfc944358f533b740b93b3d8d681e" + url: "https://pub.dev" + source: hosted + version: "4.1.0" + meta: + dependency: transitive + description: + name: meta + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + url: "https://pub.dev" + source: hosted + version: "1.12.0" + mustache_template: + dependency: transitive + description: + name: mustache_template + sha256: a46e26f91445bfb0b60519be280555b06792460b27b19e2b19ad5b9740df5d1c + url: "https://pub.dev" + source: hosted + version: "2.0.0" + path: + dependency: transitive + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + platform: + dependency: transitive + description: + name: platform + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + url: "https://pub.dev" + source: hosted + version: "3.1.4" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + process: + dependency: transitive + description: + name: process + sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32" + url: "https://pub.dev" + source: hosted + version: "5.0.2" + prompts: + dependency: transitive + description: + name: prompts + sha256: "3773b845e85a849f01e793c4fc18a45d52d7783b4cb6c0569fad19f9d0a774a1" + url: "https://pub.dev" + source: hosted + version: "2.0.0" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + pub_updater: + dependency: transitive + description: + name: pub_updater + sha256: "54e8dc865349059ebe7f163d6acce7c89eb958b8047e6d6e80ce93b13d7c9e60" + url: "https://pub.dev" + source: hosted + version: "0.4.0" + pubspec: + dependency: transitive + description: + name: pubspec + sha256: f534a50a2b4d48dc3bc0ec147c8bd7c304280fff23b153f3f11803c4d49d927e + url: "https://pub.dev" + source: hosted + version: "2.3.0" + quiver: + dependency: transitive + description: + name: quiver + sha256: b1c1ac5ce6688d77f65f3375a9abb9319b3cb32486bdc7a1e0fdf004d7ba4e47 + url: "https://pub.dev" + source: hosted + version: "3.2.1" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + url: "https://pub.dev" + source: hosted + version: "0.7.0" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + uri: + dependency: transitive + description: + name: uri + sha256: "889eea21e953187c6099802b7b4cf5219ba8f3518f604a1033064d45b1b8268a" + url: "https://pub.dev" + source: hosted + version: "1.0.0" + web: + dependency: transitive + description: + name: web + sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05" + url: "https://pub.dev" + source: hosted + version: "0.4.2" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" + yaml_edit: + dependency: transitive + description: + name: yaml_edit + sha256: "1579d4a0340a83cf9e4d580ea51a16329c916973bffd5bd4b45e911b25d46bfd" + url: "https://pub.dev" + source: hosted + version: "2.1.1" +sdks: + dart: ">=3.2.0 <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..292a4e4 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,8 @@ +name: fluorflow_workspace +publish_to: 'none' + +environment: + sdk: '>=3.0.0 <4.0.0' + +dev_dependencies: + melos: ^4.1.0