diff --git a/.github/workflows/analyzer.yml b/.github/workflows/analyzer.yml index 378a4377..4eaba081 100644 --- a/.github/workflows/analyzer.yml +++ b/.github/workflows/analyzer.yml @@ -14,5 +14,6 @@ jobs: - uses: subosito/flutter-action@v2.8.0 with: channel: 'stable' - - run: flutter packages get - - run: flutter analyze + - run: ./tool/install_fvm.sh + - run: fvm flutter packages get + - run: fvm flutter analyze diff --git a/.github/workflows/rename_project.yml b/.github/workflows/rename_project.yml index 70b6ef96..b261808e 100644 --- a/.github/workflows/rename_project.yml +++ b/.github/workflows/rename_project.yml @@ -14,5 +14,6 @@ jobs: - uses: subosito/flutter-action@v2.8.0 with: channel: 'stable' - - run: flutter packages get - - run: printf 'Test Project\ndescription\ntest_project\nTestProject\ncom.test.project\nn\ny\n' | flutter pub run ./tool/dart_tool/rename_project.dart \ No newline at end of file + - run: ./tool/install_fvm.sh + - run: fvm flutter packages get + - run: printf 'Test Project\ndescription\ntest_project\nTestProject\ncom.test.project\nn\ny\n' | fvm flutter pub run ./tool/dart_tool/rename_project.dart \ No newline at end of file diff --git a/.github/workflows/strip_boilerplate_project.yaml b/.github/workflows/strip_boilerplate_project.yaml index 71cf9cb2..21f5baef 100644 --- a/.github/workflows/strip_boilerplate_project.yaml +++ b/.github/workflows/strip_boilerplate_project.yaml @@ -14,8 +14,8 @@ jobs: - uses: subosito/flutter-action@v2.8.0 with: channel: 'stable' - - run: flutter packages get - run: ./tool/install_fvm.sh + - run: fvm flutter packages get - run: printf 'yes\n' | fvm flutter pub run ./tool/dart_tool/strip_boilerplate_project.dart - run: fvm flutter analyze - run: fvm flutter test --update-goldens test/screen/home/home_screen_test.dart diff --git a/.github/workflows/strip_boilerplate_project_remove_tests.yaml b/.github/workflows/strip_boilerplate_project_remove_tests.yaml index 5a981fa2..7bb55685 100644 --- a/.github/workflows/strip_boilerplate_project_remove_tests.yaml +++ b/.github/workflows/strip_boilerplate_project_remove_tests.yaml @@ -14,7 +14,7 @@ jobs: - uses: subosito/flutter-action@v2.8.0 with: channel: 'stable' - - run: flutter packages get - run: ./tool/install_fvm.sh - - run: printf 'no\n' | flutter pub run ./tool/dart_tool/strip_boilerplate_project.dart - - run: flutter analyze + - run: fvm flutter packages get + - run: printf 'no\n' | fvm flutter pub run ./tool/dart_tool/strip_boilerplate_project.dart + - run: fvm flutter analyze diff --git a/README.md b/README.md index 8912ca23..50110cad 100644 --- a/README.md +++ b/README.md @@ -38,15 +38,14 @@ flutter: Command to run to update the translations ``` -flutter packages pub run icapps_translations +fvm flutter packages pub run icapps_translations ``` ## Json Serializable & Kiwi ``` -flutter packages pub run build_runner build -flutter packages pub run build_runner build --delete-conflicting-outputs -flutter packages pub run build_runner watch +fvm flutter packages pub run build_runner build --delete-conflicting-outputs +fvm flutter packages pub run build_runner watch ``` ## Environments @@ -54,9 +53,9 @@ flutter packages pub run build_runner watch ### Dev, Debug ``` -flutter run --flavor dev -t lib/main.dart +fvm flutter run --flavor dev -t lib/main.dart -flutter run --release --flavor dev -t lib/main.dart +fvm flutter run --release --flavor dev -t lib/main.dart ``` ### Dummy @@ -64,30 +63,30 @@ flutter run --release --flavor dev -t lib/main.dart Note: a hot reload is required after launch to use the correct launch file. ``` -flutter run --flavor dev -t lib/main_dummy.dart +fvm flutter run --flavor dev -t lib/main_dummy.dart -flutter run --release --flavor dev -t lib/main_dummy.dart +fvm flutter run --release --flavor dev -t lib/main_dummy.dart ``` ### Alpha ``` -flutter run --flavor alpha -t lib/main_alpha.dart +fvm flutter run --flavor alpha -t lib/main_alpha.dart -flutter run --release --flavor alpha -t lib/main_alpha.dart +fvm flutter run --release --flavor alpha -t lib/main_alpha.dart ``` ### Beta ``` -flutter run --flavor beta -t lib/main_beta.dart +fvm flutter run --flavor beta -t lib/main_beta.dart -flutter run --release --flavor beta -t lib/main_beta.dart +fvm flutter run --release --flavor beta -t lib/main_beta.dart ``` ### Prod, Release ``` -flutter run --flavor prod -t lib/main_prod.dart +fvm flutter run --flavor prod -t lib/main_prod.dart -flutter run --release --flavor prod -t lib/main_prod.dart +fvm flutter run --release --flavor prod -t lib/main_prod.dart ``` ## Niddler @@ -100,7 +99,7 @@ Niddler is also available for Android & Java (OkHttp: https://github.com/icapps/ ## Linting -To check your code matches our linting. The analysis_options.yaml contains all our code checks. +To check your code matches our linting. The `analysis_options.yaml` contains all our code checks. ``` flutter analyze @@ -111,13 +110,13 @@ flutter analyze In order to run our test we need to run ``` -flutter test +fvm flutter test ``` If we want to update our golden files we need to run ``` -flutter test --update-goldens +fvm flutter test --update-goldens ``` ## Fastlane @@ -135,15 +134,21 @@ This script will run a dart script. The dart script itself will ask you some inp #### Add provisioning files -``` -place the provisioning profiles -> provision_profile/** -naming should be the same as provided in the iOS/Configuration/** files (underscore will be replaced with a space in the configuration files) -``` +Add the provisioning profiles in the ios/provisioning/ folder. The naming of the files should be the same as provided in the `ios/Configuration/{flavor}.xcconfig` files (underscore will be replaced with a space in the configuration files) + +#### Firebase + +To setup firebase you will need to create a new firebase project with 8 new apps, 1 for each flavor on both iOS and Android. + +When creating the iOS apps on firebase you will be able to download a `GoogleService-Info.plist` file which you will need to rename according to the flavor you just created an app for e.g.: You just created the iOS App for the Dev flavor so your file should be named `GoogleService-Info-dev.plist`. +Each `.plist` file you download from firebase needs to be placed in the ios/Configuration/GoogleService/ folder. Whenever the project is run with a different flavor from the currently active flavor, it will automatically copy the correct `GoogleService-Info-{flavor}.plist` file into the ios/Runner/ folder. + +When creating the Android apps you will be able to download a `google-services.json` file, you only need to download this file once at the end of the last Android app setup on firebase. This `.json` file contains all the configurations for the 4 Android apps which you just created. Add the `.json` file in the android/app/src/ folder. #### Languages ``` -Configure the required languages in xCode +Configure the required languages in Xcode ``` ### icapps Translations @@ -157,34 +162,34 @@ Update the translations.py file (edit the todos) Obfuscation is enabled by default when using fastlane for building. The symbol files are stored in `./build/debug-info/#{options[:flavor]}` -**Important**: Add the following regex to jenking configuration to also archive the symbol files +**Important**: Add the following regex to jenkins configuration to also archive the symbol files ``` **/*.symbols ``` ### Icons -Replace the files in assets_launcher_icons/ +Replace the files in the `assets_launcher_icons/**` folder. -You can also change the adaptive_icon_background in the flutter_launcher_icons-{flavor}.yaml (currently "#CB2E63") (only available for Android 8.0 devices and above) +You can also change the adaptive_icon_background in the `flutter_launcher_icons-{flavor}.yaml` (currently "#CB2E63") (only available for Android 8.0 devices and above) After this, run the following command ``` -flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-dev.yaml +fvm flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-dev.yaml ``` ### Common issues ``` -No Flavor provided +No flavor provided ``` Add a flavor to your configuration. Extra info can be found in this issue -> https://github.com/icapps/flutter-template/issues/3 ### Questions? -For question contact Koen Van Looveren +For question contact William Verhaeghe ### Finish diff --git a/lib/model/exceptions/bad_request_error.dart b/lib/model/exceptions/bad_request_error.dart index 7e6e9060..1a3c9fbe 100644 --- a/lib/model/exceptions/bad_request_error.dart +++ b/lib/model/exceptions/bad_request_error.dart @@ -8,7 +8,7 @@ class BadRequestError extends NetworkError { static const statusCode = HttpStatus.badRequest; BadRequestError( - super.dioError, { + super.dioException, { super.statusCodeValue, }); @@ -25,7 +25,7 @@ class BadRequestError extends NetworkError { final dynamic data = err.response?.data; if (data is! Map) return BadRequestError(err); if (!data.containsKey('code')) return BadRequestError(err); - final code = data['code'] as String; + final code = data['code'] as String?; switch (code) { default: return BadRequestError(err); diff --git a/lib/model/exceptions/forbidden_error.dart b/lib/model/exceptions/forbidden_error.dart index e9f603a4..a6e73069 100644 --- a/lib/model/exceptions/forbidden_error.dart +++ b/lib/model/exceptions/forbidden_error.dart @@ -8,7 +8,7 @@ class ForbiddenError extends NetworkError { static const statusCode = HttpStatus.forbidden; ForbiddenError( - super.dioError, { + super.dioException, { super.statusCodeValue, }); @@ -25,7 +25,7 @@ class ForbiddenError extends NetworkError { final dynamic data = err.response?.data; if (data is! Map) return ForbiddenError(err); if (!data.containsKey('code')) return ForbiddenError(err); - final code = data['code'] as String; + final code = data['code'] as String?; switch (code) { default: return ForbiddenError(err); diff --git a/lib/model/exceptions/general_error.dart b/lib/model/exceptions/general_error.dart index 8f070100..38de4a1c 100644 --- a/lib/model/exceptions/general_error.dart +++ b/lib/model/exceptions/general_error.dart @@ -1,12 +1,9 @@ import 'package:flutter_template/util/locale/localization_keys.dart'; import 'package:icapps_architecture/icapps_architecture.dart'; -class GeneralNetworkError extends NetworkError { - GeneralNetworkError(super.dioError); +class GeneralError with LocalizedError { + GeneralError() : super(); @override String getLocalizedKey() => LocalizationKeys.errorGeneral; - - @override - String? get getErrorCode => null; } diff --git a/lib/model/exceptions/general_network_error.dart b/lib/model/exceptions/general_network_error.dart index 38de4a1c..9653f888 100644 --- a/lib/model/exceptions/general_network_error.dart +++ b/lib/model/exceptions/general_network_error.dart @@ -1,9 +1,12 @@ import 'package:flutter_template/util/locale/localization_keys.dart'; import 'package:icapps_architecture/icapps_architecture.dart'; -class GeneralError with LocalizedError { - GeneralError() : super(); +class GeneralNetworkError extends NetworkError { + GeneralNetworkError(super.dioException); @override String getLocalizedKey() => LocalizationKeys.errorGeneral; + + @override + String? get getErrorCode => null; } diff --git a/lib/model/exceptions/internal_server_error.dart b/lib/model/exceptions/internal_server_error.dart index 5a043857..d69949e7 100644 --- a/lib/model/exceptions/internal_server_error.dart +++ b/lib/model/exceptions/internal_server_error.dart @@ -7,7 +7,7 @@ class InternalServerError extends NetworkError { static const statusCode = HttpStatus.internalServerError; InternalServerError( - super.dioError, { + super.dioException, { super.statusCodeValue, }); diff --git a/lib/model/exceptions/no_internet_error.dart b/lib/model/exceptions/no_internet_error.dart index 24c6eda2..ba665ac6 100644 --- a/lib/model/exceptions/no_internet_error.dart +++ b/lib/model/exceptions/no_internet_error.dart @@ -2,7 +2,7 @@ import 'package:flutter_template/util/locale/localization_keys.dart'; import 'package:icapps_architecture/icapps_architecture.dart'; class NoInternetError extends NetworkError { - NoInternetError(super.dioError); + NoInternetError(super.dioException); @override String getLocalizedKey() => LocalizationKeys.errorNoNetwork; diff --git a/lib/model/exceptions/un_authorized_error.dart b/lib/model/exceptions/un_authorized_error.dart index 36095816..a2e57e62 100644 --- a/lib/model/exceptions/un_authorized_error.dart +++ b/lib/model/exceptions/un_authorized_error.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:dio/dio.dart'; import 'package:flutter_template/util/locale/localization_keys.dart'; import 'package:icapps_architecture/icapps_architecture.dart'; @@ -7,7 +8,7 @@ class UnAuthorizedError extends NetworkError { static const statusCode = HttpStatus.unauthorized; UnAuthorizedError( - super.dioError, { + super.dioException, { super.statusCodeValue, }); @@ -19,4 +20,15 @@ class UnAuthorizedError extends NetworkError { if (statusCodeValue == null) return '$statusCode'; return '$statusCode [$statusCodeValue]'; } + + static NetworkError parseError(DioException err) { + final dynamic data = err.response?.data; + if (data is! Map) return UnAuthorizedError(err); + if (!data.containsKey('code')) return UnAuthorizedError(err); + final code = data['code'] as String?; + switch (code) { + default: + return UnAuthorizedError(err); + } + } } diff --git a/lib/util/interceptor/network_error_interceptor.dart b/lib/util/interceptor/network_error_interceptor.dart index 28d2a185..0246aaef 100644 --- a/lib/util/interceptor/network_error_interceptor.dart +++ b/lib/util/interceptor/network_error_interceptor.dart @@ -2,7 +2,7 @@ import 'package:dio/dio.dart'; import 'package:flutter_template/model/exceptions/bad_request_error.dart'; import 'package:flutter_template/model/exceptions/code_error.dart'; import 'package:flutter_template/model/exceptions/forbidden_error.dart'; -import 'package:flutter_template/model/exceptions/general_error.dart'; +import 'package:flutter_template/model/exceptions/general_network_error.dart'; import 'package:flutter_template/model/exceptions/internal_server_error.dart'; import 'package:flutter_template/model/exceptions/no_internet_error.dart'; import 'package:flutter_template/model/exceptions/un_authorized_error.dart'; @@ -31,7 +31,7 @@ class NetworkErrorInterceptor extends SimpleInterceptor { final statusCode = error.response?.statusCode; switch (statusCode) { case UnAuthorizedError.statusCode: - return UnAuthorizedError(error); + return UnAuthorizedError.parseError(error); case BadRequestError.statusCode: return BadRequestError.parseError(error); case ForbiddenError.statusCode: diff --git a/lib/util/interceptor/network_log_interceptor.dart b/lib/util/interceptor/network_log_interceptor.dart index 7ab2d817..8099cc66 100644 --- a/lib/util/interceptor/network_log_interceptor.dart +++ b/lib/util/interceptor/network_log_interceptor.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:dio/dio.dart'; -import 'package:flutter_template/model/exceptions/general_error.dart'; +import 'package:flutter_template/model/exceptions/general_network_error.dart'; import 'package:icapps_architecture/icapps_architecture.dart'; import 'package:injectable/injectable.dart'; diff --git a/test/repository/refresh/refresh_repository_test.dart b/test/repository/refresh/refresh_repository_test.dart index c58ee11d..b7ede64e 100644 --- a/test/repository/refresh/refresh_repository_test.dart +++ b/test/repository/refresh/refresh_repository_test.dart @@ -1,5 +1,5 @@ import 'package:dio/dio.dart'; -import 'package:flutter_template/model/exceptions/general_network_error.dart'; +import 'package:flutter_template/model/exceptions/general_error.dart'; import 'package:flutter_template/model/exceptions/un_authorized_error.dart'; import 'package:flutter_template/repository/refresh/refresh_repository.dart'; import 'package:flutter_template/repository/secure_storage/auth/auth_storage.dart'; diff --git a/test/util/interceptor/network_error_interceptor_test.dart b/test/util/interceptor/network_error_interceptor_test.dart index 086cfe49..02c1e8be 100644 --- a/test/util/interceptor/network_error_interceptor_test.dart +++ b/test/util/interceptor/network_error_interceptor_test.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_template/model/exceptions/bad_request_error.dart'; import 'package:flutter_template/model/exceptions/code_error.dart'; import 'package:flutter_template/model/exceptions/forbidden_error.dart'; -import 'package:flutter_template/model/exceptions/general_error.dart'; +import 'package:flutter_template/model/exceptions/general_network_error.dart'; import 'package:flutter_template/model/exceptions/internal_server_error.dart'; import 'package:flutter_template/model/exceptions/un_authorized_error.dart'; import 'package:flutter_template/util/env/flavor_config.dart'; diff --git a/test/viewmodel/login/login_viewmodel_test.dart b/test/viewmodel/login/login_viewmodel_test.dart index 19bc9c41..98ea28e5 100644 --- a/test/viewmodel/login/login_viewmodel_test.dart +++ b/test/viewmodel/login/login_viewmodel_test.dart @@ -1,4 +1,4 @@ -import 'package:flutter_template/model/exceptions/general_network_error.dart'; +import 'package:flutter_template/model/exceptions/general_error.dart'; import 'package:flutter_template/navigator/main_navigator.dart'; import 'package:flutter_template/navigator/onboarding_navigator.dart'; import 'package:flutter_template/repository/login/login_repository.dart'; diff --git a/test/viewmodel/todo/todo_list/todo_list_viewmodel_test.dart b/test/viewmodel/todo/todo_list/todo_list_viewmodel_test.dart index 06deb86c..fbce3e79 100644 --- a/test/viewmodel/todo/todo_list/todo_list_viewmodel_test.dart +++ b/test/viewmodel/todo/todo_list/todo_list_viewmodel_test.dart @@ -1,4 +1,4 @@ -import 'package:flutter_template/model/exceptions/general_network_error.dart'; +import 'package:flutter_template/model/exceptions/general_error.dart'; import 'package:flutter_template/model/webservice/todo/todo.dart'; import 'package:flutter_template/navigator/main_navigator.dart'; import 'package:flutter_template/repository/todo/todo_repository.dart'; diff --git a/tool/rename_project.sh b/tool/rename_project.sh index e09dde45..398c5b0f 100755 --- a/tool/rename_project.sh +++ b/tool/rename_project.sh @@ -1,3 +1,3 @@ #!/bin/bash -flutter pub run tool/dart_tool/rename_project.dart \ No newline at end of file +fvm flutter pub run tool/dart_tool/rename_project.dart \ No newline at end of file diff --git a/tool/strip_boilerplate_project.sh b/tool/strip_boilerplate_project.sh index 4a4cb0bc..9a2a358b 100755 --- a/tool/strip_boilerplate_project.sh +++ b/tool/strip_boilerplate_project.sh @@ -1,3 +1,3 @@ #!/bin/bash -flutter pub run tool/dart_tool/strip_boilerplate_project.dart \ No newline at end of file +fvm flutter pub run tool/dart_tool/strip_boilerplate_project.dart \ No newline at end of file