diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ee42575..7d34cfb 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,4 +12,25 @@ updates: - package-ecosystem: 'pub' directory: '/' schedule: - interval: 'weekly' + interval: 'daily' + open-pull-requests-limit: 2 + - package-ecosystem: 'github-actions' + directory: '/' + schedule: + interval: 'daily' + open-pull-requests-limit: 2 + - package-ecosystem: 'bundler' + directory: '/' + schedule: + interval: 'daily' + open-pull-requests-limit: 2 + - package-ecosystem: 'bundler' + directory: '/ios/' + schedule: + interval: 'daily' + open-pull-requests-limit: 2 + - package-ecosystem: 'bundler' + directory: '/android/' + schedule: + interval: 'daily' + open-pull-requests-limit: 2 diff --git a/.github/workflows/flutter-ci.yml b/.github/workflows/flutter-ci.yml index 2cbb614..e2b8f0c 100644 --- a/.github/workflows/flutter-ci.yml +++ b/.github/workflows/flutter-ci.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-java@v2 + - uses: actions/setup-java@v3 with: distribution: 'zulu' java-version: '11' @@ -28,19 +28,23 @@ jobs: - name: Install FVM && Flutter run: dart pub global activate fvm --verbose && fvm install --verbose && fvm use --force --verbose - name: Get dependencies - uses: maierj/fastlane-action@v2.2.0 + uses: maierj/fastlane-action@v2.3.0 with: lane: 'fetch_dependencies' - name: 'Run lints' - uses: maierj/fastlane-action@v2.2.0 + uses: maierj/fastlane-action@v2.3.0 with: lane: 'lints' + - name: 'Check generated code' + uses: maierj/fastlane-action@v2.3.0 + with: + lane: 'ensure_no_change_in_generated_code' - name: 'Run tests' - uses: maierj/fastlane-action@v2.2.0 + uses: maierj/fastlane-action@v2.3.0 with: lane: 'tests' - name: 'Build android app' - uses: maierj/fastlane-action@v2.2.0 + uses: maierj/fastlane-action@v2.3.0 with: lane: 'android build_dev_debug_apk' subdirectory: 'android' diff --git a/.gitignore b/.gitignore index a0d3406..c9750aa 100644 --- a/.gitignore +++ b/.gitignore @@ -57,4 +57,4 @@ app.*.map.json **/fastlane/Preview.html **/fastlane/screenshots **/fastlane/test_output - +.bundle/ diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..ef538c2 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.1.2 diff --git a/Gemfile.lock b/Gemfile.lock index a3c5635..60b4f8f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,8 +8,8 @@ GEM artifactory (3.0.15) atomos (0.1.3) aws-eventstream (1.2.0) - aws-partitions (1.633.0) - aws-sdk-core (3.151.0) + aws-partitions (1.644.0) + aws-sdk-core (3.159.0) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.525.0) aws-sigv4 (~> 1.1) @@ -21,7 +21,7 @@ GEM aws-sdk-core (~> 3, >= 3.127.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.4) - aws-sigv4 (1.5.1) + aws-sigv4 (1.5.2) aws-eventstream (~> 1, >= 1.0.2) babosa (1.0.4) claide (1.1.0) @@ -36,7 +36,7 @@ GEM unf (>= 0.0.5, < 1.0.0) dotenv (2.8.1) emoji_regex (3.2.3) - excon (0.92.4) + excon (0.93.0) faraday (1.10.2) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) @@ -107,8 +107,8 @@ GEM xcpretty-travis-formatter (>= 0.0.3) fastlane-plugin-flutter_version (1.1.15) gh_inspector (1.1.3) - google-apis-androidpublisher_v3 (0.27.0) - google-apis-core (>= 0.7.2, < 2.a) + google-apis-androidpublisher_v3 (0.29.0) + google-apis-core (>= 0.9.0, < 2.a) google-apis-core (0.9.0) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) @@ -118,23 +118,23 @@ GEM retriable (>= 2.0, < 4.a) rexml webrick - google-apis-iamcredentials_v1 (0.14.0) - google-apis-core (>= 0.7.2, < 2.a) - google-apis-playcustomapp_v1 (0.10.0) - google-apis-core (>= 0.7, < 2.a) - google-apis-storage_v1 (0.17.0) - google-apis-core (>= 0.7, < 2.a) + google-apis-iamcredentials_v1 (0.15.0) + google-apis-core (>= 0.9.0, < 2.a) + google-apis-playcustomapp_v1 (0.11.0) + google-apis-core (>= 0.9.0, < 2.a) + google-apis-storage_v1 (0.19.0) + google-apis-core (>= 0.9.0, < 2.a) google-cloud-core (1.6.0) google-cloud-env (~> 1.0) google-cloud-errors (~> 1.0) google-cloud-env (1.6.0) faraday (>= 0.17.3, < 3.0) google-cloud-errors (1.3.0) - google-cloud-storage (1.42.0) + google-cloud-storage (1.43.0) addressable (~> 2.8) digest-crc (~> 0.4) google-apis-iamcredentials_v1 (~> 0.1) - google-apis-storage_v1 (~> 0.17.0) + google-apis-storage_v1 (~> 0.19.0) google-cloud-core (~> 1.6) googleauth (>= 0.16.2, < 2.a) mini_mime (~> 1.0) @@ -211,6 +211,8 @@ GEM PLATFORMS arm64-darwin-21 + x86_64-darwin-20 + x86_64-linux DEPENDENCIES fastlane diff --git a/android/fastlane/README.md b/android/fastlane/README.md index c958a7d..380dc2c 100644 --- a/android/fastlane/README.md +++ b/android/fastlane/README.md @@ -53,6 +53,14 @@ For _fastlane_ installation instructions, see [Installing _fastlane_](https://do **Run linters** +### ensure_no_change_in_generated_code + +```sh +[bundle exec] fastlane ensure_no_change_in_generated_code +``` + +**Check generated code is fine** + ### tests ```sh diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 8d50fc4..1a490ac 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -55,6 +55,12 @@ lane :lints do lint_analyze end +desc "**Check generated code is fine**" +lane :ensure_no_change_in_generated_code do + build_autogenerated_code + ensure_git_status_clean(show_diff: true) +end + desc "**Run tests**" lane :tests do |options| flutter_command(command: "test --no-pub --coverage --suppress-analytics") diff --git a/fastlane/README.md b/fastlane/README.md index 6447d5b..4fe20a8 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -53,6 +53,14 @@ For _fastlane_ installation instructions, see [Installing _fastlane_](https://do **Run linters** +### ensure_no_change_in_generated_code + +```sh +[bundle exec] fastlane ensure_no_change_in_generated_code +``` + +**Check generated code is fine** + ### tests ```sh diff --git a/ios/fastlane/README.md b/ios/fastlane/README.md index 0952776..8efa164 100644 --- a/ios/fastlane/README.md +++ b/ios/fastlane/README.md @@ -53,6 +53,14 @@ For _fastlane_ installation instructions, see [Installing _fastlane_](https://do **Run linters** +### ensure_no_change_in_generated_code + +```sh +[bundle exec] fastlane ensure_no_change_in_generated_code +``` + +**Check generated code is fine** + ### tests ```sh diff --git a/lib/core/source/common/app_database.g.dart b/lib/core/source/common/app_database.g.dart index 157701d..b842747 100644 --- a/lib/core/source/common/app_database.g.dart +++ b/lib/core/source/common/app_database.g.dart @@ -63,8 +63,11 @@ class _$AppDatabase extends AppDatabase { ProjectLocalSource? _projectLocalSourceInstance; - Future open(String path, List migrations, - [Callback? callback]) async { + Future open( + String path, + List migrations, [ + Callback? callback, + ]) async { final databaseOptions = sqflite.OpenDatabaseOptions( version: 1, onConfigure: (database) async { @@ -98,8 +101,10 @@ class _$AppDatabase extends AppDatabase { } class _$ProjectLocalSource extends ProjectLocalSource { - _$ProjectLocalSource(this.database, this.changeListener) - : _queryAdapter = QueryAdapter(database, changeListener), + _$ProjectLocalSource( + this.database, + this.changeListener, + ) : _queryAdapter = QueryAdapter(database, changeListener), _projectDbEntityInsertionAdapter = InsertionAdapter( database, 'projects', diff --git a/lib/gen/assets.gen.dart b/lib/gen/assets.gen.dart index 05314a4..49322c1 100644 --- a/lib/gen/assets.gen.dart +++ b/lib/gen/assets.gen.dart @@ -5,7 +5,7 @@ // coverage:ignore-file // ignore_for_file: type=lint -// ignore_for_file: directives_ordering,unnecessary_import +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal import 'package:flutter/widgets.dart'; @@ -17,6 +17,9 @@ class $AssetsEnvironmentsGen { /// File path: assets/environments/development.env String get development => 'assets/environments/development.env'; + + /// List of all assets + List get values => [env, development]; } class Assets { @@ -83,6 +86,8 @@ class AssetGenImage { ); } + ImageProvider provider() => AssetImage(_assetName); + String get path => _assetName; String get keyName => _assetName; diff --git a/lib/ui/app_router.gr.dart b/lib/ui/app_router.gr.dart index 8fdf640..bbadcf1 100644 --- a/lib/ui/app_router.gr.dart +++ b/lib/ui/app_router.gr.dart @@ -19,44 +19,68 @@ class _$AppRouter extends RootStackRouter { final Map pagesMap = { UnauthenticatedRouter.name: (routeData) { return MaterialPageX( - routeData: routeData, child: SectionRouter()); + routeData: routeData, + child: SectionRouter(), + ); }, AuthenticatedRouter.name: (routeData) { return MaterialPageX( - routeData: routeData, child: SectionRouter()); + routeData: routeData, + child: SectionRouter(), + ); }, SignInScreenRoute.name: (routeData) { return MaterialPageX( - routeData: routeData, child: const SignInScreen()); + routeData: routeData, + child: const SignInScreen(), + ); }, WelcomeScreenRoute.name: (routeData) { return MaterialPageX( - routeData: routeData, child: WelcomeScreen()); - } + routeData: routeData, + child: WelcomeScreen(), + ); + }, }; @override List get routes => [ - RouteConfig(UnauthenticatedRouter.name, path: '/', children: [ - RouteConfig('#redirect', + RouteConfig( + UnauthenticatedRouter.name, + path: '/', + children: [ + RouteConfig( + '#redirect', path: '', parent: UnauthenticatedRouter.name, redirectTo: 'signin', - fullMatch: true), - RouteConfig(SignInScreenRoute.name, - path: 'signin', parent: UnauthenticatedRouter.name) - ]), - RouteConfig(AuthenticatedRouter.name, - path: '/section-router', - children: [ - RouteConfig('#redirect', - path: '', - parent: AuthenticatedRouter.name, - redirectTo: 'welcome', - fullMatch: true), - RouteConfig(WelcomeScreenRoute.name, - path: 'welcome', parent: AuthenticatedRouter.name) - ]) + fullMatch: true, + ), + RouteConfig( + SignInScreenRoute.name, + path: 'signin', + parent: UnauthenticatedRouter.name, + ), + ], + ), + RouteConfig( + AuthenticatedRouter.name, + path: '/section-router', + children: [ + RouteConfig( + '#redirect', + path: '', + parent: AuthenticatedRouter.name, + redirectTo: 'welcome', + fullMatch: true, + ), + RouteConfig( + WelcomeScreenRoute.name, + path: 'welcome', + parent: AuthenticatedRouter.name, + ), + ], + ), ]; } @@ -64,7 +88,11 @@ class _$AppRouter extends RootStackRouter { /// [SectionRouter] class UnauthenticatedRouter extends PageRouteInfo { const UnauthenticatedRouter({List? children}) - : super(UnauthenticatedRouter.name, path: '/', initialChildren: children); + : super( + UnauthenticatedRouter.name, + path: '/', + initialChildren: children, + ); static const String name = 'UnauthenticatedRouter'; } @@ -73,8 +101,11 @@ class UnauthenticatedRouter extends PageRouteInfo { /// [SectionRouter] class AuthenticatedRouter extends PageRouteInfo { const AuthenticatedRouter({List? children}) - : super(AuthenticatedRouter.name, - path: '/section-router', initialChildren: children); + : super( + AuthenticatedRouter.name, + path: '/section-router', + initialChildren: children, + ); static const String name = 'AuthenticatedRouter'; } @@ -82,7 +113,11 @@ class AuthenticatedRouter extends PageRouteInfo { /// generated route for /// [SignInScreen] class SignInScreenRoute extends PageRouteInfo { - const SignInScreenRoute() : super(SignInScreenRoute.name, path: 'signin'); + const SignInScreenRoute() + : super( + SignInScreenRoute.name, + path: 'signin', + ); static const String name = 'SignInScreenRoute'; } @@ -90,7 +125,11 @@ class SignInScreenRoute extends PageRouteInfo { /// generated route for /// [WelcomeScreen] class WelcomeScreenRoute extends PageRouteInfo { - const WelcomeScreenRoute() : super(WelcomeScreenRoute.name, path: 'welcome'); + const WelcomeScreenRoute() + : super( + WelcomeScreenRoute.name, + path: 'welcome', + ); static const String name = 'WelcomeScreenRoute'; } diff --git a/lib/ui/extensions/context_extensions.dart b/lib/ui/extensions/context_extensions.dart new file mode 100644 index 0000000..89280f7 --- /dev/null +++ b/lib/ui/extensions/context_extensions.dart @@ -0,0 +1,8 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +extension ContextExtensions on BuildContext { + AppLocalizations get localizations => AppLocalizations.of(this)!; + + ThemeData get theme => Theme.of(this); +} diff --git a/lib/ui/resources.dart b/lib/ui/resources.dart index ed51f9b..8e20801 100644 --- a/lib/ui/resources.dart +++ b/lib/ui/resources.dart @@ -1,13 +1,17 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_template/ui/extensions/context_extensions.dart'; abstract class Resources { + /// Returns the app localizations + /// It should be used only in spacial cases when the context is not available + /// It's recommended to use `context.localizations` extension method. + /// This property doesn't notify the widget if the language changes, + /// so if the language changes or the localization are load async, + /// the app language will not be consistent. static late AppLocalizations localizations; - static late ThemeData theme; - static void setup(BuildContext appContext) { - localizations = AppLocalizations.of(appContext)!; - theme = Theme.of(appContext); + localizations = appContext.localizations; } } diff --git a/lib/ui/section/section_router.dart b/lib/ui/section/section_router.dart index cfce269..f2bd44d 100644 --- a/lib/ui/section/section_router.dart +++ b/lib/ui/section/section_router.dart @@ -1,7 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_template/ui/resources.dart'; +import 'package:flutter_template/ui/extensions/context_extensions.dart'; import 'package:flutter_template/ui/section/error_handler/error_handler_cubit.dart'; class SectionRouter extends StatelessWidget { @@ -21,14 +21,14 @@ class SectionRouter extends StatelessWidget { init: () => {}, unknownError: (error, retry) => _showDialog( context, - Resources.localizations.error_unknown_error_title, - Resources.localizations.error_unknown_error_description, + context.localizations.error_unknown_error_title, + context.localizations.error_unknown_error_description, retry, ), internetError: (retry) => _showDialog( context, - Resources.localizations.error_no_internet_connection_error_title, - Resources + context.localizations.error_no_internet_connection_error_title, + context .localizations.error_no_internet_connection_error_description, retry, ), @@ -42,17 +42,17 @@ class SectionRouter extends StatelessWidget { context: context, builder: (context) => AlertDialog( title: Text( - title ?? Resources.localizations.error_unknown_error_title), + title ?? context.localizations.error_unknown_error_title), content: Text(description), actions: [ if (retry != null) TextButton( onPressed: () => Navigator.pop(context), - child: Text(Resources.localizations.error_button_retry), + child: Text(context.localizations.error_button_retry), ), TextButton( onPressed: () => Navigator.pop(context), - child: Text(Resources.localizations.error_button_ok), + child: Text(context.localizations.error_button_ok), ), ], )); diff --git a/lib/ui/signin/signin_bloc.dart b/lib/ui/signin/signin_bloc.dart deleted file mode 100644 index dd5d3e8..0000000 --- a/lib/ui/signin/signin_bloc.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:flutter_template/core/common/extension/stream_future_extensions.dart'; -import 'package:flutter_template/core/common/helper/future_helpers.dart'; -import 'package:flutter_template/core/di/di_provider.dart'; -import 'package:flutter_template/core/repository/session_repository.dart'; -import 'package:flutter_template/ui/section/error_handler/error_handler_cubit.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'signin_bloc.freezed.dart'; - -part 'signin_event.dart'; - -part 'signin_state.dart'; - -class SignInBloc extends Bloc { - final SessionRepository _sessionRepository = DiProvider.get(); - - // TODO: use it - // ignore: unused_field - final GeneralErrorHandler _errorHandler; - - SignInBloc(this._errorHandler) - : super(const SignInState( - email: 'hi@xmartlabs.com', password: 'xmartlabs', error: '')) { - on(eventHandler); - } - - Future eventHandler( - SignInEvent event, Emitter emitter) async => - await event.when( - changeEmail: (email) => - wrapInFuture(() => emitter(state.copyWith(email: email))), - changePassword: (password) => - wrapInFuture(() => emitter(state.copyWith(password: password))), - login: () => _performSignInEvent(emitter)); - - Future _performSignInEvent(Emitter emitter) async { - final result = await _sessionRepository - .signInUser(email: state.email!, password: state.password!) - .mapToResult(); - emitter( - state.copyWith(error: result.isSuccess ? '' : 'Error ${result.error}'), - ); - } -} diff --git a/lib/ui/signin/signin_bloc.freezed.dart b/lib/ui/signin/signin_bloc.freezed.dart deleted file mode 100644 index fdff985..0000000 --- a/lib/ui/signin/signin_bloc.freezed.dart +++ /dev/null @@ -1,721 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target - -part of 'signin_bloc.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -/// @nodoc -mixin _$SignInEvent { - @optionalTypeArgs - TResult when({ - required TResult Function(String email) changeEmail, - required TResult Function(String password) changePassword, - required TResult Function() login, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function(String email)? changeEmail, - TResult Function(String password)? changePassword, - TResult Function()? login, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(String email)? changeEmail, - TResult Function(String password)? changePassword, - TResult Function()? login, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(ChangeEmailSignInEvent value) changeEmail, - required TResult Function(ChangePasswordSignInEvent value) changePassword, - required TResult Function(LoginSignInEvent value) login, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(ChangeEmailSignInEvent value)? changeEmail, - TResult Function(ChangePasswordSignInEvent value)? changePassword, - TResult Function(LoginSignInEvent value)? login, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(ChangeEmailSignInEvent value)? changeEmail, - TResult Function(ChangePasswordSignInEvent value)? changePassword, - TResult Function(LoginSignInEvent value)? login, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $SignInEventCopyWith<$Res> { - factory $SignInEventCopyWith( - SignInEvent value, $Res Function(SignInEvent) then) = - _$SignInEventCopyWithImpl<$Res>; -} - -/// @nodoc -class _$SignInEventCopyWithImpl<$Res> implements $SignInEventCopyWith<$Res> { - _$SignInEventCopyWithImpl(this._value, this._then); - - final SignInEvent _value; - // ignore: unused_field - final $Res Function(SignInEvent) _then; -} - -/// @nodoc -abstract class _$$ChangeEmailSignInEventCopyWith<$Res> { - factory _$$ChangeEmailSignInEventCopyWith(_$ChangeEmailSignInEvent value, - $Res Function(_$ChangeEmailSignInEvent) then) = - __$$ChangeEmailSignInEventCopyWithImpl<$Res>; - $Res call({String email}); -} - -/// @nodoc -class __$$ChangeEmailSignInEventCopyWithImpl<$Res> - extends _$SignInEventCopyWithImpl<$Res> - implements _$$ChangeEmailSignInEventCopyWith<$Res> { - __$$ChangeEmailSignInEventCopyWithImpl(_$ChangeEmailSignInEvent _value, - $Res Function(_$ChangeEmailSignInEvent) _then) - : super(_value, (v) => _then(v as _$ChangeEmailSignInEvent)); - - @override - _$ChangeEmailSignInEvent get _value => - super._value as _$ChangeEmailSignInEvent; - - @override - $Res call({ - Object? email = freezed, - }) { - return _then(_$ChangeEmailSignInEvent( - email: email == freezed - ? _value.email - : email // ignore: cast_nullable_to_non_nullable - as String, - )); - } -} - -/// @nodoc - -class _$ChangeEmailSignInEvent implements ChangeEmailSignInEvent { - const _$ChangeEmailSignInEvent({required this.email}); - - @override - final String email; - - @override - String toString() { - return 'SignInEvent.changeEmail(email: $email)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$ChangeEmailSignInEvent && - const DeepCollectionEquality().equals(other.email, email)); - } - - @override - int get hashCode => - Object.hash(runtimeType, const DeepCollectionEquality().hash(email)); - - @JsonKey(ignore: true) - @override - _$$ChangeEmailSignInEventCopyWith<_$ChangeEmailSignInEvent> get copyWith => - __$$ChangeEmailSignInEventCopyWithImpl<_$ChangeEmailSignInEvent>( - this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(String email) changeEmail, - required TResult Function(String password) changePassword, - required TResult Function() login, - }) { - return changeEmail(email); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function(String email)? changeEmail, - TResult Function(String password)? changePassword, - TResult Function()? login, - }) { - return changeEmail?.call(email); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(String email)? changeEmail, - TResult Function(String password)? changePassword, - TResult Function()? login, - required TResult orElse(), - }) { - if (changeEmail != null) { - return changeEmail(email); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(ChangeEmailSignInEvent value) changeEmail, - required TResult Function(ChangePasswordSignInEvent value) changePassword, - required TResult Function(LoginSignInEvent value) login, - }) { - return changeEmail(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(ChangeEmailSignInEvent value)? changeEmail, - TResult Function(ChangePasswordSignInEvent value)? changePassword, - TResult Function(LoginSignInEvent value)? login, - }) { - return changeEmail?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(ChangeEmailSignInEvent value)? changeEmail, - TResult Function(ChangePasswordSignInEvent value)? changePassword, - TResult Function(LoginSignInEvent value)? login, - required TResult orElse(), - }) { - if (changeEmail != null) { - return changeEmail(this); - } - return orElse(); - } -} - -abstract class ChangeEmailSignInEvent implements SignInEvent { - const factory ChangeEmailSignInEvent({required final String email}) = - _$ChangeEmailSignInEvent; - - String get email; - @JsonKey(ignore: true) - _$$ChangeEmailSignInEventCopyWith<_$ChangeEmailSignInEvent> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$ChangePasswordSignInEventCopyWith<$Res> { - factory _$$ChangePasswordSignInEventCopyWith( - _$ChangePasswordSignInEvent value, - $Res Function(_$ChangePasswordSignInEvent) then) = - __$$ChangePasswordSignInEventCopyWithImpl<$Res>; - $Res call({String password}); -} - -/// @nodoc -class __$$ChangePasswordSignInEventCopyWithImpl<$Res> - extends _$SignInEventCopyWithImpl<$Res> - implements _$$ChangePasswordSignInEventCopyWith<$Res> { - __$$ChangePasswordSignInEventCopyWithImpl(_$ChangePasswordSignInEvent _value, - $Res Function(_$ChangePasswordSignInEvent) _then) - : super(_value, (v) => _then(v as _$ChangePasswordSignInEvent)); - - @override - _$ChangePasswordSignInEvent get _value => - super._value as _$ChangePasswordSignInEvent; - - @override - $Res call({ - Object? password = freezed, - }) { - return _then(_$ChangePasswordSignInEvent( - password: password == freezed - ? _value.password - : password // ignore: cast_nullable_to_non_nullable - as String, - )); - } -} - -/// @nodoc - -class _$ChangePasswordSignInEvent implements ChangePasswordSignInEvent { - const _$ChangePasswordSignInEvent({required this.password}); - - @override - final String password; - - @override - String toString() { - return 'SignInEvent.changePassword(password: $password)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$ChangePasswordSignInEvent && - const DeepCollectionEquality().equals(other.password, password)); - } - - @override - int get hashCode => - Object.hash(runtimeType, const DeepCollectionEquality().hash(password)); - - @JsonKey(ignore: true) - @override - _$$ChangePasswordSignInEventCopyWith<_$ChangePasswordSignInEvent> - get copyWith => __$$ChangePasswordSignInEventCopyWithImpl< - _$ChangePasswordSignInEvent>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(String email) changeEmail, - required TResult Function(String password) changePassword, - required TResult Function() login, - }) { - return changePassword(password); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function(String email)? changeEmail, - TResult Function(String password)? changePassword, - TResult Function()? login, - }) { - return changePassword?.call(password); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(String email)? changeEmail, - TResult Function(String password)? changePassword, - TResult Function()? login, - required TResult orElse(), - }) { - if (changePassword != null) { - return changePassword(password); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(ChangeEmailSignInEvent value) changeEmail, - required TResult Function(ChangePasswordSignInEvent value) changePassword, - required TResult Function(LoginSignInEvent value) login, - }) { - return changePassword(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(ChangeEmailSignInEvent value)? changeEmail, - TResult Function(ChangePasswordSignInEvent value)? changePassword, - TResult Function(LoginSignInEvent value)? login, - }) { - return changePassword?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(ChangeEmailSignInEvent value)? changeEmail, - TResult Function(ChangePasswordSignInEvent value)? changePassword, - TResult Function(LoginSignInEvent value)? login, - required TResult orElse(), - }) { - if (changePassword != null) { - return changePassword(this); - } - return orElse(); - } -} - -abstract class ChangePasswordSignInEvent implements SignInEvent { - const factory ChangePasswordSignInEvent({required final String password}) = - _$ChangePasswordSignInEvent; - - String get password; - @JsonKey(ignore: true) - _$$ChangePasswordSignInEventCopyWith<_$ChangePasswordSignInEvent> - get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$LoginSignInEventCopyWith<$Res> { - factory _$$LoginSignInEventCopyWith( - _$LoginSignInEvent value, $Res Function(_$LoginSignInEvent) then) = - __$$LoginSignInEventCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$LoginSignInEventCopyWithImpl<$Res> - extends _$SignInEventCopyWithImpl<$Res> - implements _$$LoginSignInEventCopyWith<$Res> { - __$$LoginSignInEventCopyWithImpl( - _$LoginSignInEvent _value, $Res Function(_$LoginSignInEvent) _then) - : super(_value, (v) => _then(v as _$LoginSignInEvent)); - - @override - _$LoginSignInEvent get _value => super._value as _$LoginSignInEvent; -} - -/// @nodoc - -class _$LoginSignInEvent implements LoginSignInEvent { - const _$LoginSignInEvent(); - - @override - String toString() { - return 'SignInEvent.login()'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$LoginSignInEvent); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(String email) changeEmail, - required TResult Function(String password) changePassword, - required TResult Function() login, - }) { - return login(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function(String email)? changeEmail, - TResult Function(String password)? changePassword, - TResult Function()? login, - }) { - return login?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(String email)? changeEmail, - TResult Function(String password)? changePassword, - TResult Function()? login, - required TResult orElse(), - }) { - if (login != null) { - return login(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(ChangeEmailSignInEvent value) changeEmail, - required TResult Function(ChangePasswordSignInEvent value) changePassword, - required TResult Function(LoginSignInEvent value) login, - }) { - return login(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(ChangeEmailSignInEvent value)? changeEmail, - TResult Function(ChangePasswordSignInEvent value)? changePassword, - TResult Function(LoginSignInEvent value)? login, - }) { - return login?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(ChangeEmailSignInEvent value)? changeEmail, - TResult Function(ChangePasswordSignInEvent value)? changePassword, - TResult Function(LoginSignInEvent value)? login, - required TResult orElse(), - }) { - if (login != null) { - return login(this); - } - return orElse(); - } -} - -abstract class LoginSignInEvent implements SignInEvent { - const factory LoginSignInEvent() = _$LoginSignInEvent; -} - -/// @nodoc -mixin _$SignInBaseState { - String? get email => throw _privateConstructorUsedError; - String? get password => throw _privateConstructorUsedError; - String get error => throw _privateConstructorUsedError; - @optionalTypeArgs - TResult when({ - required TResult Function(String? email, String? password, String error) - state, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function(String? email, String? password, String error)? state, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(String? email, String? password, String error)? state, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(SignInState value) state, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(SignInState value)? state, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(SignInState value)? state, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - - @JsonKey(ignore: true) - $SignInBaseStateCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $SignInBaseStateCopyWith<$Res> { - factory $SignInBaseStateCopyWith( - SignInBaseState value, $Res Function(SignInBaseState) then) = - _$SignInBaseStateCopyWithImpl<$Res>; - $Res call({String? email, String? password, String error}); -} - -/// @nodoc -class _$SignInBaseStateCopyWithImpl<$Res> - implements $SignInBaseStateCopyWith<$Res> { - _$SignInBaseStateCopyWithImpl(this._value, this._then); - - final SignInBaseState _value; - // ignore: unused_field - final $Res Function(SignInBaseState) _then; - - @override - $Res call({ - Object? email = freezed, - Object? password = freezed, - Object? error = freezed, - }) { - return _then(_value.copyWith( - email: email == freezed - ? _value.email - : email // ignore: cast_nullable_to_non_nullable - as String?, - password: password == freezed - ? _value.password - : password // ignore: cast_nullable_to_non_nullable - as String?, - error: error == freezed - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as String, - )); - } -} - -/// @nodoc -abstract class _$$SignInStateCopyWith<$Res> - implements $SignInBaseStateCopyWith<$Res> { - factory _$$SignInStateCopyWith( - _$SignInState value, $Res Function(_$SignInState) then) = - __$$SignInStateCopyWithImpl<$Res>; - @override - $Res call({String? email, String? password, String error}); -} - -/// @nodoc -class __$$SignInStateCopyWithImpl<$Res> - extends _$SignInBaseStateCopyWithImpl<$Res> - implements _$$SignInStateCopyWith<$Res> { - __$$SignInStateCopyWithImpl( - _$SignInState _value, $Res Function(_$SignInState) _then) - : super(_value, (v) => _then(v as _$SignInState)); - - @override - _$SignInState get _value => super._value as _$SignInState; - - @override - $Res call({ - Object? email = freezed, - Object? password = freezed, - Object? error = freezed, - }) { - return _then(_$SignInState( - email: email == freezed - ? _value.email - : email // ignore: cast_nullable_to_non_nullable - as String?, - password: password == freezed - ? _value.password - : password // ignore: cast_nullable_to_non_nullable - as String?, - error: error == freezed - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as String, - )); - } -} - -/// @nodoc - -class _$SignInState implements SignInState { - const _$SignInState( - {required this.email, required this.password, required this.error}); - - @override - final String? email; - @override - final String? password; - @override - final String error; - - @override - String toString() { - return 'SignInBaseState.state(email: $email, password: $password, error: $error)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$SignInState && - const DeepCollectionEquality().equals(other.email, email) && - const DeepCollectionEquality().equals(other.password, password) && - const DeepCollectionEquality().equals(other.error, error)); - } - - @override - int get hashCode => Object.hash( - runtimeType, - const DeepCollectionEquality().hash(email), - const DeepCollectionEquality().hash(password), - const DeepCollectionEquality().hash(error)); - - @JsonKey(ignore: true) - @override - _$$SignInStateCopyWith<_$SignInState> get copyWith => - __$$SignInStateCopyWithImpl<_$SignInState>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(String? email, String? password, String error) - state, - }) { - return state(email, password, error); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult Function(String? email, String? password, String error)? state, - }) { - return state?.call(email, password, error); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(String? email, String? password, String error)? state, - required TResult orElse(), - }) { - if (state != null) { - return state(email, password, error); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(SignInState value) state, - }) { - return state(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult Function(SignInState value)? state, - }) { - return state?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(SignInState value)? state, - required TResult orElse(), - }) { - if (state != null) { - return state(this); - } - return orElse(); - } -} - -abstract class SignInState implements SignInBaseState { - const factory SignInState( - {required final String? email, - required final String? password, - required final String error}) = _$SignInState; - - @override - String? get email; - @override - String? get password; - @override - String get error; - @override - @JsonKey(ignore: true) - _$$SignInStateCopyWith<_$SignInState> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/lib/ui/signin/signin_cubit.dart b/lib/ui/signin/signin_cubit.dart new file mode 100644 index 0000000..39b1695 --- /dev/null +++ b/lib/ui/signin/signin_cubit.dart @@ -0,0 +1,31 @@ +import 'package:bloc/bloc.dart'; +import 'package:flutter_template/core/common/extension/stream_future_extensions.dart'; +import 'package:flutter_template/core/di/di_provider.dart'; +import 'package:flutter_template/core/repository/session_repository.dart'; +import 'package:flutter_template/ui/section/error_handler/error_handler_cubit.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'signin_cubit.freezed.dart'; +part 'signin_state.dart'; + +class SignInCubit extends Cubit { + final GeneralErrorHandler _errorHandler; + final SessionRepository _sessionRepository = DiProvider.get(); + + SignInCubit(this._errorHandler) + : super( + SignInBaseState.state( + email: 'hi@xmartlabs.com', + password: 'xmartlabs', + error: '', + ), + ); + + void changeEmail(String email) => emit(state.copyWith(email: email)); + + void changePassword(String email) => emit(state.copyWith(email: email)); + + Future signIn() => _sessionRepository + .signInUser(email: state.email!, password: state.password!) + .filterSuccess(_errorHandler.handleError); +} diff --git a/lib/ui/signin/signin_cubit.freezed.dart b/lib/ui/signin/signin_cubit.freezed.dart new file mode 100644 index 0000000..653b98d --- /dev/null +++ b/lib/ui/signin/signin_cubit.freezed.dart @@ -0,0 +1,259 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target + +part of 'signin_cubit.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$SignInBaseState { + String? get email => throw _privateConstructorUsedError; + String? get password => throw _privateConstructorUsedError; + String get error => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult when({ + required TResult Function(String? email, String? password, String error) + state, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function(String? email, String? password, String error)? state, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String? email, String? password, String error)? state, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(SignInState value) state, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function(SignInState value)? state, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SignInState value)? state, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $SignInBaseStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SignInBaseStateCopyWith<$Res> { + factory $SignInBaseStateCopyWith( + SignInBaseState value, $Res Function(SignInBaseState) then) = + _$SignInBaseStateCopyWithImpl<$Res>; + $Res call({String? email, String? password, String error}); +} + +/// @nodoc +class _$SignInBaseStateCopyWithImpl<$Res> + implements $SignInBaseStateCopyWith<$Res> { + _$SignInBaseStateCopyWithImpl(this._value, this._then); + + final SignInBaseState _value; + // ignore: unused_field + final $Res Function(SignInBaseState) _then; + + @override + $Res call({ + Object? email = freezed, + Object? password = freezed, + Object? error = freezed, + }) { + return _then(_value.copyWith( + email: email == freezed + ? _value.email + : email // ignore: cast_nullable_to_non_nullable + as String?, + password: password == freezed + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as String?, + error: error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +abstract class _$$SignInStateCopyWith<$Res> + implements $SignInBaseStateCopyWith<$Res> { + factory _$$SignInStateCopyWith( + _$SignInState value, $Res Function(_$SignInState) then) = + __$$SignInStateCopyWithImpl<$Res>; + @override + $Res call({String? email, String? password, String error}); +} + +/// @nodoc +class __$$SignInStateCopyWithImpl<$Res> + extends _$SignInBaseStateCopyWithImpl<$Res> + implements _$$SignInStateCopyWith<$Res> { + __$$SignInStateCopyWithImpl( + _$SignInState _value, $Res Function(_$SignInState) _then) + : super(_value, (v) => _then(v as _$SignInState)); + + @override + _$SignInState get _value => super._value as _$SignInState; + + @override + $Res call({ + Object? email = freezed, + Object? password = freezed, + Object? error = freezed, + }) { + return _then(_$SignInState( + email: email == freezed + ? _value.email + : email // ignore: cast_nullable_to_non_nullable + as String?, + password: password == freezed + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as String?, + error: error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$SignInState implements SignInState { + const _$SignInState( + {required this.email, required this.password, required this.error}); + + @override + final String? email; + @override + final String? password; + @override + final String error; + + @override + String toString() { + return 'SignInBaseState.state(email: $email, password: $password, error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SignInState && + const DeepCollectionEquality().equals(other.email, email) && + const DeepCollectionEquality().equals(other.password, password) && + const DeepCollectionEquality().equals(other.error, error)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(email), + const DeepCollectionEquality().hash(password), + const DeepCollectionEquality().hash(error)); + + @JsonKey(ignore: true) + @override + _$$SignInStateCopyWith<_$SignInState> get copyWith => + __$$SignInStateCopyWithImpl<_$SignInState>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String? email, String? password, String error) + state, + }) { + return state(email, password, error); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function(String? email, String? password, String error)? state, + }) { + return state?.call(email, password, error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String? email, String? password, String error)? state, + required TResult orElse(), + }) { + if (state != null) { + return state(email, password, error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(SignInState value) state, + }) { + return state(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function(SignInState value)? state, + }) { + return state?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SignInState value)? state, + required TResult orElse(), + }) { + if (state != null) { + return state(this); + } + return orElse(); + } +} + +abstract class SignInState implements SignInBaseState { + const factory SignInState( + {required final String? email, + required final String? password, + required final String error}) = _$SignInState; + + @override + String? get email; + @override + String? get password; + @override + String get error; + @override + @JsonKey(ignore: true) + _$$SignInStateCopyWith<_$SignInState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/ui/signin/signin_event.dart b/lib/ui/signin/signin_event.dart deleted file mode 100644 index f7bbf96..0000000 --- a/lib/ui/signin/signin_event.dart +++ /dev/null @@ -1,12 +0,0 @@ -part of 'signin_bloc.dart'; - -@freezed -class SignInEvent with _$SignInEvent { - const factory SignInEvent.changeEmail({required String email}) = - ChangeEmailSignInEvent; - - const factory SignInEvent.changePassword({required String password}) = - ChangePasswordSignInEvent; - - const factory SignInEvent.login() = LoginSignInEvent; -} diff --git a/lib/ui/signin/signin_screen.dart b/lib/ui/signin/signin_screen.dart index 0706264..b77bc29 100644 --- a/lib/ui/signin/signin_screen.dart +++ b/lib/ui/signin/signin_screen.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_template/ui/resources.dart'; +import 'package:flutter_template/ui/extensions/context_extensions.dart'; import 'package:flutter_template/ui/section/error_handler/error_handler_cubit.dart'; -import 'package:flutter_template/ui/signin/signin_bloc.dart'; + +import 'package:flutter_template/ui/signin/signin_cubit.dart'; class SignInScreen extends StatelessWidget { const SignInScreen({Key? key}) : super(key: key); @@ -10,7 +11,7 @@ class SignInScreen extends StatelessWidget { @override Widget build(BuildContext context) { return BlocProvider( - create: (context) => SignInBloc(context.read()), + create: (context) => SignInCubit(context.read()), child: _SignInContentScreen(), ); } @@ -19,23 +20,22 @@ class SignInScreen extends StatelessWidget { class _SignInContentScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (context, state) { return Scaffold( appBar: AppBar( - title: Text(Resources.localizations.sign_in), + title: Text(context.localizations.sign_in), ), body: Column( mainAxisSize: MainAxisSize.min, children: [ Expanded(child: _SignInForm()), - if (context.read().state.error.isNotEmpty) - Text(Resources.localizations - .error(context.read().state.error)), + if (context.read().state.error.isNotEmpty) + Text(context.localizations + .error(context.read().state.error)), TextButton( - onPressed: () => - context.read().add(SignInEvent.login()), - child: Text(Resources.localizations.sign_in)) + onPressed: () => context.read().signIn(), + child: Text(context.localizations.sign_in)) ], ), ); @@ -52,7 +52,7 @@ class _SignInForm extends StatefulWidget { class _SignInFormState extends State<_SignInForm> { final _emailTextController = TextEditingController(); final _passwordTextController = TextEditingController(); - late SignInBloc _signInBlock; + late SignInCubit _signInCubit; @override void dispose() { @@ -64,10 +64,10 @@ class _SignInFormState extends State<_SignInForm> { @override void initState() { super.initState(); - _signInBlock = context.read(); + _signInCubit = context.read(); // TODO: This should be bound - _emailTextController.text = _signInBlock.state.email ?? ''; - _passwordTextController.text = _signInBlock.state.password ?? ''; + _emailTextController.text = _signInCubit.state.email ?? ''; + _passwordTextController.text = _signInCubit.state.password ?? ''; } @override @@ -80,11 +80,10 @@ class _SignInFormState extends State<_SignInForm> { child: Container( child: TextField( controller: _emailTextController, - onChanged: (String text) => - _signInBlock.add(SignInEvent.changeEmail(email: text)), + onChanged: (String text) => _signInCubit.changeEmail(text), decoration: InputDecoration( border: OutlineInputBorder(), - labelText: Resources.localizations.mail, + labelText: context.localizations.mail, ), ), ), @@ -95,11 +94,11 @@ class _SignInFormState extends State<_SignInForm> { child: TextField( obscureText: true, controller: _passwordTextController, - onChanged: (String password) => _signInBlock - .add(SignInEvent.changePassword(password: password)), + onChanged: (String password) => + _signInCubit.changePassword(password), decoration: InputDecoration( border: OutlineInputBorder(), - labelText: Resources.localizations.password, + labelText: context.localizations.password, ), )), ), diff --git a/lib/ui/signin/signin_state.dart b/lib/ui/signin/signin_state.dart index f1ff095..773ad80 100644 --- a/lib/ui/signin/signin_state.dart +++ b/lib/ui/signin/signin_state.dart @@ -1,4 +1,4 @@ -part of 'signin_bloc.dart'; +part of 'signin_cubit.dart'; @freezed class SignInBaseState with _$SignInBaseState { diff --git a/lib/ui/theme/text_styles.dart b/lib/ui/theme/text_styles.dart index 17016c2..1e397ef 100644 --- a/lib/ui/theme/text_styles.dart +++ b/lib/ui/theme/text_styles.dart @@ -7,20 +7,30 @@ class AppStyles extends TextTheme { AppStyles({ required this.customStyle, - headline1, - headline2, - headline3, - headline4, - headline5, - headline6, + headlineLarge, + headlineMedium, + headlineSmall, bodyLarge, bodyMedium, bodySmall, - bodyText1, - bodyText2, - caption, - overline, - }); + titleLarge, + titleMedium, + titleSmall, + labelLarge, + labelMedium, + labelSmall, + }) : super( + bodyLarge: bodyLarge, + headlineMedium: headlineMedium, + headlineSmall: headlineSmall, + titleLarge: titleLarge, + titleMedium: titleMedium, + titleSmall: titleSmall, + bodyMedium: bodyMedium, + bodySmall: bodySmall, + labelLarge: labelLarge, + labelSmall: labelSmall, + ); factory AppStyles.fromTextTheme({ required TextStyle customStyle, @@ -28,19 +38,18 @@ class AppStyles extends TextTheme { }) => AppStyles( customStyle: customStyle, - headline1: textTheme.headline1, - headline2: textTheme.headline2, - headline3: textTheme.headline3, - headline4: textTheme.headline4, - headline5: textTheme.headline5, - headline6: textTheme.headline6, + headlineSmall: textTheme.headlineSmall, + headlineMedium: textTheme.headlineMedium, + headlineLarge: textTheme.headlineLarge, bodyLarge: textTheme.bodyLarge, bodyMedium: textTheme.bodyMedium, bodySmall: textTheme.bodySmall, - bodyText1: textTheme.bodyText1, - bodyText2: textTheme.bodyText2, - caption: textTheme.caption, - overline: textTheme.overline, + titleLarge: textTheme.titleLarge, + titleMedium: textTheme.titleMedium, + titleSmall: textTheme.titleSmall, + labelLarge: textTheme.labelLarge, + labelMedium: textTheme.labelMedium, + labelSmall: textTheme.labelSmall, ); static AppStyles getAppStyles() => AppStyles.fromTextTheme( diff --git a/lib/ui/welcome/welcome_screen.dart b/lib/ui/welcome/welcome_screen.dart index 5fd73da..f419a5d 100644 --- a/lib/ui/welcome/welcome_screen.dart +++ b/lib/ui/welcome/welcome_screen.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_template/core/model/project.dart'; -import 'package:flutter_template/ui/resources.dart'; +import 'package:flutter_template/ui/extensions/context_extensions.dart'; import 'package:flutter_template/ui/section/error_handler/error_handler_cubit.dart'; import 'package:flutter_template/ui/theme/app_theme.dart'; import 'package:flutter_template/ui/welcome/welcome_cubit.dart'; @@ -23,15 +23,15 @@ class _WelcomeContentScreen extends StatelessWidget { BlocBuilder(builder: (context, state) { return Scaffold( appBar: AppBar( - title: Text(Resources.localizations.xmartlabs_projects), + title: Text(context.localizations.xmartlabs_projects), actions: [ TextButton( style: ButtonStyle( foregroundColor: MaterialStateProperty.all( - Resources.theme.colors.onPrimary, + context.theme.colors.onPrimary, )), onPressed: () => context.read().logOut(), - child: Text(Resources.localizations.log_out), + child: Text(context.localizations.log_out), ), ], ), diff --git a/pubspec.lock b/pubspec.lock index 139267c..18fc8a7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,7 +49,7 @@ packages: name: auto_route url: "https://pub.dartlang.org" source: hosted - version: "5.0.1" + version: "5.0.2" auto_route_generator: dependency: "direct dev" description: @@ -105,7 +105,7 @@ packages: name: build_runner url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "2.3.0" build_runner_core: dependency: transitive description: @@ -168,7 +168,7 @@ packages: name: code_builder url: "https://pub.dartlang.org" source: hosted - version: "4.1.0" + version: "4.3.0" collection: dependency: transitive description: @@ -320,14 +320,14 @@ packages: name: flutter_gen_core url: "https://pub.dartlang.org" source: hosted - version: "4.3.0" + version: "5.0.2" flutter_gen_runner: dependency: "direct dev" description: name: flutter_gen_runner url: "https://pub.dartlang.org" source: hosted - version: "4.3.0" + version: "5.0.2" flutter_launcher_icons: dependency: "direct dev" description: @@ -433,7 +433,7 @@ packages: name: freezed_annotation url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" frontend_server_client: dependency: transitive description: @@ -545,7 +545,7 @@ packages: name: json_serializable url: "https://pub.dartlang.org" source: hosted - version: "6.4.0" + version: "6.5.1" lint: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 945c112..e8a2300 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,7 +22,7 @@ dependencies: sdk: flutter arb_utils: 0.2.0 - auto_route: 5.0.1 + auto_route: 5.0.2 bloc: 8.1.0 cupertino_icons: 1.0.5 dio: 4.0.6 # networking @@ -34,7 +34,7 @@ dependencies: flutter_screenutil: 5.5.4 flutter_secure_storage: 6.0.0 flutter_web_browser: 0.17.1 # This can be removed - freezed_annotation: 2.1.0 + freezed_annotation: 2.2.0 get_it: 7.2.0 google_fonts: 3.0.1 intl: 0.17.0 @@ -49,14 +49,14 @@ dev_dependencies: sdk: flutter auto_route_generator: 5.0.2 - build_runner: 2.2.1 + build_runner: 2.3.0 floor_generator: 1.3.0 flutter_flavorizr: 2.1.4 - flutter_gen_runner: 4.3.0 + flutter_gen_runner: 5.0.2 flutter_launcher_icons: 0.10.0 flutter_lints: 2.0.1 freezed: 2.1.0+1 - json_serializable: 6.4.0 + json_serializable: 6.5.1 pedantic: 1.11.1 flutter: