├── .github ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ ├── android_workflow.yaml │ ├── angular_workflow.yaml │ ├── app_ui_workflow.yaml │ ├── archive_workflow.yaml │ ├── flutter_workflow.yaml │ ├── ios_workflow.yaml │ ├── main.yaml │ ├── nps_repository_workflow.yaml │ ├── platform_close_workflow.yaml │ └── scorecards.yml ├── .gitignore ├── .vscode └── launch.json ├── LICENSE ├── README.md ├── flutter_nps ├── .gitignore ├── .metadata ├── .vscode │ └── extensions.json ├── README.md ├── analysis_options.yaml ├── coverage_badge.svg ├── l10n.yaml ├── lib │ ├── app │ │ ├── app.dart │ │ ├── route_generator.dart │ │ └── view │ │ │ └── app.dart │ ├── bootstrap.dart │ ├── capture │ │ ├── capture.dart │ │ ├── cubit │ │ │ ├── capture_cubit.dart │ │ │ └── capture_cubit_state.dart │ │ └── view │ │ │ ├── capture_end_page.dart │ │ │ └── capture_page.dart │ ├── gen │ │ └── assets.gen.dart │ ├── l10n │ │ ├── arb │ │ │ └── app_en.arb │ │ └── l10n.dart │ └── main.dart ├── packages │ ├── app_ui │ │ ├── .gitignore │ │ ├── README.md │ │ ├── analysis_options.yaml │ │ ├── assets │ │ │ └── icons │ │ │ │ ├── check-circle.png │ │ │ │ ├── loving-emoji.png │ │ │ │ └── thumb-down-emoji.png │ │ ├── lib │ │ │ ├── app_ui.dart │ │ │ └── src │ │ │ │ ├── colors │ │ │ │ └── colors.dart │ │ │ │ ├── generated │ │ │ │ └── assets.gen.dart │ │ │ │ ├── spacing │ │ │ │ ├── breakpoints.dart │ │ │ │ └── spacing.dart │ │ │ │ ├── theme │ │ │ │ └── app_theme.dart │ │ │ │ ├── typography │ │ │ │ └── text_styles.dart │ │ │ │ └── widgets │ │ │ │ ├── answer_chips.dart │ │ │ │ ├── app_close_button.dart │ │ │ │ ├── capture_score_selector.dart │ │ │ │ ├── capture_score_selector_labels.dart │ │ │ │ ├── chips_panel.dart │ │ │ │ ├── responsive_card.dart │ │ │ │ └── submit_button.dart │ │ ├── pubspec.yaml │ │ └── test │ │ │ ├── helpers │ │ │ ├── helpers.dart │ │ │ └── pump_app.dart │ │ │ ├── src │ │ │ └── widgets │ │ │ │ ├── answer_chips_test.dart │ │ │ │ ├── app_close_button_test.dart │ │ │ │ ├── capture_score_selector_labels_test.dart │ │ │ │ ├── capture_score_selector_test.dart │ │ │ │ ├── chips_panel_test.dart │ │ │ │ ├── responsive_card_test.dart │ │ │ │ └── submit_button_test.dart │ │ │ └── theme │ │ │ └── app_theme_test.dart │ ├── nps_repository │ │ ├── .gitignore │ │ ├── README.md │ │ ├── analysis_options.yaml │ │ ├── lib │ │ │ ├── nps_repository.dart │ │ │ └── src │ │ │ │ ├── nps_repository.dart │ │ │ │ └── score_submit_model.dart │ │ ├── pubspec.yaml │ │ └── test │ │ │ └── src │ │ │ ├── nps_repository_test.dart │ │ │ └── score_submit_model_test.dart │ └── platform_close │ │ ├── .gitignore │ │ ├── .metadata │ │ ├── README.md │ │ ├── analysis_options.yaml │ │ ├── lib │ │ ├── mobile_close.dart │ │ ├── platform_close.dart │ │ ├── platform_close_stub.dart │ │ └── web_close.dart │ │ ├── pubspec.yaml │ │ └── test │ │ ├── mobile_close_test.dart │ │ └── platform_close_test.dart ├── pubspec.yaml └── test │ ├── app │ ├── route_generator_test.dart │ └── view │ │ └── app_test.dart │ ├── capture │ ├── cubit │ │ ├── capture_cubit_test.dart │ │ └── capture_state_test.dart │ └── view │ │ ├── capture_end_page_test.dart │ │ └── capture_page_test.dart │ ├── gen │ └── assets.gen_test.dart │ └── helpers │ ├── helpers.dart │ └── pump_app.dart ├── newsfeed_android ├── .gitignore ├── README.md ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── newsfeed_android │ │ │ └── MainActivityTest.kt │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── newsfeed_android │ │ │ │ ├── MainActivity.kt │ │ │ │ └── RecyclerViewAdapter.kt │ │ └── res │ │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── drawable │ │ │ └── ic_launcher_background.xml │ │ │ ├── layout │ │ │ ├── activity_main.xml │ │ │ ├── item_loading.xml │ │ │ └── item_row.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-mdpi │ │ │ ├── dot.png │ │ │ ├── ic_launcher.webp │ │ │ ├── ic_launcher_round.webp │ │ │ ├── placeholder_image.png │ │ │ ├── placeholder_image2.png │ │ │ └── placeholder_image3.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ │ ├── values-night │ │ │ └── themes.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── themes.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── newsfeed_android │ │ └── RecyclerViewAdapterTest.kt ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── newsfeed_angular ├── .browserslistrc ├── .editorconfig ├── .eslintrc.json ├── .gitignore ├── .prettierrc ├── .vscode │ └── extensions.json ├── README.md ├── angular.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── endless-scroll-view │ │ │ ├── endless-scroll-view.component.css │ │ │ ├── endless-scroll-view.component.html │ │ │ ├── endless-scroll-view.component.spec.ts │ │ │ └── endless-scroll-view.component.ts │ │ ├── news-tile │ │ │ ├── news-tile.component.css │ │ │ ├── news-tile.component.html │ │ │ ├── news-tile.component.spec.ts │ │ │ └── news-tile.component.ts │ │ └── shared │ │ │ └── news │ │ │ ├── news.service.spec.ts │ │ │ └── news.service.ts │ ├── assets │ │ ├── .gitkeep │ │ ├── templateImage0.png │ │ ├── templateImage1.png │ │ ├── templateImage2.png │ │ ├── templateImage3.png │ │ └── templateImage4.png │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json └── tsconfig.spec.json └── newsfeed_ios ├── .gitignore ├── Podfile ├── README.md ├── newsfeedApp ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── TemplateImage.imageset │ │ ├── Contents.json │ │ └── Rectangle 474.png │ ├── TemplateImage2.imageset │ │ ├── Contents.json │ │ └── unsplash_MxVkWPiJALs (1).png │ └── TemplateImage3.imageset │ │ ├── Contents.json │ │ └── unsplash_Tk9m_HP4rgQ.png ├── ContentDataSource.swift ├── ContentView.swift ├── EndlessList.swift ├── NewsfeedApp.swift ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json ├── RowItem.swift └── en.lproj │ └── Localizable.strings ├── newsfeedAppTests └── ContentDataSourceTests.swift ├── newsfeedAppUITests ├── NewsfeedAppUITests.swift └── NewsfeedAppUITestsLaunchTests.swift ├── newsfeed_app.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── janstepien.xcuserdatad │ │ └── UserInterfaceState.xcuserstate ├── xcshareddata │ └── xcschemes │ │ ├── newsfeed_app.xcscheme │ │ ├── newsfeed_appTests.xcscheme │ │ └── newsfeed_appUITests.xcscheme └── xcuserdata │ └── janstepien.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist └── newsfeed_app.xcworkspace ├── contents.xcworkspacedata ├── xcshareddata └── IDEWorkspaceChecks.plist └── xcuserdata └── janstepien.xcuserdatad ├── UserInterfaceState.xcuserstate └── xcdebugger └── Breakpoints_v2.xcbkptlist /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 8 | 9 | ## Description 10 | 11 | 12 | 13 | ## Type of Change 14 | 15 | 16 | 17 | - [ ] ✨ New feature (non-breaking change which adds functionality) 18 | - [ ] 🛠️ Bug fix (non-breaking change which fixes an issue) 19 | - [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change) 20 | - [ ] 🧹 Code refactor 21 | - [ ] ✅ Build configuration change 22 | - [ ] 📝 Documentation 23 | - [ ] 🗑️ Chore 24 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # See Dependabot documentation for all configuration options: 2 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 3 | 4 | version: 2 5 | enable-beta-ecosystems: true 6 | updates: 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | interval: "daily" 11 | - package-ecosystem: "pub" 12 | directory: "flutter_nps" 13 | schedule: 14 | interval: "daily" 15 | - package-ecosystem: "pub" 16 | directory: "flutter_nps/packages/app_ui" 17 | schedule: 18 | interval: "daily" 19 | - package-ecosystem: "pub" 20 | directory: "flutter_nps/packages/nps_repository" 21 | schedule: 22 | interval: "daily" 23 | - package-ecosystem: "pub" 24 | directory: "flutter_nps/packages/platform_close" 25 | schedule: 26 | interval: "daily" 27 | -------------------------------------------------------------------------------- /.github/workflows/android_workflow.yaml: -------------------------------------------------------------------------------- 1 | name: Android CI 2 | 3 | concurrency: 4 | group: ${{ github.workflow }}-${{ github.ref }} 5 | cancel-in-progress: true 6 | 7 | on: 8 | pull_request: 9 | paths: 10 | - .github/workflows/android_workflow.yaml 11 | - newsfeed_android/** 12 | 13 | # Declare default permissions as read only. 14 | permissions: read-all 15 | 16 | defaults: 17 | run: 18 | working-directory: ./newsfeed_android 19 | jobs: 20 | build: 21 | strategy: 22 | matrix: 23 | platform: [ubuntu-latest, macos-latest] 24 | runs-on: ${{ matrix.platform }} 25 | name: build / ${{ matrix.platform }} 26 | steps: 27 | - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 28 | - uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225 29 | with: 30 | channel: "stable" 31 | - run: flutter --version 32 | 33 | - name: Build Flutter AAR file 34 | working-directory: flutter_nps 35 | run: flutter build aar 36 | 37 | - name: Set up JDK 38 | uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 39 | with: 40 | distribution: "zulu" 41 | java-version: "17" 42 | 43 | - name: Change wrapper permissions 44 | working-directory: ./newsfeed_android 45 | run: chmod +x ./gradlew 46 | 47 | - name: Android linter 48 | run: ./gradlew lint 49 | continue-on-error: false 50 | 51 | - name: Run Checkstyle 52 | uses: dbelyaev/action-checkstyle@af53a52e61fa3e06b71a84aa4448491a4e066b1c 53 | if: matrix.platform == 'ubuntu-latest' 54 | with: 55 | github_token: ${{ secrets.github_token }} 56 | 57 | - name: Build with Gradle 58 | run: ./gradlew build 59 | 60 | - name: Run Android Unit Test 61 | run: ./gradlew testDebugUnitTest 62 | 63 | - name: Run Android Instrumented tests 64 | if: matrix.platform == 'macos-latest' 65 | uses: reactivecircus/android-emulator-runner@99a4aac18b4df9b3af66c4a1f04c1f23fa10c270 66 | with: 67 | working-directory: ./newsfeed_android 68 | api-level: 29 69 | script: ./gradlew connectedCheck 70 | -------------------------------------------------------------------------------- /.github/workflows/angular_workflow.yaml: -------------------------------------------------------------------------------- 1 | name: Angular CI 2 | 3 | concurrency: 4 | group: ${{ github.workflow }}-${{ github.ref }} 5 | cancel-in-progress: true 6 | 7 | on: 8 | pull_request: 9 | paths: 10 | - .github/workflows/angular_workflow.yaml 11 | - newsfeed_angular/** 12 | 13 | # Declare default permissions as read only. 14 | permissions: read-all 15 | 16 | defaults: 17 | run: 18 | working-directory: ./newsfeed_angular 19 | jobs: 20 | build: 21 | runs-on: ubuntu-latest 22 | name: "build" 23 | steps: 24 | - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 25 | - uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225 26 | with: 27 | channel: "stable" 28 | - run: flutter --version 29 | 30 | - name: Use Node.js 16.x 31 | uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 32 | with: 33 | node-version: 16.x 34 | 35 | - name: Install dependencies 36 | run: npm ci 37 | 38 | - name: Run format check 39 | run: npm run format:check 40 | 41 | - name: Run lint 42 | run: npm run lint 43 | 44 | - name: Build 45 | run: npm run build:ci 46 | 47 | - name: Test 48 | run: npm run test:ci 49 | -------------------------------------------------------------------------------- /.github/workflows/app_ui_workflow.yaml: -------------------------------------------------------------------------------- 1 | name: app_ui 2 | 3 | concurrency: 4 | group: ${{ github.workflow }}-${{ github.ref }} 5 | cancel-in-progress: true 6 | 7 | on: 8 | pull_request: 9 | paths: 10 | - .github/workflows/app_ui_workflow.yaml 11 | - flutter_nps/packages/app_ui/** 12 | 13 | # Declare default permissions as read only. 14 | permissions: read-all 15 | 16 | jobs: 17 | build: 18 | name: build 19 | uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 20 | with: 21 | working_directory: "flutter_nps/packages/app_ui" 22 | coverage_excludes: "*.g.dart lib/src/generated/*.gen.dart" 23 | flutter_channel: stable 24 | -------------------------------------------------------------------------------- /.github/workflows/archive_workflow.yaml: -------------------------------------------------------------------------------- 1 | name: Archive 2 | 3 | concurrency: 4 | group: ${{ github.workflow }}-${{ github.ref }} 5 | cancel-in-progress: true 6 | 7 | on: 8 | push: 9 | branches: 10 | - main 11 | 12 | # Declare default permissions as read only. 13 | permissions: read-all 14 | 15 | jobs: 16 | build: 17 | runs-on: macos-latest 18 | name: build 19 | steps: 20 | - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 21 | - uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225 22 | with: 23 | channel: "stable" 24 | - run: flutter --version 25 | 26 | - name: Set up JDK 27 | uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 28 | with: 29 | distribution: "zulu" 30 | java-version: "17" 31 | 32 | - name: Build Flutter AAR file 33 | working-directory: flutter_nps 34 | run: flutter build aar 35 | 36 | - name: Create Flutter AAR artifact 37 | uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 38 | with: 39 | name: flutter-aar 40 | path: flutter_nps/build/host/outputs/repo 41 | 42 | - name: Convert module to app for web 43 | working-directory: flutter_nps 44 | run: | 45 | perl -i -pe's/module/app/g' .metadata 46 | flutter create . --platforms web --org com.example.flutter_nps 47 | rm test/widget_test.dart 48 | flutter build web 49 | perl -i -pe's/ swift-format.rb 51 | brew install swift-format.rb 52 | 53 | - name: Swift lint 54 | run: swift format lint -r . 55 | 56 | - name: Swift format 57 | run: swift format -r . 58 | 59 | - name: Run unit tests 60 | run: xcodebuild test -scheme newsfeed_appTests -workspace newsfeed_app.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 11,OS=15.2' | xcpretty && exit ${PIPESTATUS[0]} 61 | 62 | - name: Run UI tests 63 | run: xcodebuild test -scheme newsfeed_appUITests -workspace newsfeed_app.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 11,OS=15.2' | xcpretty && exit ${PIPESTATUS[0]} 64 | -------------------------------------------------------------------------------- /.github/workflows/main.yaml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | concurrency: 4 | group: ${{ github.workflow }}-${{ github.ref }} 5 | cancel-in-progress: true 6 | 7 | on: 8 | pull_request: 9 | branches: 10 | - main 11 | 12 | # Declare default permissions as read only. 13 | permissions: read-all 14 | 15 | jobs: 16 | build: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: noop 20 | run: echo 'noop' 21 | -------------------------------------------------------------------------------- /.github/workflows/nps_repository_workflow.yaml: -------------------------------------------------------------------------------- 1 | name: nps_repository 2 | 3 | concurrency: 4 | group: ${{ github.workflow }}-${{ github.ref }} 5 | cancel-in-progress: true 6 | 7 | on: 8 | pull_request: 9 | paths: 10 | - .github/workflows/nps_repository_workflow.yaml 11 | - flutter_nps/packages/nps_repository/** 12 | 13 | # Declare default permissions as read only. 14 | permissions: read-all 15 | 16 | jobs: 17 | build: 18 | name: build 19 | uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 20 | with: 21 | working_directory: "flutter_nps/packages/nps_repository" 22 | coverage_excludes: "*.g.dart lib/src/gen/*.gen.dart" 23 | flutter_channel: stable 24 | -------------------------------------------------------------------------------- /.github/workflows/platform_close_workflow.yaml: -------------------------------------------------------------------------------- 1 | name: platform_close 2 | 3 | concurrency: 4 | group: ${{ github.workflow }}-${{ github.ref }} 5 | cancel-in-progress: true 6 | 7 | on: 8 | pull_request: 9 | paths: 10 | - .github/workflows/platform_close_workflow.yaml 11 | - flutter_nps/packages/platform_close/** 12 | 13 | # Declare default permissions as read only. 14 | permissions: read-all 15 | 16 | jobs: 17 | build: 18 | name: build 19 | uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 20 | with: 21 | working_directory: "flutter_nps/packages/platform_close" 22 | coverage_excludes: "*.g.dart lib/gen/*.gen.dart" 23 | flutter_channel: stable 24 | -------------------------------------------------------------------------------- /.github/workflows/scorecards.yml: -------------------------------------------------------------------------------- 1 | name: Scorecards supply-chain security 2 | on: 3 | # Only the default branch is supported. 4 | branch_protection_rule: 5 | push: 6 | branches: [ main ] 7 | 8 | # Declare default permissions as read only. 9 | permissions: read-all 10 | 11 | jobs: 12 | analysis: 13 | name: Scorecards analysis 14 | runs-on: ubuntu-latest 15 | permissions: 16 | # Needed to upload the results to code-scanning dashboard. 17 | security-events: write 18 | # Used to receive a badge 19 | id-token: write 20 | actions: read 21 | contents: read 22 | 23 | steps: 24 | - name: "Checkout code" 25 | uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 26 | with: 27 | persist-credentials: false 28 | 29 | - name: "Run analysis" 30 | uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 31 | with: 32 | results_file: results.sarif 33 | results_format: sarif 34 | # (Optional) Read-only PAT token. Uncomment the `repo_token` line below if: 35 | # - you want to enable the Branch-Protection check on a *public* repository, or 36 | # - you are installing Scorecards on a *private* repository 37 | # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. 38 | repo_token: ${{ secrets.SCORECARD_READ_TOKEN }} 39 | 40 | # Publish the results for public repositories to enable scorecard badges. For more details, see 41 | # https://github.com/ossf/scorecard-action#publishing-results. 42 | # For private repositories, `publish_results` will automatically be set to `false`, regardless 43 | # of the value entered here. 44 | publish_results: true 45 | 46 | # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF 47 | # format to the repository Actions tab. 48 | - name: "Upload artifact" 49 | uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 50 | with: 51 | name: SARIF file 52 | path: results.sarif 53 | retention-days: 5 54 | 55 | # Upload the results to GitHub's code scanning dashboard. 56 | - name: "Upload to code-scanning" 57 | uses: github/codeql-action/upload-sarif@cdcdbb579706841c47f7063dda365e292e5cad7a 58 | with: 59 | sarif_file: results.sarif 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | yarn-error.log 34 | testem.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | 41 | # Coverage result 42 | coverage 43 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "flutter_nps", 9 | "cwd": "flutter_nps", 10 | "request": "launch", 11 | "type": "dart" 12 | }, 13 | { 14 | "name": "flutter_nps (profile mode)", 15 | "cwd": "flutter_nps", 16 | "request": "launch", 17 | "type": "dart", 18 | "flutterMode": "profile" 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2022 The Flutter Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of Google Inc. nor the names of its 13 | contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /flutter_nps/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | .idea/ 8 | .vagrant/ 9 | .sconsign.dblite 10 | .svn/ 11 | 12 | migrate_working_dir/ 13 | 14 | *.swp 15 | profile 16 | 17 | DerivedData/ 18 | 19 | .generated/ 20 | 21 | *.pbxuser 22 | *.mode1v3 23 | *.mode2v3 24 | *.perspectivev3 25 | 26 | !default.pbxuser 27 | !default.mode1v3 28 | !default.mode2v3 29 | !default.perspectivev3 30 | 31 | xcuserdata 32 | 33 | *.moved-aside 34 | 35 | *.pyc 36 | *sync/ 37 | Icon? 38 | .tags* 39 | 40 | build/ 41 | .android/ 42 | .ios/ 43 | .flutter-plugins 44 | .flutter-plugins-dependencies 45 | 46 | # Symbolication related 47 | app.*.symbols 48 | 49 | # Obfuscation related 50 | app.*.map.json 51 | -------------------------------------------------------------------------------- /flutter_nps/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 77d935af4db863f6abd0b9c31c7e6df2a13de57b 8 | channel: stable 9 | 10 | project_type: module 11 | -------------------------------------------------------------------------------- /flutter_nps/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dart-code.dart-code", 6 | "dart-code.flutter", 7 | "felixangelov.bloc" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /flutter_nps/README.md: -------------------------------------------------------------------------------- 1 | # Flutter NPS module 2 | 3 | ![coverage][coverage_badge] 4 | 5 | Put Flutter to Work NPS (Net Promoter Score) module 6 | 7 | --- 8 | 9 | ## Introduction 10 | 11 | This Flutter module consists of a pop-up that allows customer to provide a satisfaction score. It can be run as a standalone application; however, its main purpose is to be embedded within existing native applications as a module. 12 | 13 | Each native application uses a different system to embed a Flutter module. Follow links for a specific instruction: 14 | 15 | - [Android](https://github.com/VGVentures/take-flutter-home/tree/main/newsfeed_android/README.md) 16 | - [iOS](https://github.com/VGVentures/take-flutter-home/tree/main/newsfeed_ios/README.md) 17 | - [Web](https://github.com/VGVentures/take-flutter-home/tree/main/newsfeed_angular/README.md). 18 | For more information on integrating Flutter modules to your existing applications, see the [add-to-app documentation](https://flutter.dev/docs/development/add-to-app). 19 | 20 | # Flutter improvements 21 | 22 | Feel free to fork and customize this repository. Below is a list of guidelines on usage of the tools that are already used in this project. 23 | 24 | ### Running Tests 🧪 25 | 26 | To run all unit and widget tests use the following command: 27 | 28 | ```sh 29 | flutter test --coverage --test-randomize-ordering-seed random 30 | ``` 31 | 32 | To view the generated coverage report you can use [lcov](https://github.com/linux-test-project/lcov). 33 | 34 | ```sh 35 | # Generate Coverage Report 36 | genhtml coverage/lcov.info -o coverage/ 37 | 38 | # Open Coverage Report 39 | open coverage/index.html 40 | ``` 41 | 42 | ### Using flutter_gen 43 | 44 | To generate all the assets accessors of pubspec.yaml file run: 45 | 46 | ```sh 47 | fluttergen -c pubspec.yaml 48 | ``` 49 | 50 | For more information how to use Flutter_gen visit [Flutter_gen](https://pub.dev/packages/flutter_gen) 51 | 52 | ### Working with Translations 🌐 53 | 54 | This project relies on [flutter_localizations][flutter_localizations_link] and follows the [official internationalization guide for Flutter][internationalization_link]. 55 | 56 | ### Adding Strings 57 | 58 | 1. To add a new localizable string, open the `app_en.arb` file at `lib/l10n/arb/app_en.arb`. 59 | 60 | ```arb 61 | { 62 | "@@locale": "en", 63 | "counterAppBarTitle": "Counter", 64 | "@counterAppBarTitle": { 65 | "description": "Text shown in the AppBar of the Counter Page" 66 | } 67 | } 68 | ``` 69 | 70 | 2. Then add a new key/value and description 71 | 72 | ```arb 73 | { 74 | "@@locale": "en", 75 | "counterAppBarTitle": "Counter", 76 | "@counterAppBarTitle": { 77 | "description": "Text shown in the AppBar of the Counter Page" 78 | }, 79 | "helloWorld": "Hello World", 80 | "@helloWorld": { 81 | "description": "Hello World Text" 82 | } 83 | } 84 | ``` 85 | 86 | 3. Use the new string 87 | 88 | ```dart 89 | import 'package:project/l10n/l10n.dart'; 90 | 91 | @override 92 | Widget build(BuildContext context) { 93 | final l10n = context.l10n; 94 | return Text(l10n.helloWorld); 95 | } 96 | ``` 97 | 98 | ### Adding Supported Locales 99 | 100 | Update the `CFBundleLocalizations` array in the `Info.plist` at `ios/Runner/Info.plist` to include the new locale. 101 | 102 | ```xml 103 | ... 104 | 105 | CFBundleLocalizations 106 | 107 | en 108 | es 109 | 110 | 111 | ... 112 | ``` 113 | 114 | ### Adding Translations 115 | 116 | 1. For each supported locale, add a new ARB file in `lib/l10n/arb`. 117 | 118 | ``` 119 | ├── l10n 120 | │ ├── arb 121 | │ │ ├── app_en.arb 122 | │ │ └── app_es.arb 123 | ``` 124 | 125 | 2. Add the translated strings to each `.arb` file: 126 | 127 | `app_en.arb` 128 | 129 | ```arb 130 | { 131 | "@@locale": "en", 132 | "counterAppBarTitle": "Counter", 133 | "@counterAppBarTitle": { 134 | "description": "Text shown in the AppBar of the Counter Page" 135 | } 136 | } 137 | ``` 138 | 139 | `app_es.arb` 140 | 141 | ```arb 142 | { 143 | "@@locale": "es", 144 | "counterAppBarTitle": "Contador", 145 | "@counterAppBarTitle": { 146 | "description": "Texto mostrado en la AppBar de la página del contador" 147 | } 148 | } 149 | ``` 150 | 151 | [coverage_badge]: coverage_badge.svg 152 | [flutter_localizations_link]: https://api.flutter.dev/flutter/flutter_localizations/flutter_localizations-library.html 153 | [internationalization_link]: https://flutter.dev/docs/development/accessibility-and-localization/internationalization 154 | [license_badge]: https://img.shields.io/badge/license-MIT-blue.svg 155 | [license_link]: https://opensource.org/licenses/MIT 156 | -------------------------------------------------------------------------------- /flutter_nps/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | 3 | analyzer: 4 | language: 5 | strict-casts: true 6 | strict-inference: true 7 | 8 | errors: 9 | missing_required_param: error 10 | missing_return: error 11 | 12 | exclude: 13 | - test/.test_coverage.dart 14 | - lib/generated_plugin_registrant.dart 15 | - lib/gen/assets.gen.dart 16 | 17 | # Additional information about this file can be found at 18 | # https://dart.dev/guides/language/analysis-options 19 | -------------------------------------------------------------------------------- /flutter_nps/coverage_badge.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | coverage 16 | coverage 17 | 100% 18 | 100% 19 | 20 | -------------------------------------------------------------------------------- /flutter_nps/l10n.yaml: -------------------------------------------------------------------------------- 1 | arb-dir: lib/l10n/arb 2 | template-arb-file: app_en.arb 3 | output-localization-file: app_localizations.dart 4 | nullable-getter: false 5 | -------------------------------------------------------------------------------- /flutter_nps/lib/app/app.dart: -------------------------------------------------------------------------------- 1 | export 'view/app.dart'; 2 | -------------------------------------------------------------------------------- /flutter_nps/lib/app/route_generator.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_nps/capture/view/capture_end_page.dart'; 3 | import 'package:flutter_nps/capture/view/capture_page.dart'; 4 | 5 | class RouteGenerator { 6 | static Route generateRoute(RouteSettings settings) { 7 | switch (settings.name) { 8 | case CapturePage.routeName: 9 | return PageRouteBuilder( 10 | pageBuilder: (_, __, ___) => const CapturePage(), 11 | transitionsBuilder: buildTransitionBuilder, 12 | ); 13 | case CaptureEndPage.routeName: 14 | return PageRouteBuilder( 15 | pageBuilder: (_, __, ___) => const CaptureEndPage(), 16 | transitionsBuilder: buildTransitionBuilder, 17 | ); 18 | default: 19 | return PageRouteBuilder( 20 | pageBuilder: (_, __, ___) => Scaffold( 21 | body: Center( 22 | child: Text( 23 | 'No route defined for ${settings.name}', 24 | ), 25 | ), 26 | ), 27 | transitionsBuilder: buildTransitionBuilder, 28 | ); 29 | } 30 | } 31 | 32 | static Widget buildTransitionBuilder( 33 | BuildContext context, 34 | Animation animation, 35 | Animation secondaryAnimation, 36 | Widget child, 37 | ) { 38 | return SlideTransition( 39 | position: Tween( 40 | begin: const Offset(0, 1), 41 | end: Offset.zero, 42 | ).animate(animation), 43 | child: child, 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /flutter_nps/lib/app/view/app.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_localizations/flutter_localizations.dart'; 4 | import 'package:flutter_nps/app/route_generator.dart'; 5 | import 'package:flutter_nps/capture/capture.dart'; 6 | import 'package:flutter_nps/l10n/l10n.dart'; 7 | 8 | class App extends StatelessWidget { 9 | const App({Key? key}) : super(key: key); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return MaterialApp( 14 | theme: AppTheme().theme, 15 | initialRoute: CapturePage.routeName, 16 | debugShowCheckedModeBanner: false, 17 | onGenerateRoute: RouteGenerator.generateRoute, 18 | home: const Scaffold( 19 | body: CapturePage(), 20 | ), 21 | localizationsDelegates: const [ 22 | AppLocalizations.delegate, 23 | GlobalMaterialLocalizations.delegate, 24 | GlobalWidgetsLocalizations.delegate, 25 | GlobalCupertinoLocalizations.delegate, 26 | ], 27 | supportedLocales: AppLocalizations.supportedLocales, 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /flutter_nps/lib/bootstrap.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:developer'; 3 | 4 | import 'package:bloc/bloc.dart'; 5 | import 'package:flutter/widgets.dart'; 6 | 7 | class AppBlocObserver extends BlocObserver { 8 | @override 9 | void onChange(BlocBase bloc, Change change) { 10 | super.onChange(bloc, change); 11 | log('onChange(${bloc.runtimeType}, $change)'); 12 | } 13 | 14 | @override 15 | void onError(BlocBase bloc, Object error, StackTrace stackTrace) { 16 | log('onError(${bloc.runtimeType}, $error, $stackTrace)'); 17 | super.onError(bloc, error, stackTrace); 18 | } 19 | } 20 | 21 | Future bootstrap(FutureOr Function() builder) async { 22 | FlutterError.onError = (details) { 23 | log(details.exceptionAsString(), stackTrace: details.stack); 24 | }; 25 | 26 | Bloc.observer = AppBlocObserver(); 27 | 28 | await runZonedGuarded( 29 | () async { 30 | runApp(await builder()); 31 | }, 32 | (error, stackTrace) => log(error.toString(), stackTrace: stackTrace), 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /flutter_nps/lib/capture/capture.dart: -------------------------------------------------------------------------------- 1 | export 'cubit/capture_cubit.dart'; 2 | export 'cubit/capture_cubit_state.dart'; 3 | export 'view/capture_end_page.dart'; 4 | export 'view/capture_page.dart'; 5 | -------------------------------------------------------------------------------- /flutter_nps/lib/capture/cubit/capture_cubit.dart: -------------------------------------------------------------------------------- 1 | import 'package:bloc/bloc.dart'; 2 | import 'package:flutter_nps/capture/capture.dart'; 3 | import 'package:nps_repository/nps_repository.dart'; 4 | 5 | class CaptureCubit extends Cubit { 6 | CaptureCubit({required NpsRepository npsRepository}) 7 | : _npsRepository = npsRepository, 8 | super(CaptureCubitState.initial()); 9 | 10 | final NpsRepository _npsRepository; 11 | 12 | void selectScore({required int score}) => emit(state.copyWith(score: score)); 13 | 14 | void chipToggled({required int index}) { 15 | state.chipIndexes.contains(index) 16 | ? _removeChipIndex(index: index) 17 | : _addChipIndex(index: index); 18 | } 19 | 20 | void _addChipIndex({required int index}) => 21 | emit(state.copyWith(chipIndexes: [...state.chipIndexes, index])); 22 | 23 | void _removeChipIndex({required int index}) => emit( 24 | state.copyWith( 25 | chipIndexes: [...state.chipIndexes.where((item) => item != index)], 26 | ), 27 | ); 28 | 29 | Future submitResult() async { 30 | await _npsRepository.sendCustomerSatisfaction( 31 | scoreSubmit: CustomerSatisfaction( 32 | score: state.score, 33 | chipIndexes: state.chipIndexes, 34 | ), 35 | ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /flutter_nps/lib/capture/cubit/capture_cubit_state.dart: -------------------------------------------------------------------------------- 1 | import 'package:equatable/equatable.dart'; 2 | 3 | class CaptureCubitState extends Equatable { 4 | const CaptureCubitState({ 5 | required this.score, 6 | required this.chipIndexes, 7 | this.maxScore = 5, 8 | }); 9 | 10 | factory CaptureCubitState.initial() => 11 | const CaptureCubitState(score: -1, chipIndexes: []); 12 | 13 | final int score; 14 | final List chipIndexes; 15 | final int maxScore; 16 | 17 | CaptureCubitState copyWith({int? score, List? chipIndexes}) => 18 | CaptureCubitState( 19 | score: score ?? this.score, 20 | chipIndexes: chipIndexes ?? this.chipIndexes, 21 | maxScore: maxScore, 22 | ); 23 | 24 | @override 25 | List get props => [score, chipIndexes, maxScore]; 26 | } 27 | -------------------------------------------------------------------------------- /flutter_nps/lib/capture/view/capture_end_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_nps/l10n/l10n.dart'; 4 | import 'package:platform_close/platform_close.dart'; 5 | 6 | class CaptureEndPage extends StatelessWidget { 7 | const CaptureEndPage({Key? key}) : super(key: key); 8 | 9 | static const routeName = '/end'; 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return const ResponsiveCard( 14 | child: CaptureEndView(), 15 | ); 16 | } 17 | } 18 | 19 | class CaptureEndView extends StatelessWidget { 20 | const CaptureEndView({Key? key}) : super(key: key); 21 | 22 | @override 23 | Widget build(BuildContext context) { 24 | return Stack( 25 | alignment: Alignment.center, 26 | children: [ 27 | Column( 28 | mainAxisAlignment: MainAxisAlignment.center, 29 | children: [ 30 | const SizedBox(height: Spacing.huge), 31 | Assets.icons.checkCircle.image(), 32 | const SizedBox(height: Spacing.xl), 33 | Text( 34 | context.l10n.thankYou, 35 | style: Theme.of(context).textTheme.headlineSmall, 36 | ), 37 | Text( 38 | context.l10n.feedbackSubmittedMessage, 39 | style: Theme.of(context).textTheme.titleMedium, 40 | ), 41 | const SizedBox(height: Spacing.xxhuge), 42 | ], 43 | ), 44 | Positioned( 45 | top: Spacing.xl, 46 | right: Spacing.s, 47 | child: IconButton( 48 | onPressed: PlatformClose.instance.close, 49 | icon: const Icon(Icons.close), 50 | ), 51 | ), 52 | ], 53 | ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /flutter_nps/lib/gen/assets.gen.dart: -------------------------------------------------------------------------------- 1 | /// GENERATED CODE - DO NOT MODIFY BY HAND 2 | /// ***************************************************** 3 | /// FlutterGen 4 | /// ***************************************************** 5 | 6 | // ignore_for_file: directives_ordering,unnecessary_import 7 | 8 | import 'package:flutter/widgets.dart'; 9 | 10 | class $AssetsIconsGen { 11 | const $AssetsIconsGen(); 12 | 13 | /// File path: assets/icons/check-circle.png 14 | AssetGenImage get checkCircle => const AssetGenImage( 15 | 'assets/icons/check-circle.png', 16 | ); 17 | 18 | /// File path: assets/icons/loving-emoji.png 19 | AssetGenImage get lovingEmoji => 20 | const AssetGenImage('assets/icons/loving-emoji.png'); 21 | 22 | /// File path: assets/icons/thumb-down-emoji.png 23 | AssetGenImage get thumbDownEmoji => 24 | const AssetGenImage('assets/icons/thumb-down-emoji.png'); 25 | } 26 | 27 | class Assets { 28 | Assets._(); 29 | 30 | static const $AssetsIconsGen icons = $AssetsIconsGen(); 31 | } 32 | 33 | class AssetGenImage extends AssetImage { 34 | const AssetGenImage(String assetName) : super(assetName); 35 | 36 | Image image({ 37 | Key? key, 38 | ImageFrameBuilder? frameBuilder, 39 | ImageLoadingBuilder? loadingBuilder, 40 | ImageErrorWidgetBuilder? errorBuilder, 41 | String? semanticLabel, 42 | bool excludeFromSemantics = false, 43 | double? width, 44 | double? height, 45 | Color? color, 46 | BlendMode? colorBlendMode, 47 | BoxFit? fit, 48 | AlignmentGeometry alignment = Alignment.center, 49 | ImageRepeat repeat = ImageRepeat.noRepeat, 50 | Rect? centerSlice, 51 | bool matchTextDirection = false, 52 | bool gaplessPlayback = false, 53 | bool isAntiAlias = false, 54 | FilterQuality filterQuality = FilterQuality.low, 55 | }) { 56 | return Image( 57 | key: key, 58 | image: this, 59 | frameBuilder: frameBuilder, 60 | loadingBuilder: loadingBuilder, 61 | errorBuilder: errorBuilder, 62 | semanticLabel: semanticLabel, 63 | excludeFromSemantics: excludeFromSemantics, 64 | width: width, 65 | height: height, 66 | color: color, 67 | colorBlendMode: colorBlendMode, 68 | fit: fit, 69 | alignment: alignment, 70 | repeat: repeat, 71 | centerSlice: centerSlice, 72 | matchTextDirection: matchTextDirection, 73 | gaplessPlayback: gaplessPlayback, 74 | isAntiAlias: isAntiAlias, 75 | filterQuality: filterQuality, 76 | ); 77 | } 78 | 79 | String get path => assetName; 80 | } 81 | -------------------------------------------------------------------------------- /flutter_nps/lib/l10n/arb/app_en.arb: -------------------------------------------------------------------------------- 1 | { 2 | "@@locale": "en", 3 | "captureTitle": "How was your experience?", 4 | "@captureTitle": { 5 | "description": "Headline of Capture Page" 6 | }, 7 | "captureMessage": "Let us know by rating it.", 8 | "@captureMessage": { 9 | "description": "Message displayed under headline on Capture Page" 10 | }, 11 | "captureMinLabel": "Not a fan", 12 | "@captureMinLabel": { 13 | "description": "Label of lowest score on Capture Page" 14 | }, 15 | "captureMaxLabel": "Love it!", 16 | "@captureMaxLabel": { 17 | "description": "Label of highest score on Capture Page" 18 | }, 19 | "submit": "Submit", 20 | "@submit": { 21 | "description": "Text displayed on submit button on Capture Page" 22 | }, 23 | "thankYou": "Thank you!", 24 | "@thankYou": { 25 | "description": "Text saying thank you" 26 | }, 27 | "feedbackSubmittedMessage": "Your feedback has been submitted.", 28 | "@feedbackSubmittedMessage": { 29 | "description": "Message displayed on submit of feedback" 30 | }, 31 | "quickResponse": "Quick", 32 | "@quickResponse": { 33 | "description": "Quick chip" 34 | }, 35 | "greatUIResponse": "Great UI", 36 | "@greatUIResponse": { 37 | "description": "Great UI chip" 38 | }, 39 | "friendlyResponse": "Friendly", 40 | "@friendlyResponse": { 41 | "description": "Friendly chip" 42 | }, 43 | "funResponse": "Fun!", 44 | "@funResponse": { 45 | "description": "Fun chip" 46 | }, 47 | "responsiveResponse": "Responsive", 48 | "@responsiveResponse": { 49 | "description": "Responsive chip" 50 | }, 51 | "simpleResponse": "Simple", 52 | "@simpleResponse": { 53 | "description": "Simple chip" 54 | }, 55 | "bugFreeResponse": "Bug-Free", 56 | "@bugFreeResponse": { 57 | "description": "Bug-free chip" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /flutter_nps/lib/l10n/l10n.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | import 'package:flutter_gen/gen_l10n/app_localizations.dart'; 3 | 4 | export 'package:flutter_gen/gen_l10n/app_localizations.dart'; 5 | 6 | extension AppLocalizationsX on BuildContext { 7 | AppLocalizations get l10n => AppLocalizations.of(this); 8 | } 9 | -------------------------------------------------------------------------------- /flutter_nps/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_nps/app/app.dart'; 2 | import 'package:flutter_nps/bootstrap.dart'; 3 | 4 | void main() { 5 | bootstrap(() => const App()); 6 | } 7 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # VSCode related 19 | .vscode/ 20 | 21 | # Flutter/Dart/Pub related 22 | **/doc/api/ 23 | **/ios/Flutter/.last_build_id 24 | .dart_tool/ 25 | .flutter-plugins 26 | .flutter-plugins-dependencies 27 | .packages 28 | pubspec.lock 29 | .pub-cache/ 30 | .pub/ 31 | /build/ 32 | 33 | # Web related 34 | lib/generated_plugin_registrant.dart 35 | 36 | # Symbolication related 37 | app.*.symbols 38 | 39 | # Obfuscation related 40 | app.*.map.json 41 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/README.md: -------------------------------------------------------------------------------- 1 | # app_ui 2 | 3 | [![License: MIT][license_badge]][license_link] 4 | 5 | A UI Kit for the Flutter NPS module 6 | 7 | [license_badge]: https://img.shields.io/badge/license-MIT-blue.svg 8 | [license_link]: https://opensource.org/licenses/MIT 9 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | 3 | analyzer: 4 | language: 5 | strict-casts: true 6 | strict-inference: true 7 | 8 | errors: 9 | missing_required_param: error 10 | missing_return: error 11 | 12 | exclude: 13 | - test/.test_coverage.dart 14 | - lib/generated_plugin_registrant.dart 15 | - lib/generated/assets.gen.dart 16 | 17 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/assets/icons/check-circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/flutter_nps/packages/app_ui/assets/icons/check-circle.png -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/assets/icons/loving-emoji.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/flutter_nps/packages/app_ui/assets/icons/loving-emoji.png -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/assets/icons/thumb-down-emoji.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/flutter_nps/packages/app_ui/assets/icons/thumb-down-emoji.png -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/app_ui.dart: -------------------------------------------------------------------------------- 1 | library app_ui; 2 | 3 | export 'src/colors/colors.dart'; 4 | export 'src/generated/assets.gen.dart'; 5 | export 'src/spacing/breakpoints.dart'; 6 | export 'src/spacing/spacing.dart'; 7 | export 'src/theme/app_theme.dart'; 8 | export 'src/typography/text_styles.dart'; 9 | export 'src/widgets/answer_chips.dart'; 10 | export 'src/widgets/app_close_button.dart'; 11 | export 'src/widgets/capture_score_selector.dart'; 12 | export 'src/widgets/capture_score_selector_labels.dart'; 13 | export 'src/widgets/chips_panel.dart'; 14 | export 'src/widgets/responsive_card.dart'; 15 | export 'src/widgets/submit_button.dart'; 16 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/colors/colors.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | abstract class NpsColors { 4 | static const colorPrimary1 = Color(0xFF041E3C); 5 | static const colorBlueDash = Color(0xFF00529E); 6 | static const colorSecondary = Color(0xFF6200EE); 7 | static const colorGrey1 = Color(0xFF4A4A4A); 8 | static const colorGrey2 = Color(0xFF9FA2AF); 9 | static const colorGrey5 = Color(0xFFF8F9FA); 10 | static const colorWhite = Color(0xFFFFFFFF); 11 | static const transparent = Colors.transparent; 12 | } 13 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/generated/assets.gen.dart: -------------------------------------------------------------------------------- 1 | /// GENERATED CODE - DO NOT MODIFY BY HAND 2 | /// ***************************************************** 3 | /// FlutterGen 4 | /// ***************************************************** 5 | 6 | // ignore_for_file: directives_ordering,unnecessary_import 7 | 8 | import 'package:flutter/widgets.dart'; 9 | 10 | class $AssetsIconsGen { 11 | const $AssetsIconsGen(); 12 | 13 | /// File path: assets/icons/check-circle.png 14 | AssetGenImage get checkCircle => 15 | const AssetGenImage('assets/icons/check-circle.png'); 16 | 17 | /// File path: assets/icons/loving-emoji.png 18 | AssetGenImage get lovingEmoji => 19 | const AssetGenImage('assets/icons/loving-emoji.png'); 20 | 21 | /// File path: assets/icons/thumb-down-emoji.png 22 | AssetGenImage get thumbDownEmoji => 23 | const AssetGenImage('assets/icons/thumb-down-emoji.png'); 24 | } 25 | 26 | class Assets { 27 | Assets._(); 28 | 29 | static const $AssetsIconsGen icons = $AssetsIconsGen(); 30 | } 31 | 32 | class AssetGenImage extends AssetImage { 33 | const AssetGenImage(String assetName) : super(assetName, package: 'app_ui'); 34 | 35 | Image image({ 36 | Key? key, 37 | ImageFrameBuilder? frameBuilder, 38 | ImageLoadingBuilder? loadingBuilder, 39 | ImageErrorWidgetBuilder? errorBuilder, 40 | String? semanticLabel, 41 | bool excludeFromSemantics = false, 42 | double? width, 43 | double? height, 44 | Color? color, 45 | BlendMode? colorBlendMode, 46 | BoxFit? fit, 47 | AlignmentGeometry alignment = Alignment.center, 48 | ImageRepeat repeat = ImageRepeat.noRepeat, 49 | Rect? centerSlice, 50 | bool matchTextDirection = false, 51 | bool gaplessPlayback = false, 52 | bool isAntiAlias = false, 53 | FilterQuality filterQuality = FilterQuality.low, 54 | }) { 55 | return Image( 56 | key: key, 57 | image: this, 58 | frameBuilder: frameBuilder, 59 | loadingBuilder: loadingBuilder, 60 | errorBuilder: errorBuilder, 61 | semanticLabel: semanticLabel, 62 | excludeFromSemantics: excludeFromSemantics, 63 | width: width, 64 | height: height, 65 | color: color, 66 | colorBlendMode: colorBlendMode, 67 | fit: fit, 68 | alignment: alignment, 69 | repeat: repeat, 70 | centerSlice: centerSlice, 71 | matchTextDirection: matchTextDirection, 72 | gaplessPlayback: gaplessPlayback, 73 | isAntiAlias: isAntiAlias, 74 | filterQuality: filterQuality, 75 | ); 76 | } 77 | 78 | String get path => assetName; 79 | } 80 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/spacing/breakpoints.dart: -------------------------------------------------------------------------------- 1 | abstract class Breakpoints { 2 | static const double small = 511; 3 | static const double maxHeight = 558; 4 | } 5 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/spacing/spacing.dart: -------------------------------------------------------------------------------- 1 | abstract class Spacing { 2 | static const double xxs = 5; 3 | static const double xs = 10; 4 | static const double s = 15; 5 | static const double m = 25; 6 | static const double lg = 30; 7 | static const double xl = 35; 8 | static const double xxl = 40; 9 | static const double huge = 55; 10 | static const double xhuge = 60; 11 | static const double xxhuge = 75; 12 | } 13 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/theme/app_theme.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class AppTheme { 5 | ThemeData get theme => ThemeData( 6 | useMaterial3: true, 7 | colorScheme: ColorScheme.fromSwatch( 8 | accentColor: NpsColors.colorSecondary, 9 | backgroundColor: NpsColors.colorWhite, 10 | ), 11 | scaffoldBackgroundColor: NpsColors.colorWhite, 12 | elevatedButtonTheme: ElevatedButtonThemeData( 13 | style: ElevatedButton.styleFrom( 14 | backgroundColor: NpsColors.colorSecondary, 15 | foregroundColor: NpsColors.colorWhite, 16 | shape: RoundedRectangleBorder( 17 | borderRadius: BorderRadius.circular(24), 18 | ), 19 | ).copyWith( 20 | backgroundColor: MaterialStateProperty.resolveWith( 21 | (Set states) { 22 | if (!states.contains(MaterialState.disabled)) { 23 | return NpsColors.colorSecondary; 24 | } else if (states.contains(MaterialState.disabled)) { 25 | return NpsColors.colorWhite; 26 | } 27 | return null; 28 | }, 29 | ), 30 | ), 31 | ), 32 | textTheme: const TextTheme( 33 | headlineSmall: NpsStyles.headline5, 34 | titleMedium: NpsStyles.subtitle1, 35 | bodyMedium: NpsStyles.link, 36 | ), 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/typography/text_styles.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | abstract class NpsStyles { 4 | static const headline5 = TextStyle( 5 | fontFamily: 'Google Sans', 6 | fontWeight: FontWeight.w700, 7 | fontSize: 24, 8 | ); 9 | 10 | static const subtitle1 = TextStyle( 11 | fontFamily: 'Roboto', 12 | fontWeight: FontWeight.w400, 13 | fontSize: 18, 14 | ); 15 | 16 | static const link = TextStyle( 17 | fontFamily: 'Google Sans', 18 | fontWeight: FontWeight.w400, 19 | fontSize: 12, 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/widgets/answer_chips.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class AnswerChips extends StatelessWidget { 5 | const AnswerChips({ 6 | Key? key, 7 | required this.chips, 8 | required this.selectedChipIndices, 9 | required this.chipToggleCallback, 10 | }) : super(key: key); 11 | 12 | final List chips; 13 | final List selectedChipIndices; 14 | final void Function(int) chipToggleCallback; 15 | 16 | @override 17 | Widget build(BuildContext context) { 18 | return Wrap( 19 | runSpacing: 8, 20 | alignment: WrapAlignment.center, 21 | children: List>.generate( 22 | chips.length, 23 | (index) { 24 | final isSelected = selectedChipIndices.contains(index); 25 | return [ 26 | ActionChip( 27 | onPressed: () => chipToggleCallback(index), 28 | padding: const EdgeInsets.symmetric( 29 | horizontal: Spacing.s, 30 | vertical: Spacing.s, 31 | ), 32 | label: Text( 33 | chips[index], 34 | style: TextStyle( 35 | fontWeight: FontWeight.bold, 36 | color: isSelected 37 | ? NpsColors.colorWhite 38 | : NpsColors.colorPrimary1, 39 | ), 40 | ), 41 | backgroundColor: 42 | isSelected ? NpsColors.colorSecondary : NpsColors.colorGrey5, 43 | ), 44 | const SizedBox(width: 8), 45 | ]; 46 | }, 47 | ).reduce((value, element) => [...value, ...element]), 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/widgets/app_close_button.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class AppCloseButton extends StatelessWidget { 5 | const AppCloseButton({Key? key, required this.onPressed}) : super(key: key); 6 | 7 | final VoidCallback? onPressed; 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Padding( 12 | padding: const EdgeInsets.only( 13 | top: Spacing.xl, 14 | right: Spacing.s, 15 | ), 16 | child: Align( 17 | alignment: Alignment.topRight, 18 | child: IconButton( 19 | onPressed: onPressed, 20 | icon: const Icon(Icons.close), 21 | ), 22 | ), 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/widgets/capture_score_selector.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class CaptureScoreSelector extends StatelessWidget { 5 | const CaptureScoreSelector({ 6 | Key? key, 7 | required this.maxScore, 8 | required this.selectedIndex, 9 | required this.selectedCallback, 10 | }) : super(key: key); 11 | 12 | final int maxScore; 13 | final int selectedIndex; 14 | final void Function(int index) selectedCallback; 15 | 16 | @override 17 | Widget build(BuildContext context) { 18 | final theme = Theme.of(context); 19 | return SingleChildScrollView( 20 | scrollDirection: Axis.horizontal, 21 | child: Row( 22 | mainAxisAlignment: MainAxisAlignment.spaceBetween, 23 | children: List.generate( 24 | maxScore, 25 | (index) { 26 | return ScoreButton( 27 | index: index, 28 | isSelected: selectedIndex == index, 29 | selectedCallback: selectedCallback, 30 | theme: theme, 31 | ); 32 | }, 33 | ), 34 | ), 35 | ); 36 | } 37 | } 38 | 39 | class ScoreButton extends StatelessWidget { 40 | const ScoreButton({ 41 | Key? key, 42 | required this.index, 43 | required this.isSelected, 44 | required this.selectedCallback, 45 | required this.theme, 46 | }) : super(key: key); 47 | 48 | final int index; 49 | final bool isSelected; 50 | final void Function(int index) selectedCallback; 51 | final ThemeData theme; 52 | 53 | @override 54 | Widget build(BuildContext context) { 55 | const duration = Duration(milliseconds: 500); 56 | return AnimatedContainer( 57 | duration: duration, 58 | height: Spacing.huge, 59 | decoration: BoxDecoration( 60 | shape: BoxShape.circle, 61 | color: isSelected ? NpsColors.colorSecondary : NpsColors.colorGrey5, 62 | ), 63 | child: TextButton( 64 | onPressed: () => selectedCallback(index), 65 | style: ButtonStyle( 66 | shape: MaterialStateProperty.all( 67 | const CircleBorder(), 68 | ), 69 | alignment: Alignment.center, 70 | ), 71 | child: AnimatedDefaultTextStyle( 72 | style: theme.textTheme.titleMedium?.copyWith( 73 | color: 74 | isSelected ? NpsColors.colorWhite : NpsColors.colorPrimary1, 75 | ) ?? 76 | const TextStyle(), 77 | duration: duration, 78 | child: Text( 79 | (index + 1).toString(), 80 | ), 81 | ), 82 | ), 83 | ); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/widgets/capture_score_selector_labels.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class CaptureScoreSelectorLabels extends StatelessWidget { 5 | const CaptureScoreSelectorLabels({ 6 | Key? key, 7 | required this.minLabel, 8 | required this.maxLabel, 9 | }) : super(key: key); 10 | 11 | final String minLabel; 12 | final String maxLabel; 13 | 14 | @override 15 | Widget build(BuildContext context) { 16 | return Row( 17 | mainAxisAlignment: MainAxisAlignment.spaceBetween, 18 | children: [ 19 | Wrap( 20 | crossAxisAlignment: WrapCrossAlignment.center, 21 | children: [ 22 | Assets.icons.thumbDownEmoji 23 | .image(width: Spacing.m, height: Spacing.m), 24 | const SizedBox(width: Spacing.xs), 25 | Text(minLabel), 26 | ], 27 | ), 28 | Wrap( 29 | crossAxisAlignment: WrapCrossAlignment.center, 30 | children: [ 31 | Text(maxLabel), 32 | const SizedBox(width: Spacing.xs), 33 | Assets.icons.lovingEmoji.image( 34 | width: Spacing.m, 35 | height: Spacing.m, 36 | ) 37 | ], 38 | ) 39 | ], 40 | ); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/widgets/chips_panel.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/widgets.dart'; 3 | 4 | class ChipsPanel extends StatelessWidget { 5 | const ChipsPanel({ 6 | Key? key, 7 | required this.chips, 8 | required this.selectedChipIndexes, 9 | required this.canSubmit, 10 | required this.chipToggleCallback, 11 | required this.onSubmit, 12 | this.buttonText = '', 13 | }) : super(key: key); 14 | 15 | final List chips; 16 | final List selectedChipIndexes; 17 | final bool canSubmit; 18 | final void Function(int) chipToggleCallback; 19 | final VoidCallback onSubmit; 20 | final String buttonText; 21 | 22 | @override 23 | Widget build(BuildContext context) { 24 | return SingleChildScrollView( 25 | child: Column( 26 | children: [ 27 | AnswerChips( 28 | chips: chips, 29 | selectedChipIndices: selectedChipIndexes, 30 | chipToggleCallback: chipToggleCallback, 31 | ), 32 | const SizedBox(height: Spacing.lg), 33 | SubmitButton( 34 | buttonText: buttonText, 35 | onPressed: canSubmit ? onSubmit : null, 36 | ), 37 | ], 38 | ), 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/widgets/responsive_card.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class ResponsiveCard extends StatelessWidget { 5 | const ResponsiveCard({Key? key, required this.child}) : super(key: key); 6 | 7 | final Widget child; 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return LayoutBuilder( 12 | builder: (context, boxConstraints) { 13 | if (boxConstraints.maxWidth <= Breakpoints.small) { 14 | return Scaffold( 15 | backgroundColor: Theme.of(context).cardColor, 16 | body: SizedBox.expand(child: child), 17 | ); 18 | } else { 19 | return Scaffold( 20 | backgroundColor: NpsColors.transparent, 21 | body: SafeArea( 22 | child: SingleChildScrollView( 23 | child: Center( 24 | child: ConstrainedBox( 25 | constraints: const BoxConstraints( 26 | minWidth: Breakpoints.small, 27 | maxWidth: Breakpoints.small, 28 | ), 29 | child: Card( 30 | surfaceTintColor: Theme.of(context).cardColor, 31 | shape: RoundedRectangleBorder( 32 | borderRadius: BorderRadius.circular(32), 33 | ), 34 | child: child, 35 | ), 36 | ), 37 | ), 38 | ), 39 | ), 40 | ); 41 | } 42 | }, 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/lib/src/widgets/submit_button.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class SubmitButton extends StatelessWidget { 5 | const SubmitButton({ 6 | Key? key, 7 | required this.onPressed, 8 | required this.buttonText, 9 | }) : super(key: key); 10 | 11 | final VoidCallback? onPressed; 12 | final String buttonText; 13 | 14 | @override 15 | Widget build(BuildContext context) { 16 | return ElevatedButton( 17 | key: const Key('capturePage_submit_elevatedButton'), 18 | onPressed: onPressed, 19 | child: Padding( 20 | padding: const EdgeInsets.symmetric( 21 | horizontal: Spacing.xxhuge, 22 | vertical: Spacing.s, 23 | ), 24 | child: Text( 25 | buttonText, 26 | style: const TextStyle( 27 | fontWeight: FontWeight.bold, 28 | ), 29 | ), 30 | ), 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: app_ui 2 | description: A UI Kit for Flutter NPS module 3 | version: 1.0.0+1 4 | publish_to: none 5 | 6 | environment: 7 | sdk: '>=2.18.5 <3.0.0' 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | 13 | dev_dependencies: 14 | flutter_test: 15 | sdk: flutter 16 | flutter_lints: ^2.0.0 17 | 18 | flutter_gen: 19 | assets: 20 | package_parameter_enabled: true 21 | output: lib/src/generated/ 22 | lineLength: 80 23 | integrations: 24 | flutter_svg: true 25 | 26 | flutter: 27 | assets: 28 | - assets/icons/ 29 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/test/helpers/helpers.dart: -------------------------------------------------------------------------------- 1 | export 'pump_app.dart'; 2 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/test/helpers/pump_app.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | extension PumpApp on WidgetTester { 6 | Future pumpApp(Widget widget, {List? observers}) { 7 | return pumpWidget( 8 | MaterialApp( 9 | theme: AppTheme().theme, 10 | home: Scaffold( 11 | body: widget, 12 | ), 13 | ), 14 | ); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/test/src/widgets/answer_chips_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:app_ui/app_ui.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | 7 | import '../../helpers/helpers.dart'; 8 | 9 | void main() { 10 | group('AnswerChips', () { 11 | final chips = ['a', 'b', 'c']; 12 | final selectedChipIndices = [0, 1]; 13 | testWidgets( 14 | 'renders 3 chips', 15 | (tester) async { 16 | await tester.pumpApp( 17 | AnswerChips( 18 | chips: chips, 19 | selectedChipIndices: selectedChipIndices, 20 | chipToggleCallback: (_) {}, 21 | ), 22 | ); 23 | 24 | expect(find.byType(ActionChip), findsNWidgets(3)); 25 | }, 26 | ); 27 | 28 | testWidgets( 29 | 'tap callback with first', 30 | (tester) async { 31 | final completer = Completer(); 32 | await tester.pumpApp( 33 | AnswerChips( 34 | chips: chips, 35 | selectedChipIndices: selectedChipIndices, 36 | chipToggleCallback: completer.complete, 37 | ), 38 | ); 39 | 40 | await tester.tap(find.byType(ActionChip).first); 41 | 42 | expect(completer.isCompleted, isTrue); 43 | expect(await completer.future, equals(0)); 44 | }, 45 | ); 46 | 47 | testWidgets( 48 | 'tap callback with last index', 49 | (tester) async { 50 | final completer = Completer(); 51 | await tester.pumpApp( 52 | AnswerChips( 53 | chips: chips, 54 | selectedChipIndices: selectedChipIndices, 55 | chipToggleCallback: completer.complete, 56 | ), 57 | ); 58 | 59 | await tester.tap(find.byType(ActionChip).last); 60 | 61 | expect(completer.isCompleted, isTrue); 62 | expect(await completer.future, equals(2)); 63 | }, 64 | ); 65 | }); 66 | } 67 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/test/src/widgets/app_close_button_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:app_ui/app_ui.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | 7 | import '../../helpers/helpers.dart'; 8 | 9 | void main() { 10 | group('AppCloseButton', () { 11 | testWidgets('renders IconButton', (tester) async { 12 | final completer = Completer(); 13 | await tester.pumpApp(AppCloseButton(onPressed: completer.complete)); 14 | 15 | await tester.tap(find.byType(IconButton)); 16 | 17 | expect(completer.isCompleted, isTrue); 18 | }); 19 | }); 20 | } 21 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/test/src/widgets/capture_score_selector_labels_test.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: prefer_const_constructors 2 | 3 | import 'package:app_ui/app_ui.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | 6 | import '../../helpers/helpers.dart'; 7 | 8 | void main() { 9 | group('CaptureScoreSelectorLabels', () { 10 | const maxLabel = 'max'; 11 | const minLabel = 'min'; 12 | testWidgets( 13 | 'renders assets and texts', 14 | (tester) async { 15 | await tester.pumpApp( 16 | CaptureScoreSelectorLabels( 17 | maxLabel: maxLabel, 18 | minLabel: minLabel, 19 | ), 20 | ); 21 | 22 | expect(find.text(minLabel), findsOneWidget); 23 | expect(find.text(maxLabel), findsOneWidget); 24 | expect(find.image(Assets.icons.lovingEmoji), findsOneWidget); 25 | expect(find.image(Assets.icons.thumbDownEmoji), findsOneWidget); 26 | }, 27 | ); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/test/src/widgets/capture_score_selector_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:app_ui/app_ui.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | 6 | import '../../helpers/helpers.dart'; 7 | 8 | void main() { 9 | group('CaptureScoreSelector', () { 10 | const maxScore = 3; 11 | const selectedIndex = -1; 12 | 13 | testWidgets( 14 | 'renders 3 chips', 15 | (tester) async { 16 | await tester.pumpApp( 17 | CaptureScoreSelector( 18 | maxScore: maxScore, 19 | selectedIndex: selectedIndex, 20 | selectedCallback: (_) {}, 21 | ), 22 | ); 23 | 24 | expect(find.byType(ScoreButton), findsNWidgets(3)); 25 | }, 26 | ); 27 | 28 | testWidgets( 29 | 'tap callback with index 0', 30 | (tester) async { 31 | final completer = Completer(); 32 | await tester.pumpApp( 33 | CaptureScoreSelector( 34 | maxScore: maxScore, 35 | selectedIndex: selectedIndex, 36 | selectedCallback: completer.complete, 37 | ), 38 | ); 39 | 40 | await tester.tap(find.byType(ScoreButton).first); 41 | 42 | expect(completer.isCompleted, isTrue); 43 | expect(await completer.future, equals(0)); 44 | }, 45 | ); 46 | }); 47 | } 48 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/test/src/widgets/chips_panel_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:app_ui/app_ui.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | 7 | import '../../helpers/helpers.dart'; 8 | 9 | void main() { 10 | group('ChipsPanel', () { 11 | const chips = ['a', 'b', 'c', 'd']; 12 | 13 | testWidgets( 14 | 'renders chips with disabled button', 15 | (tester) async { 16 | await tester.pumpApp( 17 | ChipsPanel( 18 | chips: chips, 19 | canSubmit: false, 20 | selectedChipIndexes: const [], 21 | chipToggleCallback: (number) {}, 22 | onSubmit: () {}, 23 | ), 24 | ); 25 | 26 | expect(find.byType(ActionChip), findsNWidgets(chips.length)); 27 | 28 | final submitButton = find.byType(ElevatedButton); 29 | expect(submitButton, findsNWidgets(1)); 30 | expect(tester.widget(submitButton).enabled, isFalse); 31 | }, 32 | ); 33 | 34 | testWidgets( 35 | 'executes onSubmit when button pressed', 36 | (tester) async { 37 | final completer = Completer(); 38 | await tester.pumpApp( 39 | ChipsPanel( 40 | chips: chips, 41 | canSubmit: true, 42 | selectedChipIndexes: const [0], 43 | chipToggleCallback: (number) {}, 44 | onSubmit: completer.complete, 45 | ), 46 | ); 47 | 48 | final submitButton = find.byType(ElevatedButton); 49 | expect(submitButton, findsNWidgets(1)); 50 | expect(tester.widget(submitButton).enabled, isTrue); 51 | 52 | await tester.tap(submitButton); 53 | 54 | expect(completer.isCompleted, isTrue); 55 | }, 56 | ); 57 | }); 58 | } 59 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/test/src/widgets/responsive_card_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | import '../../helpers/helpers.dart'; 6 | 7 | void main() { 8 | group('ResponsiveCard', () { 9 | testWidgets('renders Text fullscreen on width <= 511 screen size', 10 | (tester) async { 11 | await tester.binding.setSurfaceSize(const Size(Breakpoints.small, 600)); 12 | await tester.pumpApp(const ResponsiveCard(child: Text('text'))); 13 | expect( 14 | find.ancestor( 15 | of: find.byType(Text), 16 | matching: find.byType(Scaffold).first, 17 | ), 18 | findsOneWidget, 19 | ); 20 | await tester.binding.setSurfaceSize(null); 21 | }); 22 | 23 | testWidgets('renders Text in card on width > 511 screen size', 24 | (tester) async { 25 | await tester.binding 26 | .setSurfaceSize(const Size(Breakpoints.small + 1, 600)); 27 | 28 | await tester.pumpApp(const ResponsiveCard(child: Text('text'))); 29 | 30 | expect( 31 | find.ancestor( 32 | of: find.byType(Text), 33 | matching: find.byType(Card).first, 34 | ), 35 | findsOneWidget, 36 | ); 37 | await tester.binding.setSurfaceSize(null); 38 | }); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/test/src/widgets/submit_button_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:app_ui/app_ui.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | 7 | import '../../helpers/helpers.dart'; 8 | 9 | void main() { 10 | group('SubmitButton', () { 11 | const buttonText = 'test'; 12 | testWidgets( 13 | 'submits on click', 14 | (tester) async { 15 | final completer = Completer(); 16 | await tester.pumpApp( 17 | SubmitButton( 18 | onPressed: completer.complete, 19 | buttonText: buttonText, 20 | ), 21 | ); 22 | await tester.tap(find.byType(ElevatedButton).first); 23 | 24 | await tester.pumpAndSettle(); 25 | 26 | expect(completer.isCompleted, isTrue); 27 | }, 28 | ); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /flutter_nps/packages/app_ui/test/theme/app_theme_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | 4 | import '../helpers/helpers.dart'; 5 | 6 | void main() { 7 | group('AppTheme', () { 8 | const textWidget = Text('test'); 9 | const disabledButton = ElevatedButton(onPressed: null, child: textWidget); 10 | final enabledButton = ElevatedButton(onPressed: () {}, child: textWidget); 11 | testWidgets('renders enabled and disabled style', (tester) async { 12 | await tester.pumpApp( 13 | ListView( 14 | children: [disabledButton, enabledButton], 15 | ), 16 | ); 17 | 18 | expect( 19 | tester.widget(find.byWidget(disabledButton)).enabled, 20 | isFalse, 21 | ); 22 | expect( 23 | tester.widget(find.byWidget(enabledButton)).enabled, 24 | isTrue, 25 | ); 26 | }); 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /flutter_nps/packages/nps_repository/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # VSCode related 19 | .vscode/ 20 | 21 | # Flutter/Dart/Pub related 22 | **/doc/api/ 23 | **/ios/Flutter/.last_build_id 24 | .dart_tool/ 25 | .flutter-plugins 26 | .flutter-plugins-dependencies 27 | .packages 28 | pubspec.lock 29 | .pub-cache/ 30 | .pub/ 31 | /build/ 32 | 33 | # Web related 34 | lib/generated_plugin_registrant.dart 35 | 36 | # Symbolication related 37 | app.*.symbols 38 | 39 | # Obfuscation related 40 | app.*.map.json 41 | -------------------------------------------------------------------------------- /flutter_nps/packages/nps_repository/README.md: -------------------------------------------------------------------------------- 1 | # nps_repository 2 | 3 | [![License: MIT][license_badge]][license_link] 4 | 5 | Repository to send Customer Score result 6 | 7 | [license_badge]: https://img.shields.io/badge/license-MIT-blue.svg 8 | [license_link]: https://opensource.org/licenses/MIT 9 | -------------------------------------------------------------------------------- /flutter_nps/packages/nps_repository/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | 3 | analyzer: 4 | language: 5 | strict-casts: true 6 | strict-inference: true 7 | 8 | errors: 9 | missing_required_param: error 10 | missing_return: error 11 | 12 | exclude: 13 | - test/.test_coverage.dart 14 | - lib/generated_plugin_registrant.dart 15 | - lib/gen/assets.gen.dart 16 | -------------------------------------------------------------------------------- /flutter_nps/packages/nps_repository/lib/nps_repository.dart: -------------------------------------------------------------------------------- 1 | library nps_repository; 2 | 3 | export 'src/nps_repository.dart'; 4 | export 'src/score_submit_model.dart'; 5 | -------------------------------------------------------------------------------- /flutter_nps/packages/nps_repository/lib/src/nps_repository.dart: -------------------------------------------------------------------------------- 1 | import 'package:nps_repository/src/score_submit_model.dart'; 2 | 3 | class NpsRepository { 4 | const NpsRepository(); 5 | 6 | Future sendCustomerSatisfaction({ 7 | required CustomerSatisfaction scoreSubmit, 8 | }) { 9 | // Add custom implementation here to report customer satisfaction. 10 | return Future.value(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /flutter_nps/packages/nps_repository/lib/src/score_submit_model.dart: -------------------------------------------------------------------------------- 1 | class CustomerSatisfaction { 2 | const CustomerSatisfaction({required this.score, required this.chipIndexes}); 3 | 4 | final int score; 5 | final List chipIndexes; 6 | 7 | Map toJson() => { 8 | 'score': score, 9 | 'chipIndexes': chipIndexes, 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /flutter_nps/packages/nps_repository/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: nps_repository 2 | description: Repository to send Customer Score result 3 | version: 1.0.0+1 4 | publish_to: none 5 | 6 | environment: 7 | sdk: '>=2.18.5 <3.0.0' 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | 13 | dev_dependencies: 14 | flutter_test: 15 | sdk: flutter 16 | flutter_lints: ^2.0.0 17 | mocktail: ^1.0.0 18 | -------------------------------------------------------------------------------- /flutter_nps/packages/nps_repository/test/src/nps_repository_test.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: prefer_const_constructors, cascade_invocations 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:mocktail/mocktail.dart'; 4 | import 'package:nps_repository/nps_repository.dart'; 5 | 6 | class NpsRepositoryMock extends Mock implements NpsRepository {} 7 | 8 | void main() { 9 | group('NpsRepository', () { 10 | final scoreSubmit = CustomerSatisfaction(score: 1, chipIndexes: [0, 1]); 11 | late NpsRepository npsRepository; 12 | 13 | setUp(() { 14 | npsRepository = NpsRepository(); 15 | }); 16 | 17 | test('can be instantiated', () { 18 | expect(npsRepository, isNotNull); 19 | }); 20 | 21 | test('sendCustomerSatisfaction was called', () { 22 | final result = 23 | npsRepository.sendCustomerSatisfaction(scoreSubmit: scoreSubmit); 24 | 25 | expectLater(result, completes); 26 | }); 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /flutter_nps/packages/nps_repository/test/src/score_submit_model_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:nps_repository/nps_repository.dart'; 5 | 6 | void main() { 7 | test('ScoreSubmitModel toJson translates corectly', () { 8 | const scoreSubmitModel = 9 | CustomerSatisfaction(chipIndexes: [0, 1], score: 1); 10 | 11 | final result = scoreSubmitModel.toJson(); 12 | 13 | expect(result, jsonDecode(jsonEncode(scoreSubmitModel))); 14 | }); 15 | } 16 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 25 | /pubspec.lock 26 | **/doc/api/ 27 | .dart_tool/ 28 | .packages 29 | pubspec.lock 30 | build/ 31 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: db747aa1331bd95bc9b3874c842261ca2d302cd5 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/README.md: -------------------------------------------------------------------------------- 1 | Platform specific package for closing app programmatically 2 | 3 | ## Features 4 | 5 | Supports programmatically closing iOS, Android and Web app 6 | 7 | ## Usage 8 | 9 | ```dart 10 | IconButton( 11 | onPressed: PlatformClose.instance.close, 12 | icon: const Icon(Icons.close), 13 | ), 14 | ``` 15 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | 3 | analyzer: 4 | language: 5 | strict-casts: true 6 | strict-inference: true 7 | 8 | errors: 9 | missing_required_param: error 10 | missing_return: error 11 | 12 | exclude: 13 | - test/.test_coverage.dart 14 | - lib/generated_plugin_registrant.dart 15 | 16 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/lib/mobile_close.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/services.dart'; 2 | import 'package:platform_close/platform_close.dart'; 3 | 4 | class MobileClose implements PlatformClose { 5 | const MobileClose({required this.closeCallback}); 6 | 7 | final VoidCallback closeCallback; 8 | 9 | @override 10 | void close() { 11 | closeCallback(); 12 | } 13 | } 14 | 15 | PlatformClose getPlatformClose() => 16 | const MobileClose(closeCallback: SystemNavigator.pop); 17 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/lib/platform_close.dart: -------------------------------------------------------------------------------- 1 | library platform_close; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:platform_close/platform_close_stub.dart' 5 | if (dart.library.io) 'package:platform_close/mobile_close.dart' 6 | if (dart.library.html) 'package:platform_close/web_close.dart'; 7 | 8 | abstract class PlatformClose { 9 | static PlatformClose get instance => platform ?? getPlatformClose(); 10 | 11 | @visibleForTesting 12 | static PlatformClose? platform; 13 | 14 | void close(); 15 | } 16 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/lib/platform_close_stub.dart: -------------------------------------------------------------------------------- 1 | import 'package:platform_close/platform_close.dart'; 2 | 3 | PlatformClose getPlatformClose() => throw UnsupportedError( 4 | 'Cannot create a platform close without the packages dart:html or package:fluter/services', 5 | ); 6 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/lib/web_close.dart: -------------------------------------------------------------------------------- 1 | // ignore: avoid_web_libraries_in_flutter 2 | import 'dart:html'; 3 | import 'package:platform_close/platform_close.dart'; 4 | 5 | class WebClose implements PlatformClose { 6 | const WebClose({required this.window}); 7 | 8 | final Window window; 9 | 10 | @override 11 | void close() { 12 | window.parent?.postMessage('close', '*'); 13 | document.getElementById('iframe')?.remove(); 14 | } 15 | } 16 | 17 | PlatformClose getPlatformClose() => WebClose(window: window); 18 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: platform_close 2 | description: Platform specific package for closing app programmatically 3 | version: 0.0.1 4 | publish_to: none 5 | 6 | environment: 7 | sdk: '>=2.18.5 <3.0.0' 8 | flutter: ">=1.17.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | 14 | dev_dependencies: 15 | flutter_test: 16 | sdk: flutter 17 | flutter_lints: ^2.0.0 18 | mocktail: ^1.0.0 19 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/test/mobile_close_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:mocktail/mocktail.dart'; 5 | import 'package:platform_close/mobile_close.dart'; 6 | 7 | class MockFunction extends Mock { 8 | void call(); 9 | } 10 | 11 | void main() { 12 | group('MobileClose', () { 13 | test('getPlatformClose returns MobileClose instance', () { 14 | expect(getPlatformClose(), isA()); 15 | }); 16 | 17 | testWidgets('close calls closeCallback', (tester) async { 18 | const testText = 'test'; 19 | final myFn = MockFunction(); 20 | final mobileClose = MobileClose(closeCallback: myFn); 21 | 22 | await tester.pumpWidget( 23 | Directionality( 24 | textDirection: TextDirection.ltr, 25 | child: ElevatedButton( 26 | onPressed: mobileClose.close, 27 | child: const Text(testText), 28 | ), 29 | ), 30 | ); 31 | 32 | await tester.tap(find.widgetWithText(ElevatedButton, testText).first); 33 | 34 | await tester.pumpAndSettle(); 35 | 36 | verify(myFn.call).called(1); 37 | }); 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /flutter_nps/packages/platform_close/test/platform_close_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:mocktail/mocktail.dart'; 4 | import 'package:platform_close/mobile_close.dart' as mobile; 5 | import 'package:platform_close/platform_close.dart'; 6 | 7 | class MockMobileClose extends Mock implements mobile.MobileClose {} 8 | 9 | void main() { 10 | group('PlatformClose', () { 11 | testWidgets('instance() calls close()', (tester) async { 12 | const testText = 'test'; 13 | final mobileMock = MockMobileClose(); 14 | PlatformClose.platform = mobileMock; 15 | 16 | await tester.pumpWidget( 17 | Directionality( 18 | textDirection: TextDirection.ltr, 19 | child: ElevatedButton( 20 | onPressed: PlatformClose.instance.close, 21 | child: const Text(testText), 22 | ), 23 | ), 24 | ); 25 | 26 | await tester.tap(find.widgetWithText(ElevatedButton, testText).first); 27 | 28 | await tester.pumpAndSettle(); 29 | 30 | verify(mobileMock.close).called(1); 31 | }); 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /flutter_nps/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_nps 2 | description: A new Flutter module project. 3 | 4 | version: 1.0.0+1 5 | publish_to: none 6 | 7 | environment: 8 | sdk: '>=2.18.5 <3.0.0' 9 | 10 | dependencies: 11 | app_ui: 12 | path: packages/app_ui 13 | bloc: ^8.1.0 14 | equatable: ^2.0.5 15 | flutter: 16 | sdk: flutter 17 | flutter_bloc: ^8.1.1 18 | flutter_localizations: 19 | sdk: flutter 20 | intl: any 21 | nps_repository: 22 | path: packages/nps_repository 23 | platform_close: 24 | path: packages/platform_close 25 | 26 | dev_dependencies: 27 | bloc_test: ^9.1.0 28 | flutter_lints: ^2.0.1 29 | flutter_test: 30 | sdk: flutter 31 | mocktail: ^1.0.0 32 | 33 | flutter: 34 | uses-material-design: true 35 | generate: true 36 | 37 | module: 38 | androidX: true 39 | androidPackage: com.example.flutter_nps 40 | iosBundleIdentifier: com.example.flutterNps 41 | -------------------------------------------------------------------------------- /flutter_nps/test/app/route_generator_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_nps/capture/view/capture_end_page.dart'; 3 | import 'package:flutter_nps/capture/view/capture_page.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | import 'package:mocktail/mocktail.dart'; 6 | 7 | import '../helpers/helpers.dart'; 8 | 9 | class MockNavigatorObserver extends Mock implements NavigatorObserver {} 10 | 11 | class FakeRoute extends Fake implements Route {} 12 | 13 | void main() { 14 | setUpAll(() { 15 | registerFallbackValue(FakeRoute()); 16 | }); 17 | 18 | group('RouteGenerator', () { 19 | final navigatorObserver = MockNavigatorObserver(); 20 | 21 | testWidgets('notified user on wrong route', (tester) async { 22 | await tester.pumpApp( 23 | Builder( 24 | builder: (context) => TextButton( 25 | child: const Text('testButton'), 26 | onPressed: () => Navigator.of(context).pushNamed('unknownRoute'), 27 | ), 28 | ), 29 | observers: [navigatorObserver], 30 | ); 31 | 32 | await tester.tap(find.widgetWithText(TextButton, 'testButton')); 33 | await tester.pumpAndSettle(); 34 | 35 | expect( 36 | find.widgetWithText(Center, 'No route defined for unknownRoute'), 37 | findsOneWidget, 38 | ); 39 | 40 | verify( 41 | () => navigatorObserver.didPush( 42 | any(that: isA()), 43 | any(that: isA()), 44 | ), 45 | ); 46 | }); 47 | 48 | testWidgets( 49 | 'navigator.pushNamed ${CapturePage.routeName} builds CaptureView', 50 | (tester) async { 51 | await tester.pumpApp( 52 | Builder( 53 | builder: (context) => TextButton( 54 | child: const Text('testButton'), 55 | onPressed: () => 56 | Navigator.of(context).pushNamed(CapturePage.routeName), 57 | ), 58 | ), 59 | observers: [navigatorObserver], 60 | ); 61 | 62 | await tester.tap(find.widgetWithText(TextButton, 'testButton')); 63 | await tester.pumpAndSettle(); 64 | 65 | expect( 66 | find.byType(CaptureView), 67 | findsOneWidget, 68 | ); 69 | 70 | verify( 71 | () => navigatorObserver.didPush( 72 | any(that: isA()), 73 | any(that: isA()), 74 | ), 75 | ); 76 | }); 77 | 78 | testWidgets( 79 | 'navigator.pushNamed ${CaptureEndPage.routeName} builds CaptureEndView', 80 | (tester) async { 81 | await tester.pumpApp( 82 | Builder( 83 | builder: (context) => TextButton( 84 | child: const Text('testButton'), 85 | onPressed: () => 86 | Navigator.of(context).pushNamed(CaptureEndPage.routeName), 87 | ), 88 | ), 89 | observers: [navigatorObserver], 90 | ); 91 | 92 | await tester.tap(find.widgetWithText(TextButton, 'testButton')); 93 | await tester.pumpAndSettle(); 94 | 95 | expect( 96 | find.byType(CaptureEndView), 97 | findsOneWidget, 98 | ); 99 | 100 | verify( 101 | () => navigatorObserver.didPush( 102 | any(that: isA()), 103 | any(that: isA()), 104 | ), 105 | ); 106 | }); 107 | }); 108 | } 109 | -------------------------------------------------------------------------------- /flutter_nps/test/app/view/app_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_nps/app/app.dart'; 2 | import 'package:flutter_nps/capture/capture.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | void main() { 6 | group('App', () { 7 | testWidgets('renders CapturePage', (tester) async { 8 | await tester.pumpWidget(const App()); 9 | expect(find.byType(CapturePage), findsOneWidget); 10 | }); 11 | }); 12 | } 13 | -------------------------------------------------------------------------------- /flutter_nps/test/capture/cubit/capture_cubit_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:bloc_test/bloc_test.dart'; 2 | import 'package:flutter_nps/capture/capture.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:mocktail/mocktail.dart'; 5 | import 'package:nps_repository/nps_repository.dart'; 6 | 7 | class MockNpsRepository extends Mock implements NpsRepository {} 8 | 9 | class MockScoreSubmitModel extends Mock implements CustomerSatisfaction {} 10 | 11 | void main() { 12 | late NpsRepository npsRepository; 13 | group('CaptureCubit', () { 14 | setUpAll(() { 15 | registerFallbackValue(MockScoreSubmitModel()); 16 | }); 17 | 18 | setUp(() { 19 | npsRepository = MockNpsRepository(); 20 | }); 21 | 22 | test('initial state is set to score: -1 and chipIndexes: []', () { 23 | expect( 24 | CaptureCubit(npsRepository: npsRepository).state, 25 | equals(CaptureCubitState.initial()), 26 | ); 27 | }); 28 | 29 | blocTest( 30 | 'selectScore sets score to 1', 31 | build: () => CaptureCubit(npsRepository: npsRepository), 32 | act: (cubit) => cubit.selectScore(score: 1), 33 | expect: () => [ 34 | equals(const CaptureCubitState(score: 1, chipIndexes: [])), 35 | ], 36 | ); 37 | 38 | blocTest( 39 | 'addChipIndex adds index to chipIndexes', 40 | build: () => CaptureCubit(npsRepository: npsRepository), 41 | seed: () => const CaptureCubitState(score: -1, chipIndexes: []), 42 | act: (cubit) => cubit.chipToggled(index: 1), 43 | expect: () => [ 44 | equals(const CaptureCubitState(score: -1, chipIndexes: [1])), 45 | ], 46 | ); 47 | 48 | blocTest( 49 | 'removeChipIndex from chipIndexes', 50 | build: () => CaptureCubit(npsRepository: npsRepository), 51 | seed: () => const CaptureCubitState(score: -1, chipIndexes: [1]), 52 | act: (cubit) => cubit.chipToggled(index: 1), 53 | expect: () => [ 54 | equals(const CaptureCubitState(score: -1, chipIndexes: [])), 55 | ], 56 | ); 57 | 58 | blocTest( 59 | 'submitResult returns nothing', 60 | setUp: () { 61 | when( 62 | () => npsRepository.sendCustomerSatisfaction( 63 | scoreSubmit: any(named: 'scoreSubmit'), 64 | ), 65 | ).thenAnswer(Future.value); 66 | }, 67 | build: () => CaptureCubit(npsRepository: npsRepository), 68 | seed: () => const CaptureCubitState(score: -1, chipIndexes: []), 69 | act: (cubit) => cubit.submitResult(), 70 | expect: () => [], 71 | ); 72 | }); 73 | } 74 | -------------------------------------------------------------------------------- /flutter_nps/test/capture/cubit/capture_state_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_nps/capture/capture.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | 4 | void main() { 5 | group('CaptureCubitState', () { 6 | final initialCaptureCubitState = CaptureCubitState.initial(); 7 | 8 | test('initial values are set to score: -1 and chipIndexes: []', () { 9 | expect(initialCaptureCubitState.chipIndexes, isEmpty); 10 | expect(initialCaptureCubitState.score, equals(-1)); 11 | }); 12 | 13 | test('initial state props returns array of props', () { 14 | expect( 15 | initialCaptureCubitState.props, 16 | contains(initialCaptureCubitState.score), 17 | ); 18 | expect( 19 | initialCaptureCubitState.props, 20 | contains(initialCaptureCubitState.chipIndexes), 21 | ); 22 | }); 23 | 24 | group('copyWith', () { 25 | final capture = CaptureCubitState.initial(); 26 | 27 | test('copies CaptureCubitState with changed values', () { 28 | expect(capture.score, equals(-1)); 29 | expect(capture.chipIndexes, equals([])); 30 | 31 | final firstCapture = capture.copyWith(score: 1); 32 | 33 | expect(firstCapture.score, equals(1)); 34 | expect(firstCapture.chipIndexes, equals([])); 35 | 36 | final secondCapture = firstCapture.copyWith(chipIndexes: [1]); 37 | 38 | expect(secondCapture.score, equals(1)); 39 | expect(secondCapture.chipIndexes, equals([1])); 40 | }); 41 | }); 42 | }); 43 | } 44 | -------------------------------------------------------------------------------- /flutter_nps/test/capture/view/capture_end_page_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:app_ui/app_ui.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_nps/capture/capture.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | 6 | import '../../helpers/helpers.dart'; 7 | 8 | void main() { 9 | group('CaptureEndPage', () { 10 | testWidgets('renders CaptureView fullscreen on width <= 511 screen size', 11 | (tester) async { 12 | await tester.binding.setSurfaceSize(const Size(Breakpoints.small, 600)); 13 | await tester.pumpApp(const CaptureEndPage()); 14 | expect( 15 | find.ancestor( 16 | of: find.byType(CaptureEndView), 17 | matching: find.byType(Scaffold).first, 18 | ), 19 | findsOneWidget, 20 | ); 21 | await tester.binding.setSurfaceSize(null); 22 | }); 23 | 24 | testWidgets('renders CaptureView in card on width > 511 screen size', 25 | (tester) async { 26 | await tester.binding 27 | .setSurfaceSize(const Size(Breakpoints.small + 1, 600)); 28 | 29 | await tester.pumpApp(const CaptureEndPage()); 30 | 31 | expect( 32 | find.ancestor( 33 | of: find.byType(CaptureEndView), 34 | matching: find.byType(Card).first, 35 | ), 36 | findsOneWidget, 37 | ); 38 | await tester.binding.setSurfaceSize(null); 39 | }); 40 | }); 41 | } 42 | -------------------------------------------------------------------------------- /flutter_nps/test/gen/assets.gen_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_nps/gen/assets.gen.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | 4 | void main() { 5 | group('Assets has icon', () { 6 | test('check-circle.png', () { 7 | final checkCircle = Assets.icons.checkCircle; 8 | expect(checkCircle, isNotNull); 9 | }); 10 | }); 11 | group('AssetGenImage', () { 12 | test('path resolves', () { 13 | const testPath = 'test/test'; 14 | const assetGen = AssetGenImage(testPath); 15 | 16 | expect(assetGen.path, equals(testPath)); 17 | }); 18 | }); 19 | } 20 | -------------------------------------------------------------------------------- /flutter_nps/test/helpers/helpers.dart: -------------------------------------------------------------------------------- 1 | export 'pump_app.dart'; 2 | -------------------------------------------------------------------------------- /flutter_nps/test/helpers/pump_app.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_localizations/flutter_localizations.dart'; 3 | import 'package:flutter_nps/app/route_generator.dart'; 4 | import 'package:flutter_nps/l10n/l10n.dart'; 5 | import 'package:flutter_test/flutter_test.dart'; 6 | 7 | extension PumpApp on WidgetTester { 8 | Future pumpApp(Widget widget, {List? observers}) { 9 | return pumpWidget( 10 | MaterialApp( 11 | navigatorObservers: observers ?? [], 12 | onGenerateRoute: RouteGenerator.generateRoute, 13 | localizationsDelegates: const [ 14 | AppLocalizations.delegate, 15 | GlobalMaterialLocalizations.delegate, 16 | ], 17 | supportedLocales: AppLocalizations.supportedLocales, 18 | home: Scaffold( 19 | body: widget, 20 | ), 21 | ), 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /newsfeed_android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | local.properties 11 | -------------------------------------------------------------------------------- /newsfeed_android/README.md: -------------------------------------------------------------------------------- 1 | # Newsfeed Android App 2 | 3 | This project contains a sample Android application that shows you how to embed a Flutter module into a native Android project. 4 | 5 | https://user-images.githubusercontent.com/17708132/163604660-54458b7a-5bc1-454f-93cc-2705a625838c.mov 6 | 7 | ## Getting Started 8 | 9 | **Important:** For instructions on integrating Flutter modules into your existing applications, see the [add-to-app documentation](https://flutter.dev/docs/development/add-to-app). 10 | 11 | ## Import a Flutter module into your Android app 12 | 13 | First download the `flutter-aar` artifact from the [github repository Archive workflow](https://github.com/VGVentures/take-flutter-home/actions/workflows/archive_workflow.yaml) and add the folder to the root directory of your project. 14 | 15 | Update your `app/build.gradle` file with path of the imported artifact: 16 | 17 | ``` 18 | android { 19 | // ... 20 | } 21 | 22 | repositories { 23 | maven { 24 | url 'some/path/android_project/' 25 | // This is relative to the location of the build.gradle file 26 | } 27 | maven { 28 | url 'https://storage.googleapis.com/download.flutter.io' 29 | } 30 | } 31 | 32 | dependencies { 33 | // ... 34 | debugImplementation 'com.example.flutter_module:flutter_debug:1.0' 35 | profileImplementation 'com.example.flutter_module:flutter_profile:1.0' 36 | releaseImplementation 'com.example.flutter_module:flutter_release:1.0' 37 | } 38 | ``` 39 | 40 | Add the code needed to launch the Flutter app as shown in the [example](https://github.com/VGVentures/take-flutter-home/blob/2db086b6b708e301c6562ceab37d933de3bd4254/newsfeed_android/app/src/main/java/com/example/newsfeed_android/MainActivity.kt#L93). 41 | 42 | Run your Android project. 43 | 44 | ## Setup 45 | 46 | To easily import the Flutter module into an existing Android application, we need to build the Flutter module into a generic Android Archive (AAR). To create an Android AAR file from the Flutter module run: 47 | 48 | ```sh 49 | cd flutter_nps 50 | flutter build aar 51 | ``` 52 | 53 | You must run `flutter build aar` every time you make code changes in your Flutter module. Then follow the rest of the instructions regarding configuration displayed in the command line. 54 | 55 | Open the Android project in Android Studio or IntelliJ and run the app. 56 | 57 | ## Troubleshooting 58 | 59 | ### Failed to resolve: com.example.flutter_nps:flutter_debug:1.0 60 | 61 | In both `build.gradle` and `app/build.gradle` replace relative path 62 | 63 | ``` 64 | maven { 65 | url '../../flutter_nps/build/host/outputs/repo' 66 | } 67 | ``` 68 | 69 | with full path: 70 | 71 | ``` 72 | maven { 73 | url '/flutter_nps/build/host/outputs/repo' 74 | } 75 | ``` 76 | -------------------------------------------------------------------------------- /newsfeed_android/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /newsfeed_android/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | apply plugin: 'kotlin-android' 6 | 7 | repositories { 8 | google() 9 | mavenCentral() 10 | 11 | String storageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com" 12 | maven { 13 | url '../../flutter_nps/build/host/outputs/repo' 14 | } 15 | maven { 16 | url "$storageUrl/download.flutter.io" 17 | } 18 | } 19 | 20 | android { 21 | compileSdk 31 22 | 23 | defaultConfig { 24 | applicationId "com.example.newsfeed_android" 25 | minSdk 23 26 | targetSdk 31 27 | versionCode 1 28 | versionName "1.0" 29 | 30 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 31 | } 32 | buildTypes { 33 | profile { 34 | initWith debug 35 | } 36 | release { 37 | minifyEnabled false 38 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 39 | } 40 | } 41 | compileOptions { 42 | sourceCompatibility JavaVersion.VERSION_1_8 43 | targetCompatibility JavaVersion.VERSION_1_8 44 | } 45 | kotlinOptions { 46 | jvmTarget = '1.8' 47 | } 48 | testOptions { 49 | unitTests.returnDefaultValues = true 50 | } 51 | buildFeatures{ 52 | dataBinding true 53 | viewBinding true 54 | } 55 | } 56 | 57 | dependencies { 58 | implementation 'androidx.appcompat:appcompat:1.4.1' 59 | implementation 'com.google.android.material:material:1.5.0' 60 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3' 61 | implementation 'androidx.test.espresso:espresso-core:3.4.0' 62 | implementation 'androidx.test:runner:1.4.0' 63 | implementation 'androidx.test:rules:1.4.0' 64 | implementation 'androidx.test.espresso:espresso-contrib:3.4.0' 65 | debugImplementation 'androidx.test.ext:junit:1.1.3' 66 | implementation "androidx.core:core-ktx:1.7.0" 67 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.20-M1" 68 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9" 69 | debugImplementation 'com.example.flutter_nps:flutter_debug:1.0' 70 | profileImplementation 'com.example.flutter_nps:flutter_profile:1.0' 71 | releaseImplementation 'com.example.flutter_nps:flutter_release:1.0' 72 | } -------------------------------------------------------------------------------- /newsfeed_android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /newsfeed_android/app/src/androidTest/java/com/example/newsfeed_android/MainActivityTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.newsfeed_android 2 | 3 | import org.junit.Test 4 | import org.junit.runner.RunWith 5 | import androidx.test.espresso.assertion.ViewAssertions.matches 6 | import androidx.test.espresso.Espresso.onView 7 | import androidx.test.espresso.matcher.ViewMatchers.* 8 | import androidx.test.ext.junit.rules.ActivityScenarioRule 9 | import androidx.test.ext.junit.runners.AndroidJUnit4 10 | import androidx.test.filters.LargeTest 11 | import org.junit.Rule 12 | 13 | @RunWith(AndroidJUnit4::class) 14 | @LargeTest 15 | class MainActivityTest { 16 | 17 | @get:Rule 18 | val activityRule = ActivityScenarioRule(MainActivity::class.java) 19 | 20 | @Test 21 | fun view_initialized() { 22 | onView(withId(R.id.app_name)).check(matches(isDisplayed())) 23 | onView(withId(R.id.dot)).check(matches(isDisplayed())) 24 | onView(withId(R.id.recyclerView)).check(matches(isDisplayed())) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/java/com/example/newsfeed_android/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.newsfeed_android 2 | 3 | import android.os.Bundle 4 | import android.view.Window 5 | import androidx.appcompat.app.AppCompatActivity 6 | import androidx.recyclerview.widget.LinearLayoutManager 7 | import androidx.recyclerview.widget.RecyclerView 8 | import com.example.newsfeed_android.databinding.ActivityMainBinding 9 | import io.flutter.embedding.android.FlutterActivity 10 | import io.flutter.embedding.android.FlutterActivityLaunchConfigs 11 | import io.flutter.embedding.engine.FlutterEngine 12 | import io.flutter.embedding.engine.FlutterEngineCache 13 | import io.flutter.embedding.engine.dart.DartExecutor 14 | import kotlinx.coroutines.* 15 | 16 | private const val FLUTTER_ENGINE_NAME = "nps_flutter_engine_name" 17 | private const val ROW_ITEM_NAME = "row_item" 18 | 19 | class MainActivity : AppCompatActivity() { 20 | private var recyclerViewAdapter: RecyclerViewAdapter? = null 21 | private var rowsArrayList: ArrayList = ArrayList() 22 | private var isLoading = false 23 | 24 | override fun onCreate(savedInstanceState: Bundle?) { 25 | super.onCreate(savedInstanceState) 26 | warmupFlutterEngine() 27 | 28 | this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE) 29 | val binding = ActivityMainBinding.inflate(layoutInflater) 30 | 31 | populateData(rowsArrayList) 32 | 33 | initAdapter(binding) 34 | initScrollListener(binding) 35 | setContentView(binding.root) 36 | } 37 | 38 | private fun initScrollListener(binding: ActivityMainBinding) { 39 | val loadMoreCallback = LoadMoreOnScrollListener(callback = { 40 | val linearLayoutManager = binding.recyclerView.layoutManager as LinearLayoutManager? 41 | if (!isLoading) { 42 | if (linearLayoutManager != null && 43 | linearLayoutManager.findLastCompletelyVisibleItemPosition() == (rowsArrayList.size - 1) 44 | ) { 45 | isLoading = true 46 | loadMore(binding.recyclerView) 47 | } 48 | } 49 | }) 50 | binding.recyclerView.addOnScrollListener(loadMoreCallback) 51 | } 52 | 53 | private fun initAdapter(binding: ActivityMainBinding) { 54 | recyclerViewAdapter = RecyclerViewAdapter(rowsArrayList) 55 | binding.recyclerView.layoutManager = LinearLayoutManager(applicationContext) 56 | binding.recyclerView.adapter = recyclerViewAdapter 57 | } 58 | 59 | private fun populateData(list: ArrayList) { 60 | for (i in 0..20) { 61 | list.add(ROW_ITEM_NAME) 62 | } 63 | } 64 | 65 | private fun loadMore(recyclerView: RecyclerView) { 66 | if (rowsArrayList.size in 19..29) { 67 | runFlutterNPS() 68 | } 69 | runBlocking { 70 | launch { 71 | fakeRequest() 72 | recyclerView.post { 73 | rowsArrayList.removeAt(rowsArrayList.size - 1) 74 | val scrollPosition = rowsArrayList.size 75 | recyclerViewAdapter?.notifyItemRemoved(scrollPosition) 76 | 77 | var currentSize = rowsArrayList.size 78 | val nextLimit = currentSize + 10 79 | while (currentSize - 1 < nextLimit) { 80 | rowsArrayList.add(ROW_ITEM_NAME) 81 | currentSize++ 82 | } 83 | isLoading = false 84 | recyclerViewAdapter?.notifyItemRangeInserted(nextLimit - 10, 10) 85 | } 86 | } 87 | } 88 | } 89 | 90 | 91 | private suspend fun fakeRequest(): Boolean { 92 | delay(2000) 93 | return true 94 | } 95 | 96 | private fun runFlutterNPS() { 97 | startActivity( 98 | FlutterActivity.withCachedEngine(FLUTTER_ENGINE_NAME) 99 | .backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.transparent) 100 | .build(this) 101 | ) 102 | } 103 | 104 | private fun warmupFlutterEngine() { 105 | val flutterEngine = FlutterEngine(this) 106 | 107 | // Start executing Dart code to pre-warm the FlutterEngine. 108 | flutterEngine.dartExecutor.executeDartEntrypoint( 109 | DartExecutor.DartEntrypoint.createDefault() 110 | ) 111 | 112 | // Cache the FlutterEngine to be used by FlutterActivity. 113 | FlutterEngineCache 114 | .getInstance() 115 | .put(FLUTTER_ENGINE_NAME, flutterEngine) 116 | } 117 | 118 | internal class LoadMoreOnScrollListener(private var callback: () -> Unit) : 119 | RecyclerView.OnScrollListener() { 120 | override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { 121 | super.onScrolled(recyclerView, dx, dy) 122 | callback() 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/java/com/example/newsfeed_android/RecyclerViewAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.example.newsfeed_android 2 | import android.view.LayoutInflater 3 | import android.view.View 4 | import android.view.ViewGroup 5 | import android.widget.ImageView 6 | import androidx.annotation.NonNull 7 | import androidx.recyclerview.widget.RecyclerView 8 | import androidx.recyclerview.widget.RecyclerView.ViewHolder 9 | 10 | private const val VIEW_TYPE_ITEM = 0 11 | private const val VIEW_TYPE_LOADING = 1 12 | 13 | class RecyclerViewAdapter constructor(private val itemList: List) : 14 | RecyclerView.Adapter() { 15 | 16 | @NonNull 17 | override fun onCreateViewHolder( 18 | @NonNull parent: ViewGroup, 19 | viewType: Int 20 | ): ViewHolder { 21 | return if (viewType == VIEW_TYPE_ITEM) { 22 | val view = 23 | LayoutInflater.from(parent.context).inflate(R.layout.item_row, parent, false) 24 | ItemViewHolder(view) 25 | } else { 26 | val view = LayoutInflater.from(parent.context) 27 | .inflate(R.layout.item_loading, parent, false) 28 | LoadingViewHolder(view) 29 | } 30 | } 31 | 32 | override fun onBindViewHolder(@NonNull viewHolder: ViewHolder, position: Int) { 33 | if (viewHolder is ItemViewHolder) { 34 | populateItemRows(viewHolder, position) 35 | } 36 | } 37 | 38 | override fun getItemViewType(position: Int): Int { 39 | return if (itemList.size - 1 == position) VIEW_TYPE_LOADING else VIEW_TYPE_ITEM 40 | } 41 | 42 | override fun getItemCount(): Int { 43 | return itemList.size 44 | } 45 | 46 | private fun populateItemRows(viewHolder: ItemViewHolder, position: Int) { 47 | when(position % 3) { 48 | 0 -> viewHolder.imageItem.setImageResource(R.mipmap.placeholder_image) 49 | 1 -> viewHolder.imageItem.setImageResource(R.mipmap.placeholder_image2) 50 | 2 -> viewHolder.imageItem.setImageResource(R.mipmap.placeholder_image3) 51 | } 52 | } 53 | 54 | inner class ItemViewHolder constructor(@NonNull itemView: View) : ViewHolder(itemView) { 55 | var imageItem: ImageView = itemView.findViewById(R.id.cardViewImage) 56 | } 57 | 58 | inner class LoadingViewHolder constructor(itemView: View) : ViewHolder(itemView) 59 | 60 | } -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 28 | 29 | 39 | 40 | 47 | 48 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/layout/item_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/layout/item_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 23 | 24 | 37 | 38 | 53 | 54 | 64 | 65 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-mdpi/dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-mdpi/dot.png -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-mdpi/placeholder_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-mdpi/placeholder_image.png -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-mdpi/placeholder_image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-mdpi/placeholder_image2.png -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-mdpi/placeholder_image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-mdpi/placeholder_image3.png -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF03DAC5 4 | #FF2196F3 5 | #FF1976D2 6 | #FF000000 7 | #FFFFFFFF 8 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | newsfeed 3 | Blue dot a part of application logo 4 | Sample image for the category row 5 | Category 6 | Lorem ipsum dolor sit amet… 7 | 13 Jan, 2022 8 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 19 | -------------------------------------------------------------------------------- /newsfeed_android/app/src/test/java/com/example/newsfeed_android/RecyclerViewAdapterTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.newsfeed_android 2 | import org.junit.Assert.assertEquals 3 | import org.junit.Test 4 | 5 | class RecyclerViewAdapterTest{ 6 | 7 | @Test fun get_item_count_returns_correct() { 8 | 9 | val list : List = listOf("Item", "Item2", "Item3") 10 | val recycler = RecyclerViewAdapter(list) 11 | 12 | assertEquals(list.size, recycler.itemCount) 13 | } 14 | 15 | @Test fun item_type_item_when_not_last_item() { 16 | 17 | val list : List = listOf("Item", "Item2", "Item3") 18 | val recycler = RecyclerViewAdapter(list) 19 | 20 | var result = recycler.getItemViewType(0) 21 | assertEquals(0, result) 22 | 23 | result = recycler.getItemViewType(1) 24 | assertEquals(0, result) 25 | } 26 | 27 | @Test fun item_type_item_when_last_item() { 28 | 29 | val list : List = listOf("Item", "Item2", "Item3") 30 | val recycler = RecyclerViewAdapter(list) 31 | 32 | val result = recycler.getItemViewType(list.size - 1) 33 | 34 | assertEquals(1, result) 35 | } 36 | } -------------------------------------------------------------------------------- /newsfeed_android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | ext.kotlin_version = '1.6.21' 4 | repositories { 5 | google() 6 | mavenCentral() 7 | String storageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com" 8 | 9 | maven { 10 | url '../../flutter_nps/build/host/outputs/repo' 11 | } 12 | maven { 13 | url "$storageUrl/download.flutter.io" 14 | } 15 | 16 | } 17 | dependencies { 18 | classpath 'com.android.tools.build:gradle:7.4.2' 19 | classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21' 20 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 21 | 22 | // NOTE: Do not place your application dependencies here; they belong 23 | // in the individual module build.gradle files 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } -------------------------------------------------------------------------------- /newsfeed_android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /newsfeed_android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /newsfeed_android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Feb 03 12:28:34 CET 2022 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /newsfeed_android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /newsfeed_android/settings.gradle: -------------------------------------------------------------------------------- 1 | import org.gradle.api.initialization.resolve.RepositoriesMode 2 | 3 | dependencyResolutionManagement { 4 | repositoriesMode.set(RepositoriesMode.PREFER_PROJECT) 5 | repositories { 6 | google() 7 | mavenCentral() 8 | jcenter() // Warning: this repository is going to shut down soon 9 | } 10 | } 11 | rootProject.name = "newsfeed_android" 12 | include ':app' 13 | -------------------------------------------------------------------------------- /newsfeed_angular/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | -------------------------------------------------------------------------------- /newsfeed_angular/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /newsfeed_angular/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "ignorePatterns": [ 4 | "projects/**/*" 5 | ], 6 | "overrides": [ 7 | { 8 | "files": [ 9 | "*.ts" 10 | ], 11 | "parserOptions": { 12 | "project": [ 13 | "tsconfig.json" 14 | ], 15 | "createDefaultProgram": true 16 | }, 17 | "extends": [ 18 | "plugin:@angular-eslint/recommended", 19 | "plugin:@angular-eslint/template/process-inline-templates" 20 | ], 21 | "rules": { 22 | "@angular-eslint/directive-selector": [ 23 | "error", 24 | { 25 | "type": "attribute", 26 | "prefix": "app", 27 | "style": "camelCase" 28 | } 29 | ], 30 | "@angular-eslint/component-selector": [ 31 | "error", 32 | { 33 | "type": "element", 34 | "prefix": "app", 35 | "style": "kebab-case" 36 | } 37 | ] 38 | } 39 | }, 40 | { 41 | "files": [ 42 | "*.html" 43 | ], 44 | "extends": [ 45 | "plugin:@angular-eslint/template/recommended" 46 | ], 47 | "rules": {} 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /newsfeed_angular/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | 3 | /dist/ 4 | /bazel-out 5 | /integration/bazel/bazel-* 6 | *.log 7 | node_modules 8 | 9 | # Include when developing application packages. 10 | pubspec.lock 11 | .c9 12 | .idea/ 13 | .devcontainer/* 14 | !.devcontainer/README.md 15 | !.devcontainer/recommended-devcontainer.json 16 | !.devcontainer/recommended-Dockerfile 17 | .settings/ 18 | .vscode/launch.json 19 | .vscode/settings.json 20 | .vscode/tasks.json 21 | *.swo 22 | *.swp 23 | modules/.settings 24 | modules/.vscode 25 | .vimrc 26 | .nvimrc 27 | 28 | # Don't check in secret files 29 | *secret.js 30 | 31 | # Ignore npm/yarn debug log 32 | npm-debug.log 33 | yarn-error.log 34 | 35 | # build-analytics 36 | .build-analytics 37 | 38 | # rollup-test output 39 | /modules/rollup-test/dist/ 40 | 41 | # User specific bazel settings 42 | .bazelrc.user 43 | 44 | # User specific ng-dev settings 45 | .ng-dev.user* 46 | 47 | .notes.md 48 | baseline.json 49 | 50 | # Ignore .history for the xyz.local-history VSCode extension 51 | .history 52 | 53 | # Husky 54 | .husky/_ 55 | 56 | .angular 57 | 58 | # Flutter web copy 59 | web/ -------------------------------------------------------------------------------- /newsfeed_angular/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "singleQuote": true, 4 | "useTabs": false, 5 | "tabWidth": 2, 6 | "semi": true, 7 | "bracketSpacing": true 8 | } 9 | -------------------------------------------------------------------------------- /newsfeed_angular/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846 3 | "recommendations": ["angular.ng-template"] 4 | } 5 | -------------------------------------------------------------------------------- /newsfeed_angular/README.md: -------------------------------------------------------------------------------- 1 | # Newsfeed Angular App 2 | 3 | This project contains a sample Angular application that shows how to add a Flutter project into an Angular (web-based) project. 4 | 5 | https://user-images.githubusercontent.com/17708132/163605104-f21a539a-c4dc-4059-aca3-670f674ebcbb.mov 6 | 7 | ## Getting Started 8 | 9 | To add an existing Flutter Application into a web-based project you need to build your Flutter project for web. 10 | 11 | ## Import Flutter module to existing Angular app 12 | 13 | To use already created Flutter module download an artifacts from the [github repository Archive workflow ](https://github.com/VGVentures/take-flutter-home/actions/workflows/archive_workflow.yaml) and add them to your project at root directory. 14 | 15 | If you want to make the changes in the project follow 'Build' instructions bellow. 16 | 17 | ## Build 18 | 19 | To set up a Flutter web project check out [building a web application with Flutter](https://docs.flutter.dev/get-started/web) 20 | 21 | To build the web app run: 22 | 23 | ``` 24 | flutter build web 25 | ``` 26 | 27 | This generates the app, including the assets, and places the files into the `/build/web` directory of the project. 28 | 29 | #### Generate web for Flutter Module 30 | 31 | **Note**: The current version of Flutter doesn't support creating web projects for Flutter modules. 32 | To allow generating of a Flutter module web project, change this entry in `.metadata`: 33 | 34 | ``` 35 | - project_type: module 36 | + project_type: app 37 | ``` 38 | 39 | Run: 40 | 41 | ``` 42 | flutter create . --platforms web --org com.example.flutter_nps 43 | ``` 44 | 45 | Remove the automatically generated `widget_test.dart` file 46 | 47 | and build the app with: 48 | 49 | ``` 50 | flutter build web 51 | ``` 52 | 53 | ### Embedding Flutter in an Angular project 54 | 55 | For the Angular project to be able to discover the Flutter project, copy `/build/web` directory from the Flutter project and paste it into the `src` directory of the Angular project. 56 | 57 | In `src/web/index.html` change to 58 | 59 | **Note**: Flutter files need to be added in `angular.json` for Angular to be able to discover them: 60 | 61 | ``` 62 | ... 63 | "assets": [ 64 | "src/favicon.ico", 65 | "src/assets", 66 | "src/web" 67 | ], 68 | ... 69 | ``` 70 | 71 | To display the Flutter application in Html use `` tag with a defined `src` pointing to the `index.html` file of your project with the `src` folder as your root. 72 | 73 | ``` 74 | 75 | ``` 76 | 77 | Move to your Angular project directory and run: 78 | 79 | `npm install` or `npm install --legacy-peed-deps` depending on your npm dependencies. 80 | 81 | Finally run: 82 | 83 | `ng serve` 84 | -------------------------------------------------------------------------------- /newsfeed_angular/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "newsfeed_angular": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:application": { 10 | "strict": true 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/newsfeed_angular", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "assets": ["src/favicon.ico", "src/assets", "src/web"], 26 | "styles": [ 27 | "./node_modules/bootstrap/dist/css/bootstrap.min.css", 28 | "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", 29 | "src/styles.css" 30 | ], 31 | "scripts": ["./node_modules/bootstrap/dist/js/bootstrap.min.js"] 32 | }, 33 | "configurations": { 34 | "production": { 35 | "budgets": [ 36 | { 37 | "type": "initial", 38 | "maximumWarning": "500kb", 39 | "maximumError": "1mb" 40 | }, 41 | { 42 | "type": "anyComponentStyle", 43 | "maximumWarning": "2kb", 44 | "maximumError": "4kb" 45 | } 46 | ], 47 | "fileReplacements": [ 48 | { 49 | "replace": "src/environments/environment.ts", 50 | "with": "src/environments/environment.prod.ts" 51 | } 52 | ], 53 | "outputHashing": "all" 54 | }, 55 | "development": { 56 | "buildOptimizer": false, 57 | "optimization": false, 58 | "vendorChunk": true, 59 | "extractLicenses": false, 60 | "sourceMap": true, 61 | "namedChunks": true 62 | } 63 | }, 64 | "defaultConfiguration": "production" 65 | }, 66 | "serve": { 67 | "builder": "@angular-devkit/build-angular:dev-server", 68 | "configurations": { 69 | "production": { 70 | "browserTarget": "newsfeed_angular:build:production" 71 | }, 72 | "development": { 73 | "browserTarget": "newsfeed_angular:build:development" 74 | } 75 | }, 76 | "defaultConfiguration": "development" 77 | }, 78 | "extract-i18n": { 79 | "builder": "@angular-devkit/build-angular:extract-i18n", 80 | "options": { 81 | "browserTarget": "newsfeed_angular:build" 82 | } 83 | }, 84 | "test": { 85 | "builder": "@angular-devkit/build-angular:karma", 86 | "options": { 87 | "main": "src/test.ts", 88 | "polyfills": "src/polyfills.ts", 89 | "tsConfig": "tsconfig.spec.json", 90 | "karmaConfig": "karma.conf.js", 91 | "assets": ["src/favicon.ico", "src/assets"], 92 | "styles": ["./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", "src/styles.css"], 93 | "scripts": [] 94 | } 95 | }, 96 | "lint": { 97 | "builder": "@angular-eslint/builder:lint", 98 | "options": { 99 | "lintFilePatterns": ["src/**/*.ts", "src/**/*.html"] 100 | } 101 | } 102 | } 103 | } 104 | }, 105 | "cli": { 106 | "schematicCollections": [ 107 | "@angular-eslint/schematics" 108 | ] 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /newsfeed_angular/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/newsfeed_angular'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ], 34 | check: { 35 | global: { 36 | statements: 100, 37 | branches: 100, 38 | functions: 100, 39 | lines: 100 40 | } 41 | } 42 | }, 43 | reporters: ['progress', 'kjhtml'], 44 | port: 9876, 45 | colors: true, 46 | logLevel: config.LOG_INFO, 47 | autoWatch: true, 48 | browsers: ['Chrome'], 49 | singleRun: false, 50 | restartOnFileChange: true, 51 | customLaunchers: { 52 | ChromeHeadlessCustom: { 53 | base: 'ChromeHeadless', 54 | flags: ['--no-sandbox', '--disable-gpu'] 55 | } 56 | }, 57 | }); 58 | }; 59 | -------------------------------------------------------------------------------- /newsfeed_angular/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "newsfeed-app-angular", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "watch": "ng build --watch --configuration development", 9 | "test": "ng test", 10 | "build:ci": "ng build --configuration production", 11 | "test:ci": "ng test --watch=false --browsers=ChromeHeadlessCustom", 12 | "format:fix": "pretty-quick --staged", 13 | "precommit": "run-s format:fix lint", 14 | "lint": "ng lint", 15 | "format:check": "prettier --config ./.prettierrc --list-different \"src/{app,environments,assets}/**/*{.ts,.js,.json,.css,.scss}\"" 16 | }, 17 | "private": true, 18 | "dependencies": { 19 | "@angular/animations": "^14.1.3", 20 | "@angular/cdk": "^14.1.3", 21 | "@angular/common": "^14.1.3", 22 | "@angular/compiler": "^14.1.3", 23 | "@angular/core": "^14.1.3", 24 | "@angular/forms": "^14.1.3", 25 | "@angular/material": "^14.1.3", 26 | "@angular/platform-browser": "^14.1.3", 27 | "@angular/platform-browser-dynamic": "^14.1.3", 28 | "@angular/router": "^14.1.3", 29 | "@ng-bootstrap/ng-bootstrap": "^13.0.0", 30 | "bootstrap": "^5.2.0", 31 | "rxjs": "~7.5.6", 32 | "tslib": "^2.3.0", 33 | "zone.js": "~0.11.8" 34 | }, 35 | "devDependencies": { 36 | "@angular-devkit/build-angular": "^14.1.3", 37 | "@angular-eslint/builder": "14.0.0", 38 | "@angular-eslint/eslint-plugin": "14.0.2", 39 | "@angular-eslint/eslint-plugin-template": "14.0.2", 40 | "@angular-eslint/schematics": "14.0.2", 41 | "@angular-eslint/template-parser": "14.0.2", 42 | "@angular/cli": "^14.1.3", 43 | "@angular/compiler-cli": "^14.1.3", 44 | "@types/jasmine": "~4.0.3", 45 | "@types/node": "^18.7.9", 46 | "@typescript-eslint/eslint-plugin": "^5.29.0", 47 | "@typescript-eslint/parser": "^5.29.0", 48 | "eslint": "^8.22.0", 49 | "husky": "^8.0.1", 50 | "jasmine-core": "~4.3.0", 51 | "karma": "~6.4.0", 52 | "karma-chrome-launcher": "~3.1.0", 53 | "karma-coverage": "~2.2.0", 54 | "karma-jasmine": "~5.1.0", 55 | "karma-jasmine-html-reporter": "~2.0.0", 56 | "npm-run-all": "^4.1.5", 57 | "prettier": "^2.7.1", 58 | "pretty-quick": "^3.1.3", 59 | "puppeteer": "^16.2.0", 60 | "typescript": "~4.7.4" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | .header { 2 | font-size: 56px; 3 | line-height: 65px; 4 | height: 56px; 5 | font-weight: 600; 6 | } 7 | 8 | .padding-vertical-large { 9 | margin-top: 110px; 10 | margin-bottom: 55px; 11 | } 12 | 13 | .bold { 14 | font-weight: bold; 15 | } 16 | 17 | .dot { 18 | height: 18px; 19 | width: 18px; 20 | background-color: #2196f3; 21 | border-radius: 50%; 22 | display: inline-block; 23 | margin-left: 10px; 24 | } 25 | 26 | .iframe-overlay { 27 | position: fixed; 28 | top: 0; 29 | height: 100%; 30 | width: 100%; 31 | border: 0; 32 | padding: 0; 33 | } 34 | 35 | .background { 36 | background-color: black; 37 | opacity: 0.2; 38 | } 39 | 40 | .padding-top-50 { 41 | padding-top: 50px; 42 | } 43 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | newsfeed 4 | 5 |
6 |

Lorem ipsum

7 | 8 |
9 |
10 |
11 | 14 |
15 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { Type } from '@angular/core'; 2 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { AppComponent } from './app.component'; 4 | import { NewsService } from './shared/news/news.service'; 5 | 6 | describe('AppComponent', () => { 7 | let fixture: ComponentFixture; 8 | let app: AppComponent; 9 | let mockNewsService: NewsService; 10 | 11 | beforeEach(async () => { 12 | await TestBed.configureTestingModule({ 13 | declarations: [AppComponent], 14 | }).compileComponents(); 15 | 16 | mockNewsService = TestBed.inject(NewsService); 17 | fixture = TestBed.createComponent(AppComponent); 18 | app = fixture.componentInstance; 19 | }); 20 | 21 | it('should create the app.', () => { 22 | expect(app).toBeTruthy(); 23 | }); 24 | 25 | it('should display header and title when initialized', () => { 26 | const compiled = fixture.debugElement.nativeElement as HTMLElement; 27 | 28 | expect(compiled.querySelector('.header')?.textContent).toContain('newsfeed'); 29 | expect(compiled.querySelector('.title')?.textContent).toContain('Lorem ipsum'); 30 | }); 31 | 32 | it('should display endless scroll view component', () => { 33 | const compiled = fixture.debugElement.nativeElement as HTMLElement; 34 | 35 | expect(compiled.querySelector('#app-endless-scroll-view')).toBeDefined(); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { filter, Observable, Subscription, take } from 'rxjs'; 3 | import { NewsService } from './shared/news/news.service'; 4 | 5 | @Component({ 6 | selector: 'app-root', 7 | templateUrl: './app.component.html', 8 | styleUrls: ['./app.component.css'], 9 | }) 10 | export class AppComponent implements OnInit { 11 | isFlutterAppVisible = false; 12 | subscription$: Subscription | undefined; 13 | 14 | constructor(private newsService: NewsService) {} 15 | 16 | ngOnInit(): void { 17 | window.addEventListener('message', this.closeFlutterModal.bind(this), true); 18 | this.subscription$ = this.newsService.loading$ 19 | .pipe( 20 | filter((value) => value == true), 21 | take(1) 22 | ) 23 | .subscribe(() => (this.isFlutterAppVisible = true)); 24 | } 25 | 26 | closeFlutterModal(event: MessageEvent): void { 27 | if (event.data === 'close') { 28 | this.isFlutterAppVisible = false; 29 | } 30 | } 31 | 32 | ngOnDestory() { 33 | this.subscription$?.unsubscribe(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | 4 | import { AppComponent } from './app.component'; 5 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 6 | 7 | import { MatButtonModule } from '@angular/material/button'; 8 | import { EndlessScrollViewComponent } from './endless-scroll-view/endless-scroll-view.component'; 9 | import { NewsTileComponent } from './news-tile/news-tile.component'; 10 | 11 | import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; 12 | 13 | @NgModule({ 14 | declarations: [AppComponent, EndlessScrollViewComponent, NewsTileComponent], 15 | imports: [BrowserModule, BrowserAnimationsModule, MatButtonModule, MatProgressSpinnerModule], 16 | providers: [], 17 | bootstrap: [AppComponent], 18 | }) 19 | export class AppModule {} 20 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/endless-scroll-view/endless-scroll-view.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_angular/src/app/endless-scroll-view/endless-scroll-view.component.css -------------------------------------------------------------------------------- /newsfeed_angular/src/app/endless-scroll-view/endless-scroll-view.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/endless-scroll-view/endless-scroll-view.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; 2 | import { NewsService } from '../shared/news/news.service'; 3 | 4 | import { EndlessScrollViewComponent } from './endless-scroll-view.component'; 5 | 6 | describe('EndlessScrollViewComponent', () => { 7 | let component: EndlessScrollViewComponent; 8 | let fixture: ComponentFixture; 9 | let mockNewsService: NewsService; 10 | 11 | let scrollHeight = 100; 12 | let scrollPositionFromTop = 100; 13 | let scrollingViewHeight = 200; 14 | var htmlWindowData: any; 15 | 16 | beforeEach(async () => { 17 | await TestBed.configureTestingModule({ 18 | declarations: [EndlessScrollViewComponent], 19 | }).compileComponents(); 20 | mockNewsService = TestBed.inject(NewsService); 21 | htmlWindowData = { 22 | currentTarget: { window: { scrollY: scrollHeight } }, 23 | target: { scrollingElement: { scrollHeight: scrollingViewHeight, offsetHeight: scrollPositionFromTop } }, 24 | }; 25 | }); 26 | 27 | beforeEach(() => { 28 | fixture = TestBed.createComponent(EndlessScrollViewComponent); 29 | component = fixture.componentInstance; 30 | fixture.detectChanges(); 31 | }); 32 | 33 | it('should create', () => { 34 | expect(component).toBeTruthy(); 35 | }); 36 | 37 | it('should build app news tiles from news service', fakeAsync(() => { 38 | expect(fixture.debugElement.nativeElement.querySelectorAll('app-news-tile').length).toEqual(10); 39 | 40 | mockNewsService.loadMoreNews(); 41 | tick(2001); 42 | fixture.detectChanges(); 43 | 44 | expect(fixture.debugElement.nativeElement.querySelectorAll('app-news-tile').length).toEqual(20); 45 | })); 46 | 47 | it('should call loadMoreNews onScroll at the bottom', fakeAsync(() => { 48 | let spy = spyOn(mockNewsService, 'loadMoreNews').and.returnValue(); 49 | 50 | component.onScroll(htmlWindowData); 51 | 52 | expect(spy).toHaveBeenCalledTimes(1); 53 | })); 54 | 55 | it('should not call loadMoreNews onScroll when not reached bottom', fakeAsync(() => { 56 | htmlWindowData.target.scrollingElement.offsetHeight = 50; 57 | 58 | let spy = spyOn(mockNewsService, 'loadMoreNews').and.returnValue(); 59 | 60 | component.onScroll(htmlWindowData); 61 | 62 | expect(spy).not.toHaveBeenCalled(); 63 | })); 64 | }); 65 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/endless-scroll-view/endless-scroll-view.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, HostListener, Input, OnInit } from '@angular/core'; 2 | import { Observable } from 'rxjs'; 3 | import { NewsService } from '../shared/news/news.service'; 4 | 5 | @Component({ 6 | selector: 'app-endless-scroll-view', 7 | templateUrl: './endless-scroll-view.component.html', 8 | styleUrls: ['./endless-scroll-view.component.css'], 9 | }) 10 | export class EndlessScrollViewComponent implements OnInit { 11 | news$: Observable | undefined; 12 | 13 | constructor(private dataService: NewsService) {} 14 | 15 | ngOnInit(): void { 16 | this.news$ = this.dataService.getNews(); 17 | } 18 | 19 | @HostListener('window:scroll', ['$event']) 20 | onScroll(event: any) { 21 | const scrollBottom = event.currentTarget.window.scrollY + event.target.scrollingElement.offsetHeight; 22 | const viewHeight = event.target.scrollingElement.scrollHeight; 23 | 24 | if (scrollBottom >= viewHeight) { 25 | this.dataService.loadMoreNews(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/news-tile/news-tile.component.css: -------------------------------------------------------------------------------- 1 | .bubble { 2 | border-radius: 25px; 3 | border: 1px solid #c4c4c4; 4 | padding: 20px; 5 | margin-top: 20px; 6 | margin-bottom: 20px; 7 | } 8 | 9 | .square { 10 | height: 16px; 11 | width: 16px; 12 | background-color: #c4c4c4; 13 | margin-right: 10px; 14 | } 15 | 16 | .title { 17 | font-weight: bold; 18 | font-size: 24px; 19 | line-height: 28px; 20 | margin-top: 12px; 21 | margin-bottom: 12px; 22 | } 23 | 24 | .content { 25 | font-size: 18px; 26 | line-height: 24px; 27 | } 28 | 29 | .date { 30 | color: #4a4a4a; 31 | font-size: 12px; 32 | margin-top: 12px; 33 | margin-bottom: 12px; 34 | } 35 | 36 | .template-image { 37 | object-fit: contain; 38 | } 39 | 40 | .image-wrapper { 41 | width: 200px; 42 | } 43 | 44 | img { 45 | max-width: 100%; 46 | max-height: 100%; 47 | } 48 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/news-tile/news-tile.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 |
Lorem
7 |
8 |
9 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore 10 | magna aliqua. 11 |
12 |
13 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore 14 | magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 15 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 16 | pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est 17 | laborum 18 |
19 |
3 hours ago
20 |
21 |
22 | 23 |
24 |
25 |
26 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/news-tile/news-tile.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { NewsTileComponent } from './news-tile.component'; 4 | 5 | describe('NewsTileComponent', () => { 6 | let component: NewsTileComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [NewsTileComponent], 12 | }).compileComponents(); 13 | }); 14 | 15 | beforeEach(() => { 16 | fixture = TestBed.createComponent(NewsTileComponent); 17 | component = fixture.componentInstance; 18 | }); 19 | 20 | it('should create', () => { 21 | expect(component).toBeTruthy(); 22 | }); 23 | 24 | it('should set correct image on ngInit', () => { 25 | const numberInputs = [0, 1, 2, 3, 4, 5, 6]; 26 | const fileNameResults = [ 27 | 'assets/templateImage0.png', 28 | 'assets/templateImage1.png', 29 | 'assets/templateImage2.png', 30 | 'assets/templateImage3.png', 31 | 'assets/templateImage4.png', 32 | 'assets/templateImage0.png', 33 | 'assets/templateImage1.png', 34 | ]; 35 | 36 | numberInputs.forEach((input) => { 37 | component.newsId = input; 38 | component.ngOnInit(); 39 | 40 | expect(component.image).toEqual(fileNameResults[input]); 41 | }); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/news-tile/news-tile.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-news-tile', 5 | templateUrl: './news-tile.component.html', 6 | styleUrls: ['./news-tile.component.css'], 7 | }) 8 | export class NewsTileComponent implements OnInit { 9 | @Input() 10 | newsId: number | undefined; 11 | image: string | undefined; 12 | static imageName: string = 'assets/templateImage'; 13 | 14 | ngOnInit(): void { 15 | this.image = NewsTileComponent.imageName + ((this.newsId ?? 0) % 5).toString() + '.png'; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/shared/news/news.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { fakeAsync, TestBed, tick } from '@angular/core/testing'; 2 | 3 | import { NewsService } from './news.service'; 4 | 5 | describe('DataService', () => { 6 | let service: NewsService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(NewsService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | 17 | it('should return initial value on subscribe', () => { 18 | let initialData = Array.from(Array(10).keys()); 19 | 20 | let serviceData$ = service.getNews(); 21 | 22 | serviceData$.subscribe((result) => expect(result).toEqual(initialData)); 23 | }); 24 | 25 | it('should return 10 more items on load more', fakeAsync(() => { 26 | let initialData = Array.from(Array(10).keys()); 27 | let loadedMoreData = Array.from(Array(20).keys()); 28 | let fakeServiceDelay = 2000; 29 | 30 | let serviceData$ = service.getNews(); 31 | service.loadMoreNews(); 32 | tick(fakeServiceDelay + 1); 33 | 34 | serviceData$.subscribe((result) => expect(result).toEqual(loadedMoreData)); 35 | })); 36 | }); 37 | -------------------------------------------------------------------------------- /newsfeed_angular/src/app/shared/news/news.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { BehaviorSubject, delay, Observable, of } from 'rxjs'; 3 | 4 | @Injectable({ 5 | providedIn: 'root', 6 | }) 7 | export class NewsService { 8 | private _news: BehaviorSubject = new BehaviorSubject(Array.from(Array(10).keys())); 9 | readonly loading$ = new BehaviorSubject(false); 10 | 11 | loadMoreNews() { 12 | this.loading$.next(true); 13 | let newContent = Array.from(Array(10).keys()).map( 14 | (item) => item + this._news.value[this._news.value.length - 1] + 1 15 | ); 16 | var updatedNews = [...this._news.value, ...newContent]; 17 | let delayedObservable = of(updatedNews).pipe(delay(2000)); 18 | delayedObservable.subscribe((data) => { 19 | this._news.next(data); 20 | this.loading$.next(false); 21 | }); 22 | } 23 | 24 | getNews(): Observable { 25 | return this._news; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /newsfeed_angular/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_angular/src/assets/.gitkeep -------------------------------------------------------------------------------- /newsfeed_angular/src/assets/templateImage0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_angular/src/assets/templateImage0.png -------------------------------------------------------------------------------- /newsfeed_angular/src/assets/templateImage1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_angular/src/assets/templateImage1.png -------------------------------------------------------------------------------- /newsfeed_angular/src/assets/templateImage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_angular/src/assets/templateImage2.png -------------------------------------------------------------------------------- /newsfeed_angular/src/assets/templateImage3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_angular/src/assets/templateImage3.png -------------------------------------------------------------------------------- /newsfeed_angular/src/assets/templateImage4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_angular/src/assets/templateImage4.png -------------------------------------------------------------------------------- /newsfeed_angular/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | }; 4 | -------------------------------------------------------------------------------- /newsfeed_angular/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/plugins/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /newsfeed_angular/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_angular/src/favicon.ico -------------------------------------------------------------------------------- /newsfeed_angular/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angular Demo Home Page 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /newsfeed_angular/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /newsfeed_angular/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes recent versions of Safari, Chrome (including 12 | * Opera), Edge on the desktop, and iOS and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** 22 | * By default, zone.js will patch all possible macroTask and DomEvents 23 | * user can disable parts of macroTask/DomEvents patch by setting following flags 24 | * because those flags need to be set before `zone.js` being loaded, and webpack 25 | * will put import in the top of bundle, so user need to create a separate file 26 | * in this directory (for example: zone-flags.ts), and put the following flags 27 | * into that file, and then add the following code before importing zone.js. 28 | * import './zone-flags'; 29 | * 30 | * The flags allowed in zone-flags.ts are listed here. 31 | * 32 | * The following flags will work for all browsers. 33 | * 34 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 35 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 36 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 37 | * 38 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 39 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 40 | * 41 | * (window as any).__Zone_enable_cross_context_check = true; 42 | * 43 | */ 44 | 45 | /*************************************************************************************************** 46 | * Zone JS is required by default for Angular itself. 47 | */ 48 | import 'zone.js'; // Included with Angular CLI. 49 | 50 | 51 | /*************************************************************************************************** 52 | * APPLICATION IMPORTS 53 | */ 54 | -------------------------------------------------------------------------------- /newsfeed_angular/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | html, body { height: 100%; } 4 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } 5 | -------------------------------------------------------------------------------- /newsfeed_angular/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | (id: string): T; 13 | keys(): string[]; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting(), 21 | ); 22 | 23 | // Then we find all the tests. 24 | const context = require.context('./', true, /\.spec\.ts$/); 25 | // And load the modules. 26 | context.keys().map(context); 27 | -------------------------------------------------------------------------------- /newsfeed_angular/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /newsfeed_angular/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitOverride": true, 10 | "noPropertyAccessFromIndexSignature": true, 11 | "noImplicitReturns": true, 12 | "noFallthroughCasesInSwitch": true, 13 | "sourceMap": true, 14 | "declaration": false, 15 | "downlevelIteration": true, 16 | "experimentalDecorators": true, 17 | "moduleResolution": "node", 18 | "importHelpers": true, 19 | "target": "es2020", 20 | "module": "es2020", 21 | "lib": [ 22 | "es2020", 23 | "dom" 24 | ] 25 | }, 26 | "angularCompilerOptions": { 27 | "enableI18nLegacyMessageIdFormat": false, 28 | "strictInjectionParameters": true, 29 | "strictInputAccessModifiers": true, 30 | "strictTemplates": true 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /newsfeed_angular/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /newsfeed_ios/.gitignore: -------------------------------------------------------------------------------- 1 | /Pods 2 | Podfile.lock 3 | newsfeed_app.xcworkspace/xcuserdata -------------------------------------------------------------------------------- /newsfeed_ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | platform :ios, '11.0' 3 | 4 | target 'newsfeed_app' do 5 | # Comment the next line if you don't want to use dynamic frameworks 6 | use_frameworks! 7 | 8 | # Pods for newsfeed_app 9 | flutter_application_path = '../flutter_nps' 10 | load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb') 11 | install_all_flutter_pods(flutter_application_path) 12 | 13 | target 'newsfeed_appTests' do 14 | inherit! :search_paths 15 | # Pods for testing 16 | install_all_flutter_pods(flutter_application_path) 17 | end 18 | 19 | target 'newsfeed_appUITests' do 20 | # Pods for testing 21 | install_all_flutter_pods(flutter_application_path) 22 | end 23 | 24 | end 25 | 26 | post_install do |installer| 27 | flutter_post_install(installer) if defined?(flutter_post_install) 28 | end 29 | -------------------------------------------------------------------------------- /newsfeed_ios/README.md: -------------------------------------------------------------------------------- 1 | # Newsfeed iOS App 2 | 3 | This project contains a sample iOS application that shows how to embed the Flutter module into a native iOS project. 4 | 5 | https://user-images.githubusercontent.com/17708132/163604266-3e640917-6860-4592-baa4-2376335a8fc3.mov 6 | 7 | ## Getting Started 8 | 9 | **Important:** For instructions on integrating Flutter modules into your existing applications, 10 | see the [add-to-app documentation](https://flutter.dev/docs/development/add-to-app). 11 | 12 | ## Import Flutter module to existing iOS app 13 | 14 | First download two artifacts from the [github repository Swift CI workflow ](https://github.com/VGVentures/take-flutter-home/actions/workflows/ios_workflow.yaml) and add them to your project at root directory. 15 | 16 | 17 | 18 | 19 | Add below configuration to your `Podfile` target (on instruction how to setup cocoapods visit [cocoapods installation guide](https://guides.cocoapods.org/using/using-cocoapods.html)) 20 | 21 | ``` 22 | flutter_application_path = './ios-podhelper' 23 | load File.join(flutter_application_path, 'podhelper.rb') 24 | install_all_flutter_pods(flutter_application_path) 25 | ``` 26 | 27 | In Xcode project settings > Build Settings > Linking > Runpath Search Paths add `$(PROJECT_DIR)/flutter-framework/Release`. 28 | 29 | 30 | Run `pod install` and `pod update`. 31 | 32 | Add opening of the Flutter app to your application as shown in [example](https://github.com/VGVentures/take-flutter-home/blob/2db086b6b708e301c6562ceab37d933de3bd4254/newsfeed_ios/newsfeedApp/EndlessList.swift#L37). 33 | 34 | Run your iOS app using Xcode. 35 | 36 | ## Troubleshooting 37 | 38 | ### Error: 'framework not found FlutterPluginRegistrant' 39 | 40 | Usually it's missing path, make sure you added '$(PROJECT_DIR)/flutter-framework/Release' to your Runpath Search Paths. 41 | 42 | and run `pod update` 43 | 44 | ### Error: 'building for iOS Simulator, but linking in dylib built for macOS... for architecture x86_64' 45 | 46 | In Xcode project set 'Excluded Architectures' to `arm64` than run `pod install` 47 | 48 | ## Build 49 | 50 | You must run `flutter build ios-framework` every time you make code changes in your Flutter module. 51 | 52 | When you change the Flutter plugin dependencies in `flutter_nps/pubspec.yaml`, run `flutter pub get` in your Flutter module directory to refresh the list of plugins read by the podhelper.rb script. 53 | 54 | Then, run `pod install` again from your application at `newsfeed_ios/`. 55 | 56 | Open the xcworkspace in Xcode and run the app. 57 | 58 | ### Installing swift-format 59 | 60 | For the full guide on swift-format visit [swift-format GitHub repository](https://github.com/apple/swift-format#:~:text=swift%2Dformat%20provides%20the%20formatting,and%20invoked%20via%20an%20API.) 61 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/Assets.xcassets/TemplateImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Rectangle 474.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/Assets.xcassets/TemplateImage.imageset/Rectangle 474.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_ios/newsfeedApp/Assets.xcassets/TemplateImage.imageset/Rectangle 474.png -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/Assets.xcassets/TemplateImage2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "unsplash_MxVkWPiJALs (1).png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/Assets.xcassets/TemplateImage2.imageset/unsplash_MxVkWPiJALs (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_ios/newsfeedApp/Assets.xcassets/TemplateImage2.imageset/unsplash_MxVkWPiJALs (1).png -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/Assets.xcassets/TemplateImage3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "unsplash_Tk9m_HP4rgQ.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/Assets.xcassets/TemplateImage3.imageset/unsplash_Tk9m_HP4rgQ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_ios/newsfeedApp/Assets.xcassets/TemplateImage3.imageset/unsplash_Tk9m_HP4rgQ.png -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/ContentDataSource.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentDataSource.swift 3 | // newsfeed_app 4 | // 5 | 6 | import Combine 7 | import Foundation 8 | import SwiftUI 9 | 10 | @MainActor class ContentDataSource: ObservableObject { 11 | 12 | @Published var items: [Int] = Array(0...9) 13 | @Published var isLoadingPage = false 14 | private var currentPage = 1 15 | private var canLoadMorePages = true 16 | 17 | func loadMoreContentIfNeeded(currentItem item: Int?) { 18 | guard let item = item else { 19 | Task { 20 | await loadMoreContent() 21 | } 22 | return 23 | } 24 | 25 | let thresholdIndex = items.index(items.endIndex, offsetBy: -5) 26 | if items.first(where: { $0 == item }) == thresholdIndex { 27 | Task { 28 | await loadMoreContent() 29 | } 30 | } 31 | } 32 | 33 | private func loadMoreContent() async { 34 | guard !isLoadingPage && canLoadMorePages else { 35 | return 36 | } 37 | 38 | isLoadingPage = true 39 | 40 | // Mimic the network delay. 41 | do { 42 | try await Task.sleep(nanoseconds: 2_000_000_000) 43 | } catch {} 44 | 45 | canLoadMorePages = true 46 | items += Array(items.count...items.count+9) 47 | isLoadingPage = false 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // newsfeed_app 4 | // 5 | 6 | import Flutter 7 | import SwiftUI 8 | import UIKit 9 | 10 | struct ContentView: View { 11 | 12 | init() { 13 | UINavigationBar.appearance().barTintColor = .white 14 | } 15 | 16 | var body: some View { 17 | NavigationView { 18 | EndlessList() 19 | .background(.clear) 20 | .navigationBarTitleDisplayMode(.inline) 21 | .toolbar { 22 | ToolbarItem(placement: .principal) { 23 | HStack(alignment: .top) { 24 | Text("appName".localized()).font(.system(size: 24, weight: .bold)) 25 | Circle().frame(width: 8, height: 8) 26 | .foregroundColor(.blue) 27 | } 28 | } 29 | } 30 | } 31 | .navigationViewStyle(.stack) 32 | } 33 | } 34 | 35 | struct ContentViewPreviews: PreviewProvider { 36 | static var previews: some View { 37 | ContentView() 38 | .environmentObject(FlutterDependencies()) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/EndlessList.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EndlessList.swift 3 | // newsfeed_app 4 | // 5 | 6 | import Flutter 7 | import SwiftUI 8 | import UIKit 9 | 10 | struct EndlessList: View { 11 | 12 | @EnvironmentObject var flutterDependencies: FlutterDependencies 13 | 14 | @StateObject var dataSource = ContentDataSource() 15 | @State var wasOpened = false 16 | 17 | var body: some View { 18 | List { 19 | ForEach(dataSource.items, id: \.self) { item in 20 | RowItem(id: item) 21 | .onAppear { 22 | dataSource.loadMoreContentIfNeeded(currentItem: item) 23 | if item == 10 && wasOpened == false { 24 | openFlutterApp() 25 | wasOpened = true 26 | } 27 | }.listRowSeparator(.hidden) 28 | } 29 | if dataSource.isLoadingPage { 30 | HStack { 31 | Spacer() 32 | ProgressView() 33 | Spacer() 34 | } 35 | } 36 | } 37 | } 38 | 39 | func openFlutterApp() { 40 | // Get the RootViewController. 41 | guard 42 | let windowScene = UIApplication.shared.connectedScenes 43 | .first(where: { $0.activationState == .foregroundActive && $0 is UIWindowScene }) as? UIWindowScene, 44 | let window = windowScene.windows.first(where: \.isKeyWindow), 45 | let rootViewController = window.rootViewController 46 | else { return } 47 | 48 | // Create the FlutterViewController. 49 | let flutterViewController = FlutterViewController( 50 | engine: flutterDependencies.npsFlutterEngine, 51 | nibName: nil, 52 | bundle: nil) 53 | flutterViewController.modalPresentationStyle = .overCurrentContext 54 | flutterViewController.isViewOpaque = false 55 | 56 | rootViewController.present(flutterViewController, animated: true) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/NewsfeedApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NewsfeedApp.swift 3 | // newsfeed_app 4 | // 5 | 6 | import Flutter 7 | import FlutterPluginRegistrant 8 | import SwiftUI 9 | 10 | class FlutterDependencies: ObservableObject { 11 | let npsFlutterEngine = FlutterEngine(name: "flutter_nps_engine") 12 | 13 | init() { 14 | // Prepare a Flutter engine in advance. 15 | npsFlutterEngine.run() 16 | } 17 | } 18 | 19 | @main 20 | struct NewsfeedApp: App { 21 | 22 | // flutterDependencies will be injected using EnvironmentObject 23 | @StateObject var flutterDependencies = FlutterDependencies() 24 | 25 | var body: some Scene { 26 | WindowGroup { 27 | ContentView() 28 | .environmentObject(flutterDependencies) 29 | } 30 | } 31 | } 32 | 33 | extension String { 34 | func localized() -> String { 35 | return NSLocalizedString( 36 | self, tableName: "Localizable", bundle: .main, value: self, comment: self) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/RowItem.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RowItem.swift 3 | // newsfeed_app 4 | // 5 | 6 | import Foundation 7 | import SwiftUI 8 | import UIKit 9 | 10 | struct RowItem: View { 11 | let id: Int 12 | 13 | init(id: Int) { 14 | self.id = id 15 | } 16 | 17 | var body: some View { 18 | HStack { 19 | switch id % 3 { 20 | case 0: 21 | Image("TemplateImage").frame(alignment: .leading) 22 | case 1: 23 | Image("TemplateImage2").frame(alignment: .leading) 24 | default: 25 | Image("TemplateImage3").frame(alignment: .leading) 26 | } 27 | VStack(alignment: .leading, spacing: 8) { 28 | Text("category".localized()).font(.system(size: 18, weight: .bold)).foregroundColor(.gray) 29 | Text("content".localized()).font(.system(size: 16, weight: .bold)) 30 | HStack { 31 | Spacer() 32 | Text("date".localized()).frame(alignment: .trailing).font(.system(size: 16)) 33 | .foregroundColor(.gray) 34 | } 35 | }.padding(.leading, 16) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedApp/en.lproj/Localizable.strings: -------------------------------------------------------------------------------- 1 | /* 2 | Localizable.strings 3 | newsfeed_app 4 | */ 5 | 6 | "appName"="newsfeed"; 7 | "category"="Category"; 8 | "content"="Lorem ipsum dolor sit amet..."; 9 | "date"="13 Jan, 2022"; 10 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedAppTests/ContentDataSourceTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentDataSourceTests.swift 3 | // newsfeed_appTests 4 | // 5 | 6 | import XCTest 7 | 8 | @testable import newsfeed_app 9 | 10 | class ContentDataSourceTests: XCTestCase { 11 | 12 | func testHasItemsInitialized() async { 13 | let sut = await ContentDataSource() 14 | 15 | let count = await sut.items.count 16 | 17 | XCTAssertEqual(count, 10, "Bad initialization") 18 | } 19 | 20 | func testLoadMoreNotAddIfNotLastItemIndexGiven() async { 21 | let sut = await ContentDataSource() 22 | let lastIndex = await sut.items.count - 1 23 | XCTAssertNotEqual(8, lastIndex, "Last index given") 24 | 25 | await sut.loadMoreContentIfNeeded(currentItem: 8) 26 | 27 | let count = await sut.items.count 28 | XCTAssertEqual(count, 10, "Didnt load correct amount of items") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedAppUITests/NewsfeedAppUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NewsfeedAppUITests.swift 3 | // newsfeed_appUITests 4 | // 5 | 6 | import XCTest 7 | 8 | class NewsfeedAppUITests: XCTestCase { 9 | 10 | override func setUpWithError() throws { 11 | continueAfterFailure = false 12 | } 13 | 14 | func testViewWasLoadedCorrectly() throws { 15 | let app = XCUIApplication() 16 | app.launch() 17 | 18 | XCTAssertTrue(app.staticTexts.element(matching: .any, identifier: "newsfeed").exists) 19 | XCTAssertTrue(app.staticTexts.element(matching: .any, identifier: "Category").exists) 20 | XCTAssertTrue( 21 | app.staticTexts.element(matching: .any, identifier: "Lorem ipsum dolor sit amet...").exists) 22 | XCTAssertTrue(app.staticTexts.element(matching: .any, identifier: "13 Jan, 2022").exists) 23 | } 24 | 25 | func testLaunchPerformance() throws { 26 | if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { 27 | // This measures how long it takes to launch your application. 28 | measure(metrics: [XCTApplicationLaunchMetric()]) { 29 | XCUIApplication().launch() 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeedAppUITests/NewsfeedAppUITestsLaunchTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NewsfeedAppUITestsLaunchTests.swift 3 | // newsfeed_appUITests 4 | // 5 | 6 | import XCTest 7 | 8 | class NewsfeedAppUITestsLaunchTests: XCTestCase { 9 | 10 | override class var runsForEachTargetApplicationUIConfiguration: Bool { 11 | true 12 | } 13 | 14 | override func setUpWithError() throws { 15 | continueAfterFailure = false 16 | } 17 | 18 | func testLaunch() throws { 19 | let app = XCUIApplication() 20 | app.launch() 21 | 22 | // Insert steps here to perform after app launch but before taking a screenshot, 23 | // such as logging into a test account or navigating somewhere in the app 24 | 25 | let attachment = XCTAttachment(screenshot: app.screenshot()) 26 | attachment.name = "Launch Screen" 27 | attachment.lifetime = .keepAlways 28 | add(attachment) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeed_app.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeed_app.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeed_app.xcodeproj/project.xcworkspace/xcuserdata/janstepien.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_ios/newsfeed_app.xcodeproj/project.xcworkspace/xcuserdata/janstepien.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /newsfeed_ios/newsfeed_app.xcodeproj/xcshareddata/xcschemes/newsfeed_app.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeed_app.xcodeproj/xcshareddata/xcschemes/newsfeed_appTests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 54 | 60 | 61 | 63 | 64 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeed_app.xcodeproj/xcshareddata/xcschemes/newsfeed_appUITests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 54 | 60 | 61 | 67 | 68 | 69 | 70 | 72 | 73 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeed_app.xcodeproj/xcuserdata/janstepien.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | newsfeed_app.xcscheme_^#shared#^_ 8 | 9 | isShown 10 | 11 | orderHint 12 | 0 13 | 14 | newsfeed_appTests.xcscheme_^#shared#^_ 15 | 16 | isShown 17 | 18 | orderHint 19 | 1 20 | 21 | newsfeed_appUITests.xcscheme_^#shared#^_ 22 | 23 | isShown 24 | 25 | orderHint 26 | 8 27 | 28 | 29 | SuppressBuildableAutocreation 30 | 31 | 2B77B4EC27AAC75800D1FED3 32 | 33 | primary 34 | 35 | 36 | 2B77B4FC27AAC75900D1FED3 37 | 38 | primary 39 | 40 | 41 | 2B77B50627AAC75900D1FED3 42 | 43 | primary 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeed_app.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeed_app.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /newsfeed_ios/newsfeed_app.xcworkspace/xcuserdata/janstepien.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutter/put-flutter-to-work/724ffc6db1f2e892a50ea423f4378f3a17bc5a7b/newsfeed_ios/newsfeed_app.xcworkspace/xcuserdata/janstepien.xcuserdatad/UserInterfaceState.xcuserstate --------------------------------------------------------------------------------