Compare commits
No commits in common. "05609d592d3fd24dbe9708a7e258b29e41075814" and "ca5d2a58e7378eed89fc547cab4c43d1681c050c" have entirely different histories.
05609d592d
...
ca5d2a58e7
Binary file not shown.
|
Before Width: | Height: | Size: 125 KiB |
@ -1,49 +0,0 @@
|
|||||||
import 'package:dartz/dartz.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
||||||
import 'package:injectable/injectable.dart';
|
|
||||||
|
|
||||||
import '../../domain/auth/auth.dart';
|
|
||||||
|
|
||||||
part 'auth_event.dart';
|
|
||||||
part 'auth_state.dart';
|
|
||||||
part 'auth_bloc.freezed.dart';
|
|
||||||
|
|
||||||
@injectable
|
|
||||||
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
||||||
final IAuthRepository _repository;
|
|
||||||
AuthBloc(this._repository) : super(AuthState.initial()) {
|
|
||||||
on<AuthEvent>(_onAuthEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _onAuthEvent(AuthEvent event, Emitter<AuthState> emit) {
|
|
||||||
return event.map(
|
|
||||||
fetchCurrentUser: (e) async {
|
|
||||||
emit(state.copyWith(failureOption: none()));
|
|
||||||
|
|
||||||
final token = await _repository.hasToken();
|
|
||||||
|
|
||||||
final failureOrAuth = await _repository.currentUser();
|
|
||||||
|
|
||||||
failureOrAuth.fold(
|
|
||||||
(f) => emit(
|
|
||||||
state.copyWith(
|
|
||||||
failureOption: optionOf(f),
|
|
||||||
status: token
|
|
||||||
? AuthStatus.authenticated()
|
|
||||||
: AuthStatus.unauthenticated(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(user) => emit(
|
|
||||||
state.copyWith(
|
|
||||||
user: user,
|
|
||||||
status: token
|
|
||||||
? AuthStatus.authenticated()
|
|
||||||
: AuthStatus.unauthenticated(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,806 +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, unnecessary_question_mark
|
|
||||||
|
|
||||||
part of 'auth_bloc.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// FreezedGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
T _$identity<T>(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#adding-getters-and-methods-to-our-models',
|
|
||||||
);
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
mixin _$AuthEvent {
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult when<TResult extends Object?>({
|
|
||||||
required TResult Function() fetchCurrentUser,
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? whenOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function()? fetchCurrentUser,
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
|
||||||
TResult Function()? fetchCurrentUser,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult map<TResult extends Object?>({
|
|
||||||
required TResult Function(_FetchCurrentUser value) fetchCurrentUser,
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? mapOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function(_FetchCurrentUser value)? fetchCurrentUser,
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeMap<TResult extends Object?>({
|
|
||||||
TResult Function(_FetchCurrentUser value)? fetchCurrentUser,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class $AuthEventCopyWith<$Res> {
|
|
||||||
factory $AuthEventCopyWith(AuthEvent value, $Res Function(AuthEvent) then) =
|
|
||||||
_$AuthEventCopyWithImpl<$Res, AuthEvent>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class _$AuthEventCopyWithImpl<$Res, $Val extends AuthEvent>
|
|
||||||
implements $AuthEventCopyWith<$Res> {
|
|
||||||
_$AuthEventCopyWithImpl(this._value, this._then);
|
|
||||||
|
|
||||||
// ignore: unused_field
|
|
||||||
final $Val _value;
|
|
||||||
// ignore: unused_field
|
|
||||||
final $Res Function($Val) _then;
|
|
||||||
|
|
||||||
/// Create a copy of AuthEvent
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class _$$FetchCurrentUserImplCopyWith<$Res> {
|
|
||||||
factory _$$FetchCurrentUserImplCopyWith(
|
|
||||||
_$FetchCurrentUserImpl value,
|
|
||||||
$Res Function(_$FetchCurrentUserImpl) then,
|
|
||||||
) = __$$FetchCurrentUserImplCopyWithImpl<$Res>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class __$$FetchCurrentUserImplCopyWithImpl<$Res>
|
|
||||||
extends _$AuthEventCopyWithImpl<$Res, _$FetchCurrentUserImpl>
|
|
||||||
implements _$$FetchCurrentUserImplCopyWith<$Res> {
|
|
||||||
__$$FetchCurrentUserImplCopyWithImpl(
|
|
||||||
_$FetchCurrentUserImpl _value,
|
|
||||||
$Res Function(_$FetchCurrentUserImpl) _then,
|
|
||||||
) : super(_value, _then);
|
|
||||||
|
|
||||||
/// Create a copy of AuthEvent
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
|
|
||||||
class _$FetchCurrentUserImpl implements _FetchCurrentUser {
|
|
||||||
const _$FetchCurrentUserImpl();
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'AuthEvent.fetchCurrentUser()';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return identical(this, other) ||
|
|
||||||
(other.runtimeType == runtimeType && other is _$FetchCurrentUserImpl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => runtimeType.hashCode;
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult when<TResult extends Object?>({
|
|
||||||
required TResult Function() fetchCurrentUser,
|
|
||||||
}) {
|
|
||||||
return fetchCurrentUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? whenOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function()? fetchCurrentUser,
|
|
||||||
}) {
|
|
||||||
return fetchCurrentUser?.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
|
||||||
TResult Function()? fetchCurrentUser,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (fetchCurrentUser != null) {
|
|
||||||
return fetchCurrentUser();
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult map<TResult extends Object?>({
|
|
||||||
required TResult Function(_FetchCurrentUser value) fetchCurrentUser,
|
|
||||||
}) {
|
|
||||||
return fetchCurrentUser(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? mapOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function(_FetchCurrentUser value)? fetchCurrentUser,
|
|
||||||
}) {
|
|
||||||
return fetchCurrentUser?.call(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeMap<TResult extends Object?>({
|
|
||||||
TResult Function(_FetchCurrentUser value)? fetchCurrentUser,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (fetchCurrentUser != null) {
|
|
||||||
return fetchCurrentUser(this);
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class _FetchCurrentUser implements AuthEvent {
|
|
||||||
const factory _FetchCurrentUser() = _$FetchCurrentUserImpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
mixin _$AuthState {
|
|
||||||
User get user => throw _privateConstructorUsedError;
|
|
||||||
AuthStatus get status => throw _privateConstructorUsedError;
|
|
||||||
Option<AuthFailure> get failureOption => throw _privateConstructorUsedError;
|
|
||||||
bool get isFetching => throw _privateConstructorUsedError;
|
|
||||||
|
|
||||||
/// Create a copy of AuthState
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
|
||||||
$AuthStateCopyWith<AuthState> get copyWith =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class $AuthStateCopyWith<$Res> {
|
|
||||||
factory $AuthStateCopyWith(AuthState value, $Res Function(AuthState) then) =
|
|
||||||
_$AuthStateCopyWithImpl<$Res, AuthState>;
|
|
||||||
@useResult
|
|
||||||
$Res call({
|
|
||||||
User user,
|
|
||||||
AuthStatus status,
|
|
||||||
Option<AuthFailure> failureOption,
|
|
||||||
bool isFetching,
|
|
||||||
});
|
|
||||||
|
|
||||||
$UserCopyWith<$Res> get user;
|
|
||||||
$AuthStatusCopyWith<$Res> get status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class _$AuthStateCopyWithImpl<$Res, $Val extends AuthState>
|
|
||||||
implements $AuthStateCopyWith<$Res> {
|
|
||||||
_$AuthStateCopyWithImpl(this._value, this._then);
|
|
||||||
|
|
||||||
// ignore: unused_field
|
|
||||||
final $Val _value;
|
|
||||||
// ignore: unused_field
|
|
||||||
final $Res Function($Val) _then;
|
|
||||||
|
|
||||||
/// Create a copy of AuthState
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@pragma('vm:prefer-inline')
|
|
||||||
@override
|
|
||||||
$Res call({
|
|
||||||
Object? user = null,
|
|
||||||
Object? status = null,
|
|
||||||
Object? failureOption = null,
|
|
||||||
Object? isFetching = null,
|
|
||||||
}) {
|
|
||||||
return _then(
|
|
||||||
_value.copyWith(
|
|
||||||
user: null == user
|
|
||||||
? _value.user
|
|
||||||
: user // ignore: cast_nullable_to_non_nullable
|
|
||||||
as User,
|
|
||||||
status: null == status
|
|
||||||
? _value.status
|
|
||||||
: status // ignore: cast_nullable_to_non_nullable
|
|
||||||
as AuthStatus,
|
|
||||||
failureOption: null == failureOption
|
|
||||||
? _value.failureOption
|
|
||||||
: failureOption // ignore: cast_nullable_to_non_nullable
|
|
||||||
as Option<AuthFailure>,
|
|
||||||
isFetching: null == isFetching
|
|
||||||
? _value.isFetching
|
|
||||||
: isFetching // ignore: cast_nullable_to_non_nullable
|
|
||||||
as bool,
|
|
||||||
)
|
|
||||||
as $Val,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a copy of AuthState
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@override
|
|
||||||
@pragma('vm:prefer-inline')
|
|
||||||
$UserCopyWith<$Res> get user {
|
|
||||||
return $UserCopyWith<$Res>(_value.user, (value) {
|
|
||||||
return _then(_value.copyWith(user: value) as $Val);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a copy of AuthState
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@override
|
|
||||||
@pragma('vm:prefer-inline')
|
|
||||||
$AuthStatusCopyWith<$Res> get status {
|
|
||||||
return $AuthStatusCopyWith<$Res>(_value.status, (value) {
|
|
||||||
return _then(_value.copyWith(status: value) as $Val);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class _$$AuthStateImplCopyWith<$Res>
|
|
||||||
implements $AuthStateCopyWith<$Res> {
|
|
||||||
factory _$$AuthStateImplCopyWith(
|
|
||||||
_$AuthStateImpl value,
|
|
||||||
$Res Function(_$AuthStateImpl) then,
|
|
||||||
) = __$$AuthStateImplCopyWithImpl<$Res>;
|
|
||||||
@override
|
|
||||||
@useResult
|
|
||||||
$Res call({
|
|
||||||
User user,
|
|
||||||
AuthStatus status,
|
|
||||||
Option<AuthFailure> failureOption,
|
|
||||||
bool isFetching,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
$UserCopyWith<$Res> get user;
|
|
||||||
@override
|
|
||||||
$AuthStatusCopyWith<$Res> get status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class __$$AuthStateImplCopyWithImpl<$Res>
|
|
||||||
extends _$AuthStateCopyWithImpl<$Res, _$AuthStateImpl>
|
|
||||||
implements _$$AuthStateImplCopyWith<$Res> {
|
|
||||||
__$$AuthStateImplCopyWithImpl(
|
|
||||||
_$AuthStateImpl _value,
|
|
||||||
$Res Function(_$AuthStateImpl) _then,
|
|
||||||
) : super(_value, _then);
|
|
||||||
|
|
||||||
/// Create a copy of AuthState
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@pragma('vm:prefer-inline')
|
|
||||||
@override
|
|
||||||
$Res call({
|
|
||||||
Object? user = null,
|
|
||||||
Object? status = null,
|
|
||||||
Object? failureOption = null,
|
|
||||||
Object? isFetching = null,
|
|
||||||
}) {
|
|
||||||
return _then(
|
|
||||||
_$AuthStateImpl(
|
|
||||||
user: null == user
|
|
||||||
? _value.user
|
|
||||||
: user // ignore: cast_nullable_to_non_nullable
|
|
||||||
as User,
|
|
||||||
status: null == status
|
|
||||||
? _value.status
|
|
||||||
: status // ignore: cast_nullable_to_non_nullable
|
|
||||||
as AuthStatus,
|
|
||||||
failureOption: null == failureOption
|
|
||||||
? _value.failureOption
|
|
||||||
: failureOption // ignore: cast_nullable_to_non_nullable
|
|
||||||
as Option<AuthFailure>,
|
|
||||||
isFetching: null == isFetching
|
|
||||||
? _value.isFetching
|
|
||||||
: isFetching // ignore: cast_nullable_to_non_nullable
|
|
||||||
as bool,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
|
|
||||||
class _$AuthStateImpl extends _AuthState {
|
|
||||||
const _$AuthStateImpl({
|
|
||||||
required this.user,
|
|
||||||
this.status = const AuthStatus.initial(),
|
|
||||||
required this.failureOption,
|
|
||||||
this.isFetching = false,
|
|
||||||
}) : super._();
|
|
||||||
|
|
||||||
@override
|
|
||||||
final User user;
|
|
||||||
@override
|
|
||||||
@JsonKey()
|
|
||||||
final AuthStatus status;
|
|
||||||
@override
|
|
||||||
final Option<AuthFailure> failureOption;
|
|
||||||
@override
|
|
||||||
@JsonKey()
|
|
||||||
final bool isFetching;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'AuthState(user: $user, status: $status, failureOption: $failureOption, isFetching: $isFetching)';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return identical(this, other) ||
|
|
||||||
(other.runtimeType == runtimeType &&
|
|
||||||
other is _$AuthStateImpl &&
|
|
||||||
(identical(other.user, user) || other.user == user) &&
|
|
||||||
(identical(other.status, status) || other.status == status) &&
|
|
||||||
(identical(other.failureOption, failureOption) ||
|
|
||||||
other.failureOption == failureOption) &&
|
|
||||||
(identical(other.isFetching, isFetching) ||
|
|
||||||
other.isFetching == isFetching));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode =>
|
|
||||||
Object.hash(runtimeType, user, status, failureOption, isFetching);
|
|
||||||
|
|
||||||
/// Create a copy of AuthState
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
|
||||||
@override
|
|
||||||
@pragma('vm:prefer-inline')
|
|
||||||
_$$AuthStateImplCopyWith<_$AuthStateImpl> get copyWith =>
|
|
||||||
__$$AuthStateImplCopyWithImpl<_$AuthStateImpl>(this, _$identity);
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class _AuthState extends AuthState {
|
|
||||||
const factory _AuthState({
|
|
||||||
required final User user,
|
|
||||||
final AuthStatus status,
|
|
||||||
required final Option<AuthFailure> failureOption,
|
|
||||||
final bool isFetching,
|
|
||||||
}) = _$AuthStateImpl;
|
|
||||||
const _AuthState._() : super._();
|
|
||||||
|
|
||||||
@override
|
|
||||||
User get user;
|
|
||||||
@override
|
|
||||||
AuthStatus get status;
|
|
||||||
@override
|
|
||||||
Option<AuthFailure> get failureOption;
|
|
||||||
@override
|
|
||||||
bool get isFetching;
|
|
||||||
|
|
||||||
/// Create a copy of AuthState
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
@override
|
|
||||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
|
||||||
_$$AuthStateImplCopyWith<_$AuthStateImpl> get copyWith =>
|
|
||||||
throw _privateConstructorUsedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
mixin _$AuthStatus {
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult when<TResult extends Object?>({
|
|
||||||
required TResult Function() authenticated,
|
|
||||||
required TResult Function() unauthenticated,
|
|
||||||
required TResult Function() initial,
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? whenOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function()? authenticated,
|
|
||||||
TResult? Function()? unauthenticated,
|
|
||||||
TResult? Function()? initial,
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
|
||||||
TResult Function()? authenticated,
|
|
||||||
TResult Function()? unauthenticated,
|
|
||||||
TResult Function()? initial,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult map<TResult extends Object?>({
|
|
||||||
required TResult Function(_Authenticated value) authenticated,
|
|
||||||
required TResult Function(_Unauthenticated value) unauthenticated,
|
|
||||||
required TResult Function(_Initial value) initial,
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? mapOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function(_Authenticated value)? authenticated,
|
|
||||||
TResult? Function(_Unauthenticated value)? unauthenticated,
|
|
||||||
TResult? Function(_Initial value)? initial,
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeMap<TResult extends Object?>({
|
|
||||||
TResult Function(_Authenticated value)? authenticated,
|
|
||||||
TResult Function(_Unauthenticated value)? unauthenticated,
|
|
||||||
TResult Function(_Initial value)? initial,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) => throw _privateConstructorUsedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class $AuthStatusCopyWith<$Res> {
|
|
||||||
factory $AuthStatusCopyWith(
|
|
||||||
AuthStatus value,
|
|
||||||
$Res Function(AuthStatus) then,
|
|
||||||
) = _$AuthStatusCopyWithImpl<$Res, AuthStatus>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class _$AuthStatusCopyWithImpl<$Res, $Val extends AuthStatus>
|
|
||||||
implements $AuthStatusCopyWith<$Res> {
|
|
||||||
_$AuthStatusCopyWithImpl(this._value, this._then);
|
|
||||||
|
|
||||||
// ignore: unused_field
|
|
||||||
final $Val _value;
|
|
||||||
// ignore: unused_field
|
|
||||||
final $Res Function($Val) _then;
|
|
||||||
|
|
||||||
/// Create a copy of AuthStatus
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class _$$AuthenticatedImplCopyWith<$Res> {
|
|
||||||
factory _$$AuthenticatedImplCopyWith(
|
|
||||||
_$AuthenticatedImpl value,
|
|
||||||
$Res Function(_$AuthenticatedImpl) then,
|
|
||||||
) = __$$AuthenticatedImplCopyWithImpl<$Res>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class __$$AuthenticatedImplCopyWithImpl<$Res>
|
|
||||||
extends _$AuthStatusCopyWithImpl<$Res, _$AuthenticatedImpl>
|
|
||||||
implements _$$AuthenticatedImplCopyWith<$Res> {
|
|
||||||
__$$AuthenticatedImplCopyWithImpl(
|
|
||||||
_$AuthenticatedImpl _value,
|
|
||||||
$Res Function(_$AuthenticatedImpl) _then,
|
|
||||||
) : super(_value, _then);
|
|
||||||
|
|
||||||
/// Create a copy of AuthStatus
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
|
|
||||||
class _$AuthenticatedImpl implements _Authenticated {
|
|
||||||
const _$AuthenticatedImpl();
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'AuthStatus.authenticated()';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return identical(this, other) ||
|
|
||||||
(other.runtimeType == runtimeType && other is _$AuthenticatedImpl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => runtimeType.hashCode;
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult when<TResult extends Object?>({
|
|
||||||
required TResult Function() authenticated,
|
|
||||||
required TResult Function() unauthenticated,
|
|
||||||
required TResult Function() initial,
|
|
||||||
}) {
|
|
||||||
return authenticated();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? whenOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function()? authenticated,
|
|
||||||
TResult? Function()? unauthenticated,
|
|
||||||
TResult? Function()? initial,
|
|
||||||
}) {
|
|
||||||
return authenticated?.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
|
||||||
TResult Function()? authenticated,
|
|
||||||
TResult Function()? unauthenticated,
|
|
||||||
TResult Function()? initial,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (authenticated != null) {
|
|
||||||
return authenticated();
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult map<TResult extends Object?>({
|
|
||||||
required TResult Function(_Authenticated value) authenticated,
|
|
||||||
required TResult Function(_Unauthenticated value) unauthenticated,
|
|
||||||
required TResult Function(_Initial value) initial,
|
|
||||||
}) {
|
|
||||||
return authenticated(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? mapOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function(_Authenticated value)? authenticated,
|
|
||||||
TResult? Function(_Unauthenticated value)? unauthenticated,
|
|
||||||
TResult? Function(_Initial value)? initial,
|
|
||||||
}) {
|
|
||||||
return authenticated?.call(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeMap<TResult extends Object?>({
|
|
||||||
TResult Function(_Authenticated value)? authenticated,
|
|
||||||
TResult Function(_Unauthenticated value)? unauthenticated,
|
|
||||||
TResult Function(_Initial value)? initial,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (authenticated != null) {
|
|
||||||
return authenticated(this);
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class _Authenticated implements AuthStatus {
|
|
||||||
const factory _Authenticated() = _$AuthenticatedImpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class _$$UnauthenticatedImplCopyWith<$Res> {
|
|
||||||
factory _$$UnauthenticatedImplCopyWith(
|
|
||||||
_$UnauthenticatedImpl value,
|
|
||||||
$Res Function(_$UnauthenticatedImpl) then,
|
|
||||||
) = __$$UnauthenticatedImplCopyWithImpl<$Res>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class __$$UnauthenticatedImplCopyWithImpl<$Res>
|
|
||||||
extends _$AuthStatusCopyWithImpl<$Res, _$UnauthenticatedImpl>
|
|
||||||
implements _$$UnauthenticatedImplCopyWith<$Res> {
|
|
||||||
__$$UnauthenticatedImplCopyWithImpl(
|
|
||||||
_$UnauthenticatedImpl _value,
|
|
||||||
$Res Function(_$UnauthenticatedImpl) _then,
|
|
||||||
) : super(_value, _then);
|
|
||||||
|
|
||||||
/// Create a copy of AuthStatus
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
|
|
||||||
class _$UnauthenticatedImpl implements _Unauthenticated {
|
|
||||||
const _$UnauthenticatedImpl();
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'AuthStatus.unauthenticated()';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return identical(this, other) ||
|
|
||||||
(other.runtimeType == runtimeType && other is _$UnauthenticatedImpl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => runtimeType.hashCode;
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult when<TResult extends Object?>({
|
|
||||||
required TResult Function() authenticated,
|
|
||||||
required TResult Function() unauthenticated,
|
|
||||||
required TResult Function() initial,
|
|
||||||
}) {
|
|
||||||
return unauthenticated();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? whenOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function()? authenticated,
|
|
||||||
TResult? Function()? unauthenticated,
|
|
||||||
TResult? Function()? initial,
|
|
||||||
}) {
|
|
||||||
return unauthenticated?.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
|
||||||
TResult Function()? authenticated,
|
|
||||||
TResult Function()? unauthenticated,
|
|
||||||
TResult Function()? initial,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (unauthenticated != null) {
|
|
||||||
return unauthenticated();
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult map<TResult extends Object?>({
|
|
||||||
required TResult Function(_Authenticated value) authenticated,
|
|
||||||
required TResult Function(_Unauthenticated value) unauthenticated,
|
|
||||||
required TResult Function(_Initial value) initial,
|
|
||||||
}) {
|
|
||||||
return unauthenticated(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? mapOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function(_Authenticated value)? authenticated,
|
|
||||||
TResult? Function(_Unauthenticated value)? unauthenticated,
|
|
||||||
TResult? Function(_Initial value)? initial,
|
|
||||||
}) {
|
|
||||||
return unauthenticated?.call(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeMap<TResult extends Object?>({
|
|
||||||
TResult Function(_Authenticated value)? authenticated,
|
|
||||||
TResult Function(_Unauthenticated value)? unauthenticated,
|
|
||||||
TResult Function(_Initial value)? initial,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (unauthenticated != null) {
|
|
||||||
return unauthenticated(this);
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class _Unauthenticated implements AuthStatus {
|
|
||||||
const factory _Unauthenticated() = _$UnauthenticatedImpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
abstract class _$$InitialImplCopyWith<$Res> {
|
|
||||||
factory _$$InitialImplCopyWith(
|
|
||||||
_$InitialImpl value,
|
|
||||||
$Res Function(_$InitialImpl) then,
|
|
||||||
) = __$$InitialImplCopyWithImpl<$Res>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
class __$$InitialImplCopyWithImpl<$Res>
|
|
||||||
extends _$AuthStatusCopyWithImpl<$Res, _$InitialImpl>
|
|
||||||
implements _$$InitialImplCopyWith<$Res> {
|
|
||||||
__$$InitialImplCopyWithImpl(
|
|
||||||
_$InitialImpl _value,
|
|
||||||
$Res Function(_$InitialImpl) _then,
|
|
||||||
) : super(_value, _then);
|
|
||||||
|
|
||||||
/// Create a copy of AuthStatus
|
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @nodoc
|
|
||||||
|
|
||||||
class _$InitialImpl implements _Initial {
|
|
||||||
const _$InitialImpl();
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'AuthStatus.initial()';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return identical(this, other) ||
|
|
||||||
(other.runtimeType == runtimeType && other is _$InitialImpl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => runtimeType.hashCode;
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult when<TResult extends Object?>({
|
|
||||||
required TResult Function() authenticated,
|
|
||||||
required TResult Function() unauthenticated,
|
|
||||||
required TResult Function() initial,
|
|
||||||
}) {
|
|
||||||
return initial();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? whenOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function()? authenticated,
|
|
||||||
TResult? Function()? unauthenticated,
|
|
||||||
TResult? Function()? initial,
|
|
||||||
}) {
|
|
||||||
return initial?.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeWhen<TResult extends Object?>({
|
|
||||||
TResult Function()? authenticated,
|
|
||||||
TResult Function()? unauthenticated,
|
|
||||||
TResult Function()? initial,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (initial != null) {
|
|
||||||
return initial();
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult map<TResult extends Object?>({
|
|
||||||
required TResult Function(_Authenticated value) authenticated,
|
|
||||||
required TResult Function(_Unauthenticated value) unauthenticated,
|
|
||||||
required TResult Function(_Initial value) initial,
|
|
||||||
}) {
|
|
||||||
return initial(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult? mapOrNull<TResult extends Object?>({
|
|
||||||
TResult? Function(_Authenticated value)? authenticated,
|
|
||||||
TResult? Function(_Unauthenticated value)? unauthenticated,
|
|
||||||
TResult? Function(_Initial value)? initial,
|
|
||||||
}) {
|
|
||||||
return initial?.call(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
@optionalTypeArgs
|
|
||||||
TResult maybeMap<TResult extends Object?>({
|
|
||||||
TResult Function(_Authenticated value)? authenticated,
|
|
||||||
TResult Function(_Unauthenticated value)? unauthenticated,
|
|
||||||
TResult Function(_Initial value)? initial,
|
|
||||||
required TResult orElse(),
|
|
||||||
}) {
|
|
||||||
if (initial != null) {
|
|
||||||
return initial(this);
|
|
||||||
}
|
|
||||||
return orElse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class _Initial implements AuthStatus {
|
|
||||||
const factory _Initial() = _$InitialImpl;
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
part of 'auth_bloc.dart';
|
|
||||||
|
|
||||||
@freezed
|
|
||||||
class AuthEvent with _$AuthEvent {
|
|
||||||
const factory AuthEvent.fetchCurrentUser() = _FetchCurrentUser;
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
part of 'auth_bloc.dart';
|
|
||||||
|
|
||||||
@freezed
|
|
||||||
class AuthState with _$AuthState {
|
|
||||||
const AuthState._();
|
|
||||||
|
|
||||||
const factory AuthState({
|
|
||||||
required User user,
|
|
||||||
@Default(AuthStatus.initial()) AuthStatus status,
|
|
||||||
required Option<AuthFailure> failureOption,
|
|
||||||
@Default(false) bool isFetching,
|
|
||||||
}) = _AuthState;
|
|
||||||
|
|
||||||
factory AuthState.initial() =>
|
|
||||||
AuthState(user: User.empty(), failureOption: none());
|
|
||||||
|
|
||||||
bool get isAuthenticated => status == const AuthStatus.authenticated();
|
|
||||||
bool get isInitial => status == const AuthStatus.initial();
|
|
||||||
}
|
|
||||||
|
|
||||||
@freezed
|
|
||||||
sealed class AuthStatus with _$AuthStatus {
|
|
||||||
const factory AuthStatus.authenticated() = _Authenticated;
|
|
||||||
const factory AuthStatus.unauthenticated() = _Unauthenticated;
|
|
||||||
const factory AuthStatus.initial() = _Initial;
|
|
||||||
}
|
|
||||||
@ -39,8 +39,6 @@ class AppColor {
|
|||||||
static const Color white = Color(0xFFFFFFFF);
|
static const Color white = Color(0xFFFFFFFF);
|
||||||
static const Color black = Color(0xFF000000);
|
static const Color black = Color(0xFF000000);
|
||||||
|
|
||||||
static const Color disabled = Color(0xFFC8D1E1);
|
|
||||||
|
|
||||||
// Gradient Colors
|
// Gradient Colors
|
||||||
static const List<Color> primaryGradient = [
|
static const List<Color> primaryGradient = [
|
||||||
Color(0xFF36175e),
|
Color(0xFF36175e),
|
||||||
|
|||||||
@ -5,6 +5,4 @@ abstract class IAuthRepository {
|
|||||||
required String email,
|
required String email,
|
||||||
required String password,
|
required String password,
|
||||||
});
|
});
|
||||||
Future<bool> hasToken();
|
|
||||||
Future<Either<AuthFailure, User>> currentUser();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,20 +41,4 @@ class AuthRepository implements IAuthRepository {
|
|||||||
return left(const AuthFailure.unexpectedError());
|
return left(const AuthFailure.unexpectedError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<Either<AuthFailure, User>> currentUser() async {
|
|
||||||
try {
|
|
||||||
User user = await _localDataProvider.currentUser();
|
|
||||||
return right(user);
|
|
||||||
} catch (e, s) {
|
|
||||||
log('currentUserError', name: _logName, error: e, stackTrace: s);
|
|
||||||
return left(const AuthFailure.unexpectedError());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> hasToken() async {
|
|
||||||
return await _localDataProvider.hasToken();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,6 @@
|
|||||||
// coverage:ignore-file
|
// coverage:ignore-file
|
||||||
|
|
||||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||||
import 'package:apskel_pos_flutter_v2/application/auth/auth_bloc.dart' as _i343;
|
|
||||||
import 'package:apskel_pos_flutter_v2/application/auth/bloc/login_form_bloc.dart'
|
import 'package:apskel_pos_flutter_v2/application/auth/bloc/login_form_bloc.dart'
|
||||||
as _i185;
|
as _i185;
|
||||||
import 'package:apskel_pos_flutter_v2/common/api/api_client.dart' as _i457;
|
import 'package:apskel_pos_flutter_v2/common/api/api_client.dart' as _i457;
|
||||||
@ -77,9 +76,6 @@ extension GetItInjectableX on _i174.GetIt {
|
|||||||
gh<_i204.AuthLocalDataProvider>(),
|
gh<_i204.AuthLocalDataProvider>(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
gh.factory<_i343.AuthBloc>(
|
|
||||||
() => _i343.AuthBloc(gh<_i776.IAuthRepository>()),
|
|
||||||
);
|
|
||||||
gh.factory<_i185.LoginFormBloc>(
|
gh.factory<_i185.LoginFormBloc>(
|
||||||
() => _i185.LoginFormBloc(gh<_i776.IAuthRepository>()),
|
() => _i185.LoginFormBloc(gh<_i776.IAuthRepository>()),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
|
|
||||||
import '../application/auth/auth_bloc.dart';
|
|
||||||
import '../common/theme/theme.dart';
|
import '../common/theme/theme.dart';
|
||||||
import '../common/constant/app_constant.dart';
|
import '../common/constant/app_constant.dart';
|
||||||
import '../injection.dart';
|
import '../injection.dart';
|
||||||
@ -20,15 +18,12 @@ class _AppWidgetState extends State<AppWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return MaterialApp.router(
|
||||||
create: (context) => getIt<AuthBloc>(),
|
debugShowCheckedModeBanner: false,
|
||||||
child: MaterialApp.router(
|
title: AppConstant.appName,
|
||||||
debugShowCheckedModeBanner: false,
|
theme: ThemeApp.theme,
|
||||||
title: AppConstant.appName,
|
routerConfig: _appRouter.config(
|
||||||
theme: ThemeApp.theme,
|
navigatorObservers: () => <NavigatorObserver>[AppRouteObserver()],
|
||||||
routerConfig: _appRouter.config(
|
|
||||||
navigatorObservers: () => <NavigatorObserver>[AppRouteObserver()],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,12 +17,8 @@ class $AssetsImagesGen {
|
|||||||
/// File path: assets/images/logo.png
|
/// File path: assets/images/logo.png
|
||||||
AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
|
AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
|
||||||
|
|
||||||
/// File path: assets/images/logo_white.png
|
|
||||||
AssetGenImage get logoWhite =>
|
|
||||||
const AssetGenImage('assets/images/logo_white.png');
|
|
||||||
|
|
||||||
/// List of all assets
|
/// List of all assets
|
||||||
List<AssetGenImage> get values => [logo, logoWhite];
|
List<AssetGenImage> get values => [logo];
|
||||||
}
|
}
|
||||||
|
|
||||||
class Assets {
|
class Assets {
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import '../../../components/assets/assets.gen.dart';
|
|||||||
import '../../../components/button/button.dart';
|
import '../../../components/button/button.dart';
|
||||||
import '../../../components/spaces/space.dart';
|
import '../../../components/spaces/space.dart';
|
||||||
import '../../../components/toast/flushbar.dart';
|
import '../../../components/toast/flushbar.dart';
|
||||||
import '../../../router/app_router.gr.dart';
|
|
||||||
import 'widgets/email_field.dart';
|
import 'widgets/email_field.dart';
|
||||||
import 'widgets/password_field.dart';
|
import 'widgets/password_field.dart';
|
||||||
|
|
||||||
@ -30,8 +29,12 @@ class LoginPage extends StatelessWidget implements AutoRouteWrapper {
|
|||||||
(f) => AppFlushbar.showAuthFailureToast(context, f),
|
(f) => AppFlushbar.showAuthFailureToast(context, f),
|
||||||
(data) {
|
(data) {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
|
AppFlushbar.showSuccess(
|
||||||
|
context,
|
||||||
|
'Login berhasil! Selamat datang, ${data.user.name}.',
|
||||||
|
);
|
||||||
// context.read<AuthBloc>().add(AuthEvent.fetchCurrentUser());
|
// context.read<AuthBloc>().add(AuthEvent.fetchCurrentUser());
|
||||||
context.router.replace(const MainRoute());
|
// context.router.replace(const MainRoute());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,117 +0,0 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import '../../../common/theme/theme.dart';
|
|
||||||
import '../../components/assets/assets.gen.dart';
|
|
||||||
import '../../router/app_router.gr.dart';
|
|
||||||
|
|
||||||
@RoutePage()
|
|
||||||
class MainPage extends StatelessWidget {
|
|
||||||
const MainPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return AutoTabsRouter(
|
|
||||||
routes: [
|
|
||||||
HomeRoute(),
|
|
||||||
TableRoute(),
|
|
||||||
ReportRoute(),
|
|
||||||
CustomerRoute(),
|
|
||||||
SettingRoute(),
|
|
||||||
],
|
|
||||||
builder: (context, child) {
|
|
||||||
final tabsRouter = AutoTabsRouter.of(context);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
body: Row(
|
|
||||||
children: [
|
|
||||||
NavigationRail(
|
|
||||||
selectedIndex: tabsRouter.activeIndex,
|
|
||||||
onDestinationSelected: tabsRouter.setActiveIndex,
|
|
||||||
labelType: NavigationRailLabelType.none,
|
|
||||||
backgroundColor: AppColor.primary,
|
|
||||||
selectedIconTheme: const IconThemeData(color: Colors.white),
|
|
||||||
indicatorColor: AppColor.disabled.withOpacity(0.25),
|
|
||||||
indicatorShape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8.0),
|
|
||||||
),
|
|
||||||
minExtendedWidth: 56,
|
|
||||||
leading: Padding(
|
|
||||||
padding: EdgeInsets.all(8.0),
|
|
||||||
child: Assets.images.logoWhite.image(
|
|
||||||
width: 40,
|
|
||||||
height: 40,
|
|
||||||
fit: BoxFit.contain,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
trailing: Expanded(
|
|
||||||
child: Align(
|
|
||||||
alignment: Alignment.bottomCenter,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 16.0),
|
|
||||||
child: IconButton(
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.logout,
|
|
||||||
color: AppColor.disabled,
|
|
||||||
),
|
|
||||||
onPressed: () {},
|
|
||||||
tooltip: 'Logout',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
destinations: const [
|
|
||||||
NavigationRailDestination(
|
|
||||||
icon: Icon(Icons.home_outlined, color: AppColor.disabled),
|
|
||||||
selectedIcon: Icon(Icons.home, color: AppColor.white),
|
|
||||||
label: Text('POS'),
|
|
||||||
padding: EdgeInsets.symmetric(vertical: 8),
|
|
||||||
),
|
|
||||||
NavigationRailDestination(
|
|
||||||
icon: Icon(
|
|
||||||
Icons.table_bar_outlined,
|
|
||||||
color: AppColor.disabled,
|
|
||||||
),
|
|
||||||
selectedIcon: Icon(Icons.person, color: AppColor.white),
|
|
||||||
label: Text('Meja'),
|
|
||||||
padding: EdgeInsets.symmetric(vertical: 8),
|
|
||||||
),
|
|
||||||
NavigationRailDestination(
|
|
||||||
icon: Icon(
|
|
||||||
Icons.pie_chart_outline_outlined,
|
|
||||||
color: AppColor.disabled,
|
|
||||||
),
|
|
||||||
selectedIcon: Icon(Icons.settings, color: AppColor.white),
|
|
||||||
label: Text('Laporan'),
|
|
||||||
padding: EdgeInsets.symmetric(vertical: 8),
|
|
||||||
),
|
|
||||||
NavigationRailDestination(
|
|
||||||
icon: Icon(
|
|
||||||
Icons.person_2_outlined,
|
|
||||||
color: AppColor.disabled,
|
|
||||||
),
|
|
||||||
selectedIcon: Icon(Icons.person_2, color: AppColor.white),
|
|
||||||
label: Text('Pelanggan'),
|
|
||||||
padding: EdgeInsets.symmetric(vertical: 8),
|
|
||||||
),
|
|
||||||
NavigationRailDestination(
|
|
||||||
icon: Icon(
|
|
||||||
Icons.settings_outlined,
|
|
||||||
color: AppColor.disabled,
|
|
||||||
),
|
|
||||||
selectedIcon: Icon(Icons.settings, color: AppColor.white),
|
|
||||||
label: Text('Pengaturan'),
|
|
||||||
padding: EdgeInsets.symmetric(vertical: 8),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const VerticalDivider(thickness: 1, width: 1),
|
|
||||||
// Main content area
|
|
||||||
Expanded(child: child),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
@RoutePage()
|
|
||||||
class CustomerPage extends StatelessWidget {
|
|
||||||
const CustomerPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const Placeholder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
@RoutePage()
|
|
||||||
class HomePage extends StatelessWidget {
|
|
||||||
const HomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const Center(child: Text('Home Page'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
@RoutePage()
|
|
||||||
class ReportPage extends StatelessWidget {
|
|
||||||
const ReportPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const Center(child: Text('Report Page'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
@RoutePage()
|
|
||||||
class SettingPage extends StatelessWidget {
|
|
||||||
const SettingPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const Center(child: Text('Setting Page'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
@RoutePage()
|
|
||||||
class TablePage extends StatelessWidget {
|
|
||||||
const TablePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Center(
|
|
||||||
child: Text(
|
|
||||||
'Table Page',
|
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,8 +1,6 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
|
|
||||||
import '../../../application/auth/auth_bloc.dart';
|
|
||||||
import '../../components/assets/assets.gen.dart';
|
import '../../components/assets/assets.gen.dart';
|
||||||
import '../../router/app_router.gr.dart';
|
import '../../router/app_router.gr.dart';
|
||||||
|
|
||||||
@ -17,11 +15,7 @@ class SplashPage extends StatefulWidget {
|
|||||||
class _SplashPageState extends State<SplashPage> {
|
class _SplashPageState extends State<SplashPage> {
|
||||||
_startDelay() => Future.delayed(const Duration(seconds: 2), _goNext);
|
_startDelay() => Future.delayed(const Duration(seconds: 2), _goNext);
|
||||||
|
|
||||||
_goNext() {
|
_goNext() => context.router.replace(const LoginRoute());
|
||||||
if (mounted) {
|
|
||||||
context.read<AuthBloc>().add(const AuthEvent.fetchCurrentUser());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -31,24 +25,14 @@ class _SplashPageState extends State<SplashPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocListener<AuthBloc, AuthState>(
|
return Scaffold(
|
||||||
listenWhen: (previous, current) => previous.status != current.status,
|
body: Center(
|
||||||
listener: (context, state) {
|
child: Padding(
|
||||||
if (state.isAuthenticated) {
|
padding: const EdgeInsets.all(20),
|
||||||
context.router.replace(const MainRoute());
|
child: Assets.images.logo.image(
|
||||||
} else {
|
width: 100,
|
||||||
context.router.replace(const LoginRoute());
|
height: 100,
|
||||||
}
|
fit: BoxFit.contain,
|
||||||
},
|
|
||||||
child: Scaffold(
|
|
||||||
body: Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(20),
|
|
||||||
child: Assets.images.logo.image(
|
|
||||||
width: 100,
|
|
||||||
height: 100,
|
|
||||||
fit: BoxFit.contain,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -8,19 +8,7 @@ class AppRouter extends RootStackRouter {
|
|||||||
// Splash
|
// Splash
|
||||||
AutoRoute(page: SplashRoute.page, initial: true),
|
AutoRoute(page: SplashRoute.page, initial: true),
|
||||||
|
|
||||||
// Auth
|
// Router
|
||||||
AutoRoute(page: LoginRoute.page),
|
AutoRoute(page: LoginRoute.page),
|
||||||
|
|
||||||
// Main
|
|
||||||
AutoRoute(
|
|
||||||
page: MainRoute.page,
|
|
||||||
children: [
|
|
||||||
AutoRoute(page: HomeRoute.page, initial: true),
|
|
||||||
AutoRoute(page: TableRoute.page),
|
|
||||||
AutoRoute(page: ReportRoute.page),
|
|
||||||
AutoRoute(page: CustomerRoute.page),
|
|
||||||
AutoRoute(page: SettingRoute.page),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,147 +10,39 @@
|
|||||||
|
|
||||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||||
import 'package:apskel_pos_flutter_v2/presentation/pages/auth/login/login_page.dart'
|
import 'package:apskel_pos_flutter_v2/presentation/pages/auth/login/login_page.dart'
|
||||||
as _i3;
|
|
||||||
import 'package:apskel_pos_flutter_v2/presentation/pages/main/main_page.dart'
|
|
||||||
as _i4;
|
|
||||||
import 'package:apskel_pos_flutter_v2/presentation/pages/main/pages/customer/customer_page.dart'
|
|
||||||
as _i1;
|
as _i1;
|
||||||
import 'package:apskel_pos_flutter_v2/presentation/pages/main/pages/home/home_page.dart'
|
|
||||||
as _i2;
|
|
||||||
import 'package:apskel_pos_flutter_v2/presentation/pages/main/pages/report/report_page.dart'
|
|
||||||
as _i5;
|
|
||||||
import 'package:apskel_pos_flutter_v2/presentation/pages/main/pages/setting/setting_page.dart'
|
|
||||||
as _i6;
|
|
||||||
import 'package:apskel_pos_flutter_v2/presentation/pages/main/pages/table/table_page.dart'
|
|
||||||
as _i8;
|
|
||||||
import 'package:apskel_pos_flutter_v2/presentation/pages/splash/splash_page.dart'
|
import 'package:apskel_pos_flutter_v2/presentation/pages/splash/splash_page.dart'
|
||||||
as _i7;
|
as _i2;
|
||||||
import 'package:auto_route/auto_route.dart' as _i9;
|
import 'package:auto_route/auto_route.dart' as _i3;
|
||||||
|
|
||||||
/// generated route for
|
/// generated route for
|
||||||
/// [_i1.CustomerPage]
|
/// [_i1.LoginPage]
|
||||||
class CustomerRoute extends _i9.PageRouteInfo<void> {
|
class LoginRoute extends _i3.PageRouteInfo<void> {
|
||||||
const CustomerRoute({List<_i9.PageRouteInfo>? children})
|
const LoginRoute({List<_i3.PageRouteInfo>? children})
|
||||||
: super(CustomerRoute.name, initialChildren: children);
|
|
||||||
|
|
||||||
static const String name = 'CustomerRoute';
|
|
||||||
|
|
||||||
static _i9.PageInfo page = _i9.PageInfo(
|
|
||||||
name,
|
|
||||||
builder: (data) {
|
|
||||||
return const _i1.CustomerPage();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// generated route for
|
|
||||||
/// [_i2.HomePage]
|
|
||||||
class HomeRoute extends _i9.PageRouteInfo<void> {
|
|
||||||
const HomeRoute({List<_i9.PageRouteInfo>? children})
|
|
||||||
: super(HomeRoute.name, initialChildren: children);
|
|
||||||
|
|
||||||
static const String name = 'HomeRoute';
|
|
||||||
|
|
||||||
static _i9.PageInfo page = _i9.PageInfo(
|
|
||||||
name,
|
|
||||||
builder: (data) {
|
|
||||||
return const _i2.HomePage();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// generated route for
|
|
||||||
/// [_i3.LoginPage]
|
|
||||||
class LoginRoute extends _i9.PageRouteInfo<void> {
|
|
||||||
const LoginRoute({List<_i9.PageRouteInfo>? children})
|
|
||||||
: super(LoginRoute.name, initialChildren: children);
|
: super(LoginRoute.name, initialChildren: children);
|
||||||
|
|
||||||
static const String name = 'LoginRoute';
|
static const String name = 'LoginRoute';
|
||||||
|
|
||||||
static _i9.PageInfo page = _i9.PageInfo(
|
static _i3.PageInfo page = _i3.PageInfo(
|
||||||
name,
|
name,
|
||||||
builder: (data) {
|
builder: (data) {
|
||||||
return _i9.WrappedRoute(child: const _i3.LoginPage());
|
return const _i1.LoginPage();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// generated route for
|
/// generated route for
|
||||||
/// [_i4.MainPage]
|
/// [_i2.SplashPage]
|
||||||
class MainRoute extends _i9.PageRouteInfo<void> {
|
class SplashRoute extends _i3.PageRouteInfo<void> {
|
||||||
const MainRoute({List<_i9.PageRouteInfo>? children})
|
const SplashRoute({List<_i3.PageRouteInfo>? children})
|
||||||
: super(MainRoute.name, initialChildren: children);
|
|
||||||
|
|
||||||
static const String name = 'MainRoute';
|
|
||||||
|
|
||||||
static _i9.PageInfo page = _i9.PageInfo(
|
|
||||||
name,
|
|
||||||
builder: (data) {
|
|
||||||
return const _i4.MainPage();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// generated route for
|
|
||||||
/// [_i5.ReportPage]
|
|
||||||
class ReportRoute extends _i9.PageRouteInfo<void> {
|
|
||||||
const ReportRoute({List<_i9.PageRouteInfo>? children})
|
|
||||||
: super(ReportRoute.name, initialChildren: children);
|
|
||||||
|
|
||||||
static const String name = 'ReportRoute';
|
|
||||||
|
|
||||||
static _i9.PageInfo page = _i9.PageInfo(
|
|
||||||
name,
|
|
||||||
builder: (data) {
|
|
||||||
return const _i5.ReportPage();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// generated route for
|
|
||||||
/// [_i6.SettingPage]
|
|
||||||
class SettingRoute extends _i9.PageRouteInfo<void> {
|
|
||||||
const SettingRoute({List<_i9.PageRouteInfo>? children})
|
|
||||||
: super(SettingRoute.name, initialChildren: children);
|
|
||||||
|
|
||||||
static const String name = 'SettingRoute';
|
|
||||||
|
|
||||||
static _i9.PageInfo page = _i9.PageInfo(
|
|
||||||
name,
|
|
||||||
builder: (data) {
|
|
||||||
return const _i6.SettingPage();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// generated route for
|
|
||||||
/// [_i7.SplashPage]
|
|
||||||
class SplashRoute extends _i9.PageRouteInfo<void> {
|
|
||||||
const SplashRoute({List<_i9.PageRouteInfo>? children})
|
|
||||||
: super(SplashRoute.name, initialChildren: children);
|
: super(SplashRoute.name, initialChildren: children);
|
||||||
|
|
||||||
static const String name = 'SplashRoute';
|
static const String name = 'SplashRoute';
|
||||||
|
|
||||||
static _i9.PageInfo page = _i9.PageInfo(
|
static _i3.PageInfo page = _i3.PageInfo(
|
||||||
name,
|
name,
|
||||||
builder: (data) {
|
builder: (data) {
|
||||||
return const _i7.SplashPage();
|
return const _i2.SplashPage();
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// generated route for
|
|
||||||
/// [_i8.TablePage]
|
|
||||||
class TableRoute extends _i9.PageRouteInfo<void> {
|
|
||||||
const TableRoute({List<_i9.PageRouteInfo>? children})
|
|
||||||
: super(TableRoute.name, initialChildren: children);
|
|
||||||
|
|
||||||
static const String name = 'TableRoute';
|
|
||||||
|
|
||||||
static _i9.PageInfo page = _i9.PageInfo(
|
|
||||||
name,
|
|
||||||
builder: (data) {
|
|
||||||
return const _i8.TablePage();
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user