From c2c4719d266b15ed99805a2399cdf2cc8fb56a71 Mon Sep 17 00:00:00 2001 From: faiyyazs Date: Mon, 29 Aug 2022 08:59:59 +0530 Subject: [PATCH] Precommit hooks, readme updates --- README.md | 29 ++++++++++++++----- app/lib/di/states/viewmodels.dart | 1 - app/lib/entrypoints/main_prod.dart | 2 +- app/lib/feature/splash/splash_page.dart | 1 + app/lib/feature/splash/splash_page_model.dart | 7 ++--- app/lib/feature/splash/splash_page_view.dart | 1 - app/lib/flavors/flavor.dart | 2 +- app/lib/flavors/flavor_values.dart | 1 - app/lib/main.dart | 2 +- app/lib/myapp.dart | 13 ++++++--- app/lib/navigation/app_router.dart | 2 +- app/scripts/hooks/pre-commit.sh | 2 +- app/scripts/setup-hooks.sh | 2 +- core/data/example/data_example.dart | 1 - core/data/test/data_test.dart | 1 - core/domain/example/domain_example.dart | 1 - core/domain/lib/src/usecase/base/params.dart | 2 +- core/domain/test/domain_test.dart | 1 - .../lib/src/model/error/database_error.dart | 2 +- .../lib/src/model/error/network_error.dart | 4 +-- .../example/dependency_injection_example.dart | 1 - .../example/localisation_example.dart | 1 - localisation/test/localisation_test.dart | 2 -- services/test/services_test.dart | 1 - .../lib/src/base_page_state.dart | 2 +- .../statemanagement_riverpod_example.dart | 1 - .../lib/src/base_page.dart | 2 +- themes/example/themes_example.dart | 1 - themes/lib/src/theme_manager.dart | 10 +++---- 29 files changed, 50 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index de19a4b..cab008b 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Here are some things you need to prepare before this Boilerplate setup: 3. Visual Studio Code (Optional) [Install](https://code.visualstudio.com/) 4. **Dart** and **Flutter** extensions: - **Intellij Platform** users ([Dart](https://plugins.jetbrains.com/plugin/6351-dart), [Flutter](https://plugins.jetbrains.com/plugin/9212-flutter) ) - - **Visual Studio Code** users ([Dart](https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code), [Flutter](https://marketplace.visualstudio.com /items?itemName=Dart-Code.flutter) ) + - **Visual Studio Code** users ([Dart](https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code), [Flutter](https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter) ) #### Setup @@ -87,17 +87,23 @@ Sensitive information like api keys, credentials, etc should not be checked into #### Get Dependencies -``` +```bash flutter pub get ``` #### Run Code Generation +```bash +bash app/scripts/generate-all.sh ``` -bash scripts/generate-all.sh + +#### Setup Hooks + +```bash +bash app/scripts/setup-hooks.sh ``` -Read the [scripts documentation](app/scripts/README.md) to learn about all the scrips used in the project. +Read the [scripts documentation](app/scripts/README.md) to learn about all the scripts used in the project. @@ -144,7 +150,7 @@ You can setup any environment specific values in the respective `main.dart` file To run a specific flavor you need to specify the flavor and target file. -```sh +```bash flutter run --flavor qa -t lib/entrypoints/main_qa.dart ``` @@ -197,6 +203,11 @@ In Visual Studio Code, navigate to `Preferences` -> `Settings` and search for `F - [Localisation](./localisation/) - Routing/Navigations - [Responsive Framework](./wiki/responsive-framework/RESPONSIVE_FRAMEWORK.md) +- Pre-commit Checks + - Dart Analysis + - [Dart Fix](https://github.com/dart-lang/sdk/blob/main/pkg/dartdev/doc/dart-fix.md) + - Flutter Format + @@ -267,7 +278,7 @@ For the android CD workflow to run, we need to perform the following setup steps - Follow these instructions to [generate an upload keystore](https://developer.android.com/studio/publish/app-signing#generate-key). Note down the `store password`, `key alias` and `key password`. You will need these in later steps. - Use `openssl` to convert the `jks` file to `Base64`. -``` +```bash openssl base64 < app_key.jks | tr -d '\n' | tee app_key_encoded.txt ``` @@ -305,7 +316,8 @@ We will divide the guide into steps so that it is easier to understand - Replace `PROVISIONING PROFILE NAME` with your Provisioning Profile Name (You already created one in Step 2, use that) - Replace `TEAM_ID` with your team id. Look at [this](https://stackoverflow.com/a/18727947) answer on "How to find your Team ID" - Click to View Template +
+Click to View Template ```xml @@ -338,6 +350,7 @@ We will divide the guide into steps so that it is easier to understand ``` +
Create a new file called `options.plist` and save the above contents in that file @@ -364,7 +377,7 @@ We will divide the guide into steps so that it is easier to understand - To generate a base64 string, use the following command, replacing `FILENAME` with your filename -``` +```bash openssl base64 < FILENAME | tr -d '\n' | tee ENCODED_FILENAME.txt ``` diff --git a/app/lib/di/states/viewmodels.dart b/app/lib/di/states/viewmodels.dart index 4698c80..6329b72 100644 --- a/app/lib/di/states/viewmodels.dart +++ b/app/lib/di/states/viewmodels.dart @@ -3,7 +3,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../dependencies.dart'; - final splashViewModelProvider = ChangeNotifierProvider.autoDispose( (ref) => SplashViewModel(getIt.get(instanceName: "BaseUrl")), diff --git a/app/lib/entrypoints/main_prod.dart b/app/lib/entrypoints/main_prod.dart index 915afef..124e062 100644 --- a/app/lib/entrypoints/main_prod.dart +++ b/app/lib/entrypoints/main_prod.dart @@ -13,4 +13,4 @@ void main() { ), ); startApp(); -} \ No newline at end of file +} diff --git a/app/lib/feature/splash/splash_page.dart b/app/lib/feature/splash/splash_page.dart index 45a02f8..38a0a07 100644 --- a/app/lib/feature/splash/splash_page.dart +++ b/app/lib/feature/splash/splash_page.dart @@ -14,6 +14,7 @@ class SplashPage extends BasePage { } class SplashPageState extends BaseStatefulPage { + @override ProviderBase provideBase() { return splashViewModelProvider; } diff --git a/app/lib/feature/splash/splash_page_model.dart b/app/lib/feature/splash/splash_page_model.dart index d8a4a83..91bfbb0 100644 --- a/app/lib/feature/splash/splash_page_model.dart +++ b/app/lib/feature/splash/splash_page_model.dart @@ -3,12 +3,9 @@ import 'package:injectable/injectable.dart'; @injectable class SplashViewModel extends BasePageViewModel { - final String myBaseUrl; - SplashViewModel(@factoryParam this.myBaseUrl){ - print("My First log in Splash ${this.myBaseUrl}"); + SplashViewModel(@factoryParam this.myBaseUrl) { + print("My First log in Splash $myBaseUrl"); } - - } diff --git a/app/lib/feature/splash/splash_page_view.dart b/app/lib/feature/splash/splash_page_view.dart index 48f42c4..b4eed57 100644 --- a/app/lib/feature/splash/splash_page_view.dart +++ b/app/lib/feature/splash/splash_page_view.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:statemanagement_riverpod/statemanagement_riverpod.dart'; diff --git a/app/lib/flavors/flavor.dart b/app/lib/flavors/flavor.dart index 197a029..4ffe833 100644 --- a/app/lib/flavors/flavor.dart +++ b/app/lib/flavors/flavor.dart @@ -2,4 +2,4 @@ enum Flavor { dev, qa, prod, -} \ No newline at end of file +} diff --git a/app/lib/flavors/flavor_values.dart b/app/lib/flavors/flavor_values.dart index d9a9e78..16511a8 100644 --- a/app/lib/flavors/flavor_values.dart +++ b/app/lib/flavors/flavor_values.dart @@ -18,4 +18,3 @@ class FlavorValues { bool get logSqlStatements => _logSqlStatements; } - diff --git a/app/lib/main.dart b/app/lib/main.dart index f15e6a2..aae1f7f 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -11,4 +11,4 @@ import 'package:app/entrypoints/main_dev.dart' as entrypoint; /// until a fix is released. void main() { entrypoint.main(); -} \ No newline at end of file +} diff --git a/app/lib/myapp.dart b/app/lib/myapp.dart index 8968829..6a671f9 100644 --- a/app/lib/myapp.dart +++ b/app/lib/myapp.dart @@ -13,19 +13,24 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return ThemeBuilder( themes: [ - ThemeData(backgroundColor: Colors.red, accentColor: Colors.blue), + ThemeData( + backgroundColor: Colors.red, + colorScheme: + ColorScheme.fromSwatch().copyWith(secondary: Colors.blue)), ], darkTheme: ThemeData( brightness: Brightness.dark, backgroundColor: Colors.blue[700], - accentColor: Colors.yellow[700], + colorScheme: + ColorScheme.fromSwatch().copyWith(secondary: Colors.yellow[700]), ), lightTheme: ThemeData( brightness: Brightness.light, backgroundColor: Colors.blue[300], - accentColor: Colors.yellow[300], + colorScheme: + ColorScheme.fromSwatch().copyWith(secondary: Colors.yellow[300]), ), - builder: (context, regularTheme, darkTheme, themeMode) => MaterialApp( + builder: (context, regularTheme, darkTheme, themeMode) => MaterialApp( navigatorKey: AppService.navigatorKey, builder: (context, widget) => ResponsiveWrapper.builder( ClampingScrollWrapper.builder(context, widget!), diff --git a/app/lib/navigation/app_router.dart b/app/lib/navigation/app_router.dart index e12bd9e..e594aee 100644 --- a/app/lib/navigation/app_router.dart +++ b/app/lib/navigation/app_router.dart @@ -8,7 +8,7 @@ class AppRouter { switch (settings.name) { case RoutePaths.Splash: return CupertinoPageRoute( - builder: (context) => SplashPage(), + builder: (context) => const SplashPage(), settings: const RouteSettings(name: RoutePaths.Splash)); default: diff --git a/app/scripts/hooks/pre-commit.sh b/app/scripts/hooks/pre-commit.sh index a13c57f..cb10c29 100755 --- a/app/scripts/hooks/pre-commit.sh +++ b/app/scripts/hooks/pre-commit.sh @@ -13,6 +13,6 @@ else echo "Static analysis failed. Running dart fix." dart fix --apply echo "Static analysis failed. Running flutter format" - flutter format lib + flutter format app/lib exit 1 fi \ No newline at end of file diff --git a/app/scripts/setup-hooks.sh b/app/scripts/setup-hooks.sh index 751150c..1d57818 100755 --- a/app/scripts/setup-hooks.sh +++ b/app/scripts/setup-hooks.sh @@ -8,4 +8,4 @@ echo All hooks marked as executable echo Moving all hooks to .git/hooks/ -rsync -P scripts/hooks/* .git/hooks/ \ No newline at end of file +rsync -P app/scripts/hooks/* .git/hooks/ \ No newline at end of file diff --git a/core/data/example/data_example.dart b/core/data/example/data_example.dart index a15556e..a5eb090 100644 --- a/core/data/example/data_example.dart +++ b/core/data/example/data_example.dart @@ -1,4 +1,3 @@ -import 'package:data/data.dart'; void main() { diff --git a/core/data/test/data_test.dart b/core/data/test/data_test.dart index 474fc36..8ca0ec5 100644 --- a/core/data/test/data_test.dart +++ b/core/data/test/data_test.dart @@ -1,4 +1,3 @@ -import 'package:data/data.dart'; import 'package:test/test.dart'; void main() { diff --git a/core/domain/example/domain_example.dart b/core/domain/example/domain_example.dart index 2b8e48f..a5eb090 100644 --- a/core/domain/example/domain_example.dart +++ b/core/domain/example/domain_example.dart @@ -1,4 +1,3 @@ -import 'package:domain/domain.dart'; void main() { diff --git a/core/domain/lib/src/usecase/base/params.dart b/core/domain/lib/src/usecase/base/params.dart index 5f8900e..7f2cbd5 100644 --- a/core/domain/lib/src/usecase/base/params.dart +++ b/core/domain/lib/src/usecase/base/params.dart @@ -4,7 +4,7 @@ import 'package:shared/shared.dart'; abstract class Params { final bool reloading; - Params({this.reloading: false}); + Params({this.reloading = false}); Either verify(); } diff --git a/core/domain/test/domain_test.dart b/core/domain/test/domain_test.dart index 1c54494..a28c47c 100644 --- a/core/domain/test/domain_test.dart +++ b/core/domain/test/domain_test.dart @@ -1,4 +1,3 @@ -import 'package:domain/domain.dart'; import 'package:test/test.dart'; void main() { diff --git a/core/shared/lib/src/model/error/database_error.dart b/core/shared/lib/src/model/error/database_error.dart index c501ac1..8d2242c 100644 --- a/core/shared/lib/src/model/error/database_error.dart +++ b/core/shared/lib/src/model/error/database_error.dart @@ -14,7 +14,7 @@ class DatabaseError extends BaseError { @override String getFriendlyMessage() { - return "${error.message}"; + return error.message; } @override diff --git a/core/shared/lib/src/model/error/network_error.dart b/core/shared/lib/src/model/error/network_error.dart index 2ed4e31..04794a2 100644 --- a/core/shared/lib/src/model/error/network_error.dart +++ b/core/shared/lib/src/model/error/network_error.dart @@ -6,13 +6,13 @@ import 'base_error.dart'; class NetworkError extends BaseError { NetworkError({ required int httpError, - String message: "", + String message = "", required Exception cause, }) : super(error: ErrorInfo(code: httpError, message: message), cause: cause); @override String getFriendlyMessage() { - return "${this.error.message}"; + return error.message; } @override diff --git a/dependency-injection/example/dependency_injection_example.dart b/dependency-injection/example/dependency_injection_example.dart index 96e3183..a5eb090 100644 --- a/dependency-injection/example/dependency_injection_example.dart +++ b/dependency-injection/example/dependency_injection_example.dart @@ -1,4 +1,3 @@ -import 'package:dependency_injection/dependency_injection.dart'; void main() { diff --git a/localisation/example/localisation_example.dart b/localisation/example/localisation_example.dart index e69432c..a5eb090 100644 --- a/localisation/example/localisation_example.dart +++ b/localisation/example/localisation_example.dart @@ -1,4 +1,3 @@ -import 'package:localisation/strings.dart'; void main() { diff --git a/localisation/test/localisation_test.dart b/localisation/test/localisation_test.dart index 289a3a8..a5eb090 100644 --- a/localisation/test/localisation_test.dart +++ b/localisation/test/localisation_test.dart @@ -1,5 +1,3 @@ -import 'package:localisation/strings.dart'; -import 'package:test/test.dart'; void main() { diff --git a/services/test/services_test.dart b/services/test/services_test.dart index 5a57aff..02913a8 100644 --- a/services/test/services_test.dart +++ b/services/test/services_test.dart @@ -1,4 +1,3 @@ -import 'package:services/services.dart'; import 'package:test/test.dart'; void main() { diff --git a/statemanagement-core/lib/src/base_page_state.dart b/statemanagement-core/lib/src/base_page_state.dart index ddcef31..176e3f1 100644 --- a/statemanagement-core/lib/src/base_page_state.dart +++ b/statemanagement-core/lib/src/base_page_state.dart @@ -32,7 +32,7 @@ abstract class CoreBasePageState extends State backgroundColor: scaffoldBackgroundColor(), appBar: buildAppbar(), extendBodyBehindAppBar: extendBodyBehindAppBar(), - body: buildScaffoldBody(context, _viewModel!), + body: buildScaffoldBody(context, _viewModel as VM), drawer: buildDrawer(), drawerEnableOpenDragGesture: drawerEnableOpenDragGesture(), bottomNavigationBar: buildBottomNavigationBar(), diff --git a/statemanagement-riverpod/example/statemanagement_riverpod_example.dart b/statemanagement-riverpod/example/statemanagement_riverpod_example.dart index d255edd..a5eb090 100644 --- a/statemanagement-riverpod/example/statemanagement_riverpod_example.dart +++ b/statemanagement-riverpod/example/statemanagement_riverpod_example.dart @@ -1,4 +1,3 @@ -import 'package:statemanagement_riverpod/statemanagement_riverpod.dart'; void main() { diff --git a/statemanagement-riverpod/lib/src/base_page.dart b/statemanagement-riverpod/lib/src/base_page.dart index 55f41e1..a5f8ea4 100644 --- a/statemanagement-riverpod/lib/src/base_page.dart +++ b/statemanagement-riverpod/lib/src/base_page.dart @@ -40,7 +40,7 @@ abstract class BasePageViewWidget extends Widget { @override DataProviderElement createElement() => - DataProviderElement(this, this.providerBase); + DataProviderElement(this, providerBase); } class DataProviderElement diff --git a/themes/example/themes_example.dart b/themes/example/themes_example.dart index 50dce5d..a5eb090 100644 --- a/themes/example/themes_example.dart +++ b/themes/example/themes_example.dart @@ -1,4 +1,3 @@ -import 'package:themes/src/theme_manager.dart'; void main() { diff --git a/themes/lib/src/theme_manager.dart b/themes/lib/src/theme_manager.dart index bb14572..188e060 100644 --- a/themes/lib/src/theme_manager.dart +++ b/themes/lib/src/theme_manager.dart @@ -69,7 +69,7 @@ class ThemeManager { int? get selectedThemeIndex { if (themes != null && themes!.isNotEmpty) { int? themeIndex = _sharedPreferences.themeIndex; - return themeIndex == null ? 0 : themeIndex; + return themeIndex ?? 0; } return null; } @@ -86,7 +86,7 @@ class ThemeManager { var hasMultipleThemes = themes != null && themes!.length > 1; var hasLightAndDarkThemes = darkTheme != null && lightTheme != null; assert(hasMultipleThemes || hasLightAndDarkThemes, - '''You have to supply themes if you want to use themes. You have supplied no themes. Don\'t do that. Supply themes. + '''You have to supply themes if you want to use themes. You have supplied no themes. Don't do that. Supply themes. You can supply either a list of ThemeData objects to the themes property or a lightTheme and a darkTheme to be swapped between. '''); @@ -128,13 +128,13 @@ You can supply either a list of ThemeData objects to the themes property or a li updateOverlayColors(selectedTheme); } - ThemeModel _currTheme = ThemeModel( + ThemeModel currTheme = ThemeModel( selectedTheme: selectedTheme, darkTheme: darkTheme, themeMode: _selectedThemeMode); - _themesController = BehaviorSubject.seeded(_currTheme); - _initialTheme = _currTheme; + _themesController = BehaviorSubject.seeded(currTheme); + _initialTheme = currTheme; ThemeService.getInstance().setThemeManager(this); }