Compare commits

..

No commits in common. "006486bc2a22f754b581c44d7a98993583253bd7" and "0ea1a6fa56d6abecf7672eebd99ebf86abe95701" have entirely different histories.

20 changed files with 212 additions and 1459 deletions

View File

@ -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(),
),
),
);
},
);
}
}

View File

@ -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;
}

View File

@ -1,6 +0,0 @@
part of 'auth_bloc.dart';
@freezed
class AuthEvent with _$AuthEvent {
const factory AuthEvent.fetchCurrentUser() = _FetchCurrentUser;
}

View File

@ -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;
}

View File

@ -1,4 +0,0 @@
class LocalStorageKey {
static const token = 'token';
static const user = 'user';
}

View File

@ -4,5 +4,5 @@ class ApiPath {
static String verify = '/api/v1/customer-auth/register/verify-otp'; static String verify = '/api/v1/customer-auth/register/verify-otp';
static String setPassword = '/api/v1/customer-auth/register/set-password'; static String setPassword = '/api/v1/customer-auth/register/set-password';
static String login = '/api/v1/customer-auth/login'; static String login = '/api/v1/customer-auth/login';
static String resend = '/api/v1/customer-auth/resend-otp'; static String resend = '/api/v1/customer-auth/register/resend-otp';
} }

View File

@ -31,10 +31,4 @@ abstract class IAuthRepository {
required String phoneNumber, required String phoneNumber,
required String purpose, required String purpose,
}); });
Future<bool> hasToken();
Future<Either<AuthFailure, User>> currentUser();
Future<Either<AuthFailure, Unit>> logout();
} }

View File

@ -1,60 +0,0 @@
import 'dart:convert';
import 'dart:developer';
import 'package:injectable/injectable.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../../common/constant/local_storage_key.dart';
import '../../../domain/auth/auth.dart';
import '../auth_dtos.dart';
@injectable
class AuthLocalDataProvider {
final SharedPreferences _sharedPreferences;
final String _logName = 'AuthLocalDataProvider';
AuthLocalDataProvider(this._sharedPreferences);
Future<void> saveToken(String token) async {
await _sharedPreferences.setString(LocalStorageKey.token, token);
}
Future<String?> getToken() async {
return _sharedPreferences.getString(LocalStorageKey.token);
}
Future<void> deleteToken() async {
await _sharedPreferences.remove(LocalStorageKey.token);
}
Future<bool> hasToken() async {
return _sharedPreferences.containsKey(LocalStorageKey.token);
}
Future<void> saveCurrentUser(UserDto user) async {
final userJsonString = jsonEncode(user.toJson());
await _sharedPreferences.setString(LocalStorageKey.user, userJsonString);
}
Future<User> currentUser() async {
final userString = _sharedPreferences.getString(LocalStorageKey.user);
if (userString == null) return User.empty();
final Map<String, dynamic> userMap = jsonDecode(userString);
final userDto = UserDto.fromJson(userMap);
return userDto.toDomain();
}
Future<void> deleteCurrentUser() async {
await _sharedPreferences.remove(LocalStorageKey.user);
}
Future<void> deleteAllAuth() async {
try {
await _sharedPreferences.remove(LocalStorageKey.token);
await _sharedPreferences.remove(LocalStorageKey.user);
} catch (e) {
log('deleteAllAuthError', name: _logName, error: e);
}
}
}

View File

@ -161,18 +161,12 @@ class AuthRemoteDataProvider {
if (response.data['success'] == false) { if (response.data['success'] == false) {
if ((response.data['errors'] as List).isNotEmpty) { if ((response.data['errors'] as List).isNotEmpty) {
if (response.data['errors'][0]['code'] == 900) { if (response.data['errors'][0]['code'] == "900") {
return DC.error( return DC.error(
AuthFailure.dynamicErrorMessage( AuthFailure.dynamicErrorMessage(
'Invalid Registration, Lakukan kembali dari awal', 'Invalid Registration, Lakukan kembali dari awal',
), ),
); );
} else if (response.data['errors'][0]['code'] == "304") {
return DC.error(
AuthFailure.dynamicErrorMessage(
response.data['errors'][0]['cause'],
),
);
} else { } else {
return DC.error( return DC.error(
AuthFailure.dynamicErrorMessage( AuthFailure.dynamicErrorMessage(

View File

@ -4,17 +4,15 @@ import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart'; import 'package:injectable/injectable.dart';
import '../../../domain/auth/auth.dart'; import '../../../domain/auth/auth.dart';
import '../datasources/local_data_provider.dart';
import '../datasources/remote_data_provider.dart'; import '../datasources/remote_data_provider.dart';
@Injectable(as: IAuthRepository) @Injectable(as: IAuthRepository)
class AuthRepository implements IAuthRepository { class AuthRepository implements IAuthRepository {
final AuthLocalDataProvider _localDataProvider;
final AuthRemoteDataProvider _remoteDataProvider; final AuthRemoteDataProvider _remoteDataProvider;
final String _logName = 'AuthRepository'; final String _logName = 'AuthRepository';
AuthRepository(this._remoteDataProvider, this._localDataProvider); AuthRepository(this._remoteDataProvider);
@override @override
Future<Either<AuthFailure, CheckPhone>> checkPhone({ Future<Either<AuthFailure, CheckPhone>> checkPhone({
@ -107,9 +105,6 @@ class AuthRepository implements IAuthRepository {
final auth = result.data!.toDomain(); final auth = result.data!.toDomain();
await _localDataProvider.saveToken(auth.accessToken);
await _localDataProvider.saveCurrentUser(result.data!.data!.user!);
return right(auth); return right(auth);
} catch (e, s) { } catch (e, s) {
log('setPasswordError', name: _logName, error: e, stackTrace: s); log('setPasswordError', name: _logName, error: e, stackTrace: s);
@ -134,9 +129,6 @@ class AuthRepository implements IAuthRepository {
final auth = result.data!.toDomain(); final auth = result.data!.toDomain();
await _localDataProvider.saveToken(auth.accessToken);
await _localDataProvider.saveCurrentUser(result.data!.data!.user!);
return right(auth); return right(auth);
} catch (e, s) { } catch (e, s) {
log('loginError', name: _logName, error: e, stackTrace: s); log('loginError', name: _logName, error: e, stackTrace: s);
@ -167,31 +159,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();
}
@override
Future<Either<AuthFailure, Unit>> logout() async {
try {
await _localDataProvider.deleteAllAuth();
return right(unit);
} catch (e, s) {
log('logoutError', name: _logName, error: e, stackTrace: s);
return left(const AuthFailure.unexpectedError());
}
}
} }

View File

@ -11,7 +11,6 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes // ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:connectivity_plus/connectivity_plus.dart' as _i895; import 'package:connectivity_plus/connectivity_plus.dart' as _i895;
import 'package:dio/dio.dart' as _i361; import 'package:dio/dio.dart' as _i361;
import 'package:enaklo/application/auth/auth_bloc.dart' as _i771;
import 'package:enaklo/application/auth/check_phone_form/check_phone_form_bloc.dart' import 'package:enaklo/application/auth/check_phone_form/check_phone_form_bloc.dart'
as _i869; as _i869;
import 'package:enaklo/application/auth/login_form/login_form_bloc.dart' import 'package:enaklo/application/auth/login_form/login_form_bloc.dart'
@ -32,8 +31,6 @@ import 'package:enaklo/common/di/di_shared_preferences.dart' as _i672;
import 'package:enaklo/common/network/network_client.dart' as _i109; import 'package:enaklo/common/network/network_client.dart' as _i109;
import 'package:enaklo/domain/auth/auth.dart' as _i995; import 'package:enaklo/domain/auth/auth.dart' as _i995;
import 'package:enaklo/env.dart' as _i372; import 'package:enaklo/env.dart' as _i372;
import 'package:enaklo/infrastructure/auth/datasources/local_data_provider.dart'
as _i1003;
import 'package:enaklo/infrastructure/auth/datasources/remote_data_provider.dart' import 'package:enaklo/infrastructure/auth/datasources/remote_data_provider.dart'
as _i818; as _i818;
import 'package:enaklo/infrastructure/auth/repositories/auth_repository.dart' import 'package:enaklo/infrastructure/auth/repositories/auth_repository.dart'
@ -68,9 +65,6 @@ extension GetItInjectableX on _i174.GetIt {
() => _i109.NetworkClient(gh<_i895.Connectivity>()), () => _i109.NetworkClient(gh<_i895.Connectivity>()),
); );
gh.factory<_i372.Env>(() => _i372.DevEnv(), registerFor: {_dev}); gh.factory<_i372.Env>(() => _i372.DevEnv(), registerFor: {_dev});
gh.factory<_i1003.AuthLocalDataProvider>(
() => _i1003.AuthLocalDataProvider(gh<_i460.SharedPreferences>()),
);
gh.factory<_i372.Env>(() => _i372.ProdEnv(), registerFor: {_prod}); gh.factory<_i372.Env>(() => _i372.ProdEnv(), registerFor: {_prod});
gh.lazySingleton<_i842.ApiClient>( gh.lazySingleton<_i842.ApiClient>(
() => _i842.ApiClient(gh<_i361.Dio>(), gh<_i372.Env>()), () => _i842.ApiClient(gh<_i361.Dio>(), gh<_i372.Env>()),
@ -79,10 +73,10 @@ extension GetItInjectableX on _i174.GetIt {
() => _i818.AuthRemoteDataProvider(gh<_i842.ApiClient>()), () => _i818.AuthRemoteDataProvider(gh<_i842.ApiClient>()),
); );
gh.factory<_i995.IAuthRepository>( gh.factory<_i995.IAuthRepository>(
() => _i879.AuthRepository( () => _i879.AuthRepository(gh<_i818.AuthRemoteDataProvider>()),
gh<_i818.AuthRemoteDataProvider>(), );
gh<_i1003.AuthLocalDataProvider>(), gh.factory<_i510.LoginFormBloc>(
), () => _i510.LoginFormBloc(gh<_i995.IAuthRepository>()),
); );
gh.factory<_i627.ResendFormBloc>( gh.factory<_i627.ResendFormBloc>(
() => _i627.ResendFormBloc(gh<_i995.IAuthRepository>()), () => _i627.ResendFormBloc(gh<_i995.IAuthRepository>()),
@ -99,12 +93,6 @@ extension GetItInjectableX on _i174.GetIt {
gh.factory<_i521.VerifyFormBloc>( gh.factory<_i521.VerifyFormBloc>(
() => _i521.VerifyFormBloc(gh<_i995.IAuthRepository>()), () => _i521.VerifyFormBloc(gh<_i995.IAuthRepository>()),
); );
gh.factory<_i771.AuthBloc>(
() => _i771.AuthBloc(gh<_i995.IAuthRepository>()),
);
gh.factory<_i510.LoginFormBloc>(
() => _i510.LoginFormBloc(gh<_i995.IAuthRepository>()),
);
return this; return this;
} }
} }

View File

@ -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 MultiBlocProvider( return MaterialApp.router(
providers: [BlocProvider(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()],
),
), ),
); );
} }

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../../../common/extension/extension.dart'; import '../../../common/extension/extension.dart';
import '../../../common/theme/theme.dart'; import '../../../common/theme/theme.dart';

View File

@ -16,7 +16,7 @@ class AppFlushbar {
), ),
icon: const Icon(Icons.check_circle, color: Colors.white), icon: const Icon(Icons.check_circle, color: Colors.white),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
flushbarPosition: FlushbarPosition.TOP, flushbarPosition: FlushbarPosition.BOTTOM,
backgroundColor: AppColor.secondary, backgroundColor: AppColor.secondary,
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
margin: const EdgeInsets.all(12), margin: const EdgeInsets.all(12),
@ -35,7 +35,7 @@ class AppFlushbar {
), ),
icon: const Icon(Icons.error, color: Colors.white), icon: const Icon(Icons.error, color: Colors.white),
duration: const Duration(seconds: 3), duration: const Duration(seconds: 3),
flushbarPosition: FlushbarPosition.TOP, flushbarPosition: FlushbarPosition.BOTTOM,
backgroundColor: AppColor.error, backgroundColor: AppColor.error,
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
margin: const EdgeInsets.all(12), margin: const EdgeInsets.all(12),

View File

@ -1,136 +1,50 @@
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 '../../../../application/auth/set_password/set_password_form_bloc.dart';
import '../../../../injection.dart';
import '../../../components/button/button.dart'; import '../../../components/button/button.dart';
import '../../../components/field/field.dart'; import '../../../components/field/field.dart';
import '../../../components/toast/flushbar.dart';
import '../../../router/app_router.gr.dart'; import '../../../router/app_router.gr.dart';
@RoutePage() @RoutePage()
class CreatePasswordPage extends StatelessWidget implements AutoRouteWrapper { class CreatePasswordPage extends StatelessWidget {
final String registrationToken; const CreatePasswordPage({super.key});
const CreatePasswordPage({super.key, required this.registrationToken});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocListener<SetPasswordFormBloc, SetPasswordFormState>( return Scaffold(
listenWhen: (p, c) => appBar: AppBar(title: const Text('Buat Kata Sandi')),
p.failureOrSetPasswordOption != c.failureOrSetPasswordOption, body: Padding(
listener: (context, state) { padding: const EdgeInsets.symmetric(horizontal: 24.0),
state.failureOrSetPasswordOption.fold( child: Column(
() => null, crossAxisAlignment: CrossAxisAlignment.start,
(either) => either.fold( children: [
(f) => AppFlushbar.showAuthFailureToast(context, f), const SizedBox(height: 40),
(data) {
AppFlushbar.showSuccess(context, data.message);
Future.delayed(Duration(milliseconds: 1000), () {
context.read<AuthBloc>().add(AuthEvent.fetchCurrentUser());
context.router.replaceAll([MainRoute()]);
});
},
),
);
},
child: Scaffold(
appBar: AppBar(title: const Text('Buat Kata Sandi')),
body: BlocBuilder<SetPasswordFormBloc, SetPasswordFormState>(
builder: (context, state) {
return Form(
autovalidateMode: state.showErrorMessages
? AutovalidateMode.always
: AutovalidateMode.disabled,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 40),
// Title // Title
AppPasswordTextFormField( AppPasswordTextFormField(
title: 'Masukkan kata sandi', title: 'Masukkan kata sandi',
hintText: '********', hintText: '********',
onChanged: (value) => context ),
.read<SetPasswordFormBloc>() SizedBox(height: 24),
.add(SetPasswordFormEvent.passwordChanged(value)), AppPasswordTextFormField(
validator: (value) { title: 'Ulangi kata sandi',
if (context hintText: '********',
.read<SetPasswordFormBloc>() ),
.state
.password
.isEmpty) {
return 'Masukkan kata sandi';
}
return null; const SizedBox(height: 50),
},
),
SizedBox(height: 24),
AppPasswordTextFormField(
title: 'Ulangi kata sandi',
hintText: '********',
onChanged: (value) =>
context.read<SetPasswordFormBloc>().add(
SetPasswordFormEvent.confirmPasswordChanged(value),
),
validator: (value) {
if (context
.read<SetPasswordFormBloc>()
.state
.password
.isEmpty) {
return 'Masukkan kata sandi';
}
if (context Spacer(),
.read<SetPasswordFormBloc>()
.state
.password !=
context
.read<SetPasswordFormBloc>()
.state
.confirmPassword) {
return 'Kata sandi tidak cocok';
}
return null; // Continue Button
}, AppElevatedButton(
), onPressed: () => context.router.push(const MainRoute()),
title: 'Konfirmasi',
),
const SizedBox(height: 50), const SizedBox(height: 24),
],
Spacer(),
// Continue Button
AppElevatedButton(
onPressed: state.isSubmitting
? null
: () => context.read<SetPasswordFormBloc>().add(
SetPasswordFormEvent.submitted(),
),
title: 'Konfirmasi',
isLoading: state.isSubmitting,
),
const SizedBox(height: 24),
],
),
),
);
},
), ),
), ),
); );
} }
@override
Widget wrappedRoute(BuildContext context) => BlocProvider(
create: (context) => getIt<SetPasswordFormBloc>()
..add(SetPasswordFormEvent.registrationTokenChanged(registrationToken)),
child: this,
);
} }

View File

@ -2,45 +2,17 @@ import 'dart:async';
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/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../application/auth/resend_form/resend_form_bloc.dart';
import '../../../../application/auth/verify_form/verify_form_bloc.dart';
import '../../../../common/theme/theme.dart'; import '../../../../common/theme/theme.dart';
import '../../../../domain/auth/auth.dart';
import '../../../../injection.dart';
import '../../../components/toast/flushbar.dart';
import '../../../router/app_router.gr.dart'; import '../../../router/app_router.gr.dart';
@RoutePage() @RoutePage()
class OtpPage extends StatefulWidget implements AutoRouteWrapper { class OtpPage extends StatefulWidget {
final String registrationToken; final String registrationToken;
final String phoneNumber; const OtpPage({super.key, required this.registrationToken});
const OtpPage({
super.key,
required this.registrationToken,
required this.phoneNumber,
});
@override @override
State<OtpPage> createState() => _OtpPageState(); State<OtpPage> createState() => _OtpPageState();
@override
Widget wrappedRoute(BuildContext context) => MultiBlocProvider(
providers: [
BlocProvider(
create: (context) => getIt<VerifyFormBloc>()
..add(VerifyFormEvent.registrationTokenChanged(registrationToken)),
),
BlocProvider(
create: (context) => getIt<ResendFormBloc>()
..add(ResendFormEvent.phoneNumberChanged(phoneNumber))
..add(ResendFormEvent.purposeChanged('registration')),
),
],
child: this,
);
} }
class _OtpPageState extends State<OtpPage> { class _OtpPageState extends State<OtpPage> {
@ -82,7 +54,6 @@ class _OtpPageState extends State<OtpPage> {
}); });
_startTimer(); _startTimer();
// Add your resend logic here // Add your resend logic here
context.read<ResendFormBloc>().add(ResendFormEvent.submitted());
} }
String _formatTime(int seconds) { String _formatTime(int seconds) {
@ -112,9 +83,7 @@ class _OtpPageState extends State<OtpPage> {
void _verifyCode() { void _verifyCode() {
String code = _controllers.map((controller) => controller.text).join(); String code = _controllers.map((controller) => controller.text).join();
if (code.length == 6) { if (code.length == 6) {
// context.router.push(CreatePasswordRoute()); context.router.push(CreatePasswordRoute());
context.read<VerifyFormBloc>().add(VerifyFormEvent.otpCodeChanged(code));
context.read<VerifyFormBloc>().add(VerifyFormEvent.submitted());
} }
} }
@ -132,189 +101,135 @@ class _OtpPageState extends State<OtpPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MultiBlocListener( return Scaffold(
listeners: [ appBar: AppBar(title: Text('Verifikasi')),
BlocListener<VerifyFormBloc, VerifyFormState>( body: Padding(
listenWhen: (p, c) => padding: const EdgeInsets.symmetric(horizontal: 20.0),
p.failureOrVerifyOption != c.failureOrVerifyOption, child: Column(
listener: (context, state) { crossAxisAlignment: CrossAxisAlignment.start,
state.failureOrVerifyOption.fold( children: [
() {}, const SizedBox(height: 20),
(either) => either.fold(
(f) => AppFlushbar.showAuthFailureToast(context, f), // Title
(data) { Text(
if (data.status == "FAILED") { 'Masukan Kode Verifikasi',
AppFlushbar.showSuccess(context, data.message); style: AppStyle.xl.copyWith(
Future.delayed(Duration(milliseconds: 1000), () { fontWeight: FontWeight.w600,
context.router.replaceAll([LoginRoute()]); color: AppColor.textPrimary,
});
} else {
AppFlushbar.showSuccess(context, data.message);
Future.delayed(Duration(milliseconds: 1000), () {
context.router.push(
CreatePasswordRoute(
registrationToken: widget.registrationToken,
),
);
});
}
},
), ),
); ),
},
),
BlocListener<ResendFormBloc, ResendFormState>(
listenWhen: (p, c) =>
p.failureOrResendOption != c.failureOrResendOption,
listener: (context, state) {
state.failureOrResendOption.fold(
() {},
(either) => either.fold(
(f) => AppFlushbar.showAuthFailureToast(context, f),
(data) {
if (data.status.isSuccess) {
AppFlushbar.showSuccess(context, data.message);
} else {
AppFlushbar.showError(context, data.message);
}
},
),
);
},
),
],
child: Scaffold(
appBar: AppBar(title: Text('Verifikasi')),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 20),
// Title const SizedBox(height: 12),
Text(
'Masukan Kode Verifikasi',
style: AppStyle.xl.copyWith(
fontWeight: FontWeight.w600,
color: AppColor.textPrimary,
),
),
const SizedBox(height: 12), // Description
RichText(
// Description text: TextSpan(
RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Kami telah mengirimkan kode verifikasi melalui ',
style: AppStyle.sm.copyWith(
color: AppColor.textSecondary,
height: 1.4,
),
),
TextSpan(
text: 'Whatsapp',
style: AppStyle.sm.copyWith(
color: AppColor.success,
fontWeight: FontWeight.w500,
height: 1.4,
),
),
TextSpan(
text: ' ke ',
style: AppStyle.sm.copyWith(
color: AppColor.textSecondary,
height: 1.4,
),
),
TextSpan(
text: '+${widget.phoneNumber}',
style: AppStyle.sm.copyWith(
color: AppColor.textPrimary,
fontWeight: FontWeight.w500,
height: 1.4,
),
),
],
),
),
const SizedBox(height: 6),
// Hidden text fields for input
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: List.generate(6, (index) {
return Expanded(
child: Padding(
padding: EdgeInsets.only(right: index == 5 ? 0 : 8.0),
child: TextFormField(
controller: _controllers[index],
focusNode: _focusNodes[index],
keyboardType: TextInputType.number,
maxLength: 1,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(counterText: ''),
textAlign: TextAlign.center,
style: AppStyle.lg.copyWith(
color: AppColor.primary,
fontWeight: FontWeight.w600,
),
cursorColor: AppColor.primary,
onChanged: (value) {
setState(() {});
_onCodeChanged(value, index);
},
),
),
);
}),
),
const SizedBox(height: 40),
// Timer and Resend Section
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Text( TextSpan(
'Mohon tunggu untuk kirim ulang kode ', text: 'Kami telah mengirimkan kode verifikasi melalui ',
style: AppStyle.xs.copyWith(color: AppColor.textSecondary), style: AppStyle.sm.copyWith(
),
Text(
_formatTime(_secondsRemaining),
style: AppStyle.xs.copyWith(
color: AppColor.textSecondary, color: AppColor.textSecondary,
height: 1.4,
),
),
TextSpan(
text: 'Whatsapp',
style: AppStyle.sm.copyWith(
color: AppColor.success,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
height: 1.4,
),
),
TextSpan(
text: ' ke ',
style: AppStyle.sm.copyWith(
color: AppColor.textSecondary,
height: 1.4,
),
),
TextSpan(
text: '+6288976680234',
style: AppStyle.sm.copyWith(
color: AppColor.textPrimary,
fontWeight: FontWeight.w500,
height: 1.4,
), ),
), ),
], ],
), ),
),
if (_canResend) ...[ const SizedBox(height: 6),
const SizedBox(height: 12),
Center( // Hidden text fields for input
child: TextButton( Row(
onPressed: _resendCode, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
child: Text( children: List.generate(6, (index) {
'Kirim Ulang Kode', return Expanded(
style: AppStyle.sm.copyWith( child: Padding(
color: AppColor.success, padding: EdgeInsets.only(right: index == 5 ? 0 : 8.0),
fontWeight: FontWeight.w500, child: TextFormField(
controller: _controllers[index],
focusNode: _focusNodes[index],
keyboardType: TextInputType.number,
maxLength: 1,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
decoration: InputDecoration(counterText: ''),
textAlign: TextAlign.center,
style: AppStyle.lg.copyWith(
color: AppColor.primary,
fontWeight: FontWeight.w600,
), ),
cursorColor: AppColor.primary,
onChanged: (value) {
setState(() {});
_onCodeChanged(value, index);
},
), ),
), ),
);
}),
),
const SizedBox(height: 40),
// Timer and Resend Section
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'Mohon tunggu untuk kirim ulang kode ',
style: AppStyle.xs.copyWith(color: AppColor.textSecondary),
),
Text(
_formatTime(_secondsRemaining),
style: AppStyle.xs.copyWith(
color: AppColor.textSecondary,
fontWeight: FontWeight.w500,
),
), ),
], ],
),
const SizedBox(height: 24), if (_canResend) ...[
const SizedBox(height: 12),
Center(
child: TextButton(
onPressed: _resendCode,
child: Text(
'Kirim Ulang Kode',
style: AppStyle.sm.copyWith(
color: AppColor.success,
fontWeight: FontWeight.w500,
),
),
),
),
], ],
),
const SizedBox(height: 24),
],
), ),
), ),
); );

View File

@ -2,7 +2,6 @@ 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 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../application/auth/auth_bloc.dart';
import '../../../../application/auth/login_form/login_form_bloc.dart'; import '../../../../application/auth/login_form/login_form_bloc.dart';
import '../../../../injection.dart'; import '../../../../injection.dart';
import '../../../components/button/button.dart'; import '../../../components/button/button.dart';
@ -27,7 +26,6 @@ class PasswordPage extends StatelessWidget implements AutoRouteWrapper {
(data) { (data) {
AppFlushbar.showSuccess(context, data.message); AppFlushbar.showSuccess(context, data.message);
Future.delayed(Duration(milliseconds: 1000), () { Future.delayed(Duration(milliseconds: 1000), () {
context.read<AuthBloc>().add(AuthEvent.fetchCurrentUser());
context.router.replaceAll([MainRoute()]); context.router.replaceAll([MainRoute()]);
}); });
}, },

View File

@ -29,10 +29,7 @@ class RegisterPage extends StatelessWidget implements AutoRouteWrapper {
AppFlushbar.showSuccess(context, data.message); AppFlushbar.showSuccess(context, data.message);
Future.delayed(Duration(milliseconds: 1000), () { Future.delayed(Duration(milliseconds: 1000), () {
context.router.push( context.router.push(
OtpRoute( OtpRoute(registrationToken: data.registrationToken),
registrationToken: data.registrationToken,
phoneNumber: phoneNumber,
),
); );
}); });
}, },

View File

@ -1,9 +1,7 @@
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 'dart:async'; import 'dart:async';
import '../../../application/auth/auth_bloc.dart';
import '../../../common/theme/theme.dart'; import '../../../common/theme/theme.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';
@ -56,9 +54,7 @@ class _SplashPageState extends State<SplashPage>
void _navigateToHome() { void _navigateToHome() {
Timer(const Duration(milliseconds: 2500), () { Timer(const Duration(milliseconds: 2500), () {
if (mounted) { context.router.push(OnboardingRoute());
context.read<AuthBloc>().add(const AuthEvent.fetchCurrentUser());
}
}); });
} }
@ -70,63 +66,53 @@ 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: Container(
listener: (context, state) { width: double.infinity,
if (state.isAuthenticated) { height: double.infinity,
context.router.replace(const MainRoute()); decoration: const BoxDecoration(
} else { gradient: LinearGradient(
context.router.replace(const OnboardingRoute()); begin: Alignment.topLeft,
} end: Alignment.bottomRight,
}, colors: [AppColor.backgroundLight, AppColor.background],
child: Scaffold(
body: Container(
width: double.infinity,
height: double.infinity,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [AppColor.backgroundLight, AppColor.background],
),
), ),
child: Center( ),
child: AnimatedBuilder( child: Center(
animation: _logoController, child: AnimatedBuilder(
builder: (context, child) { animation: _logoController,
return Transform.scale( builder: (context, child) {
scale: _logoScaleAnimation.value, return Transform.scale(
child: Opacity( scale: _logoScaleAnimation.value,
opacity: _logoOpacityAnimation.value, child: Opacity(
child: Container( opacity: _logoOpacityAnimation.value,
width: 140, child: Container(
height: 140, width: 140,
decoration: BoxDecoration( height: 140,
gradient: const LinearGradient( decoration: BoxDecoration(
colors: AppColor.primaryGradient, gradient: const LinearGradient(
begin: Alignment.topLeft, colors: AppColor.primaryGradient,
end: Alignment.bottomRight, begin: Alignment.topLeft,
), end: Alignment.bottomRight,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: AppColor.primaryWithOpacity(0.4),
blurRadius: 25,
offset: const Offset(0, 12),
),
],
), ),
child: ClipOval( shape: BoxShape.circle,
child: Padding( boxShadow: [
padding: const EdgeInsets.all(20), BoxShadow(
child: Assets.images.logo.image(fit: BoxFit.contain), color: AppColor.primaryWithOpacity(0.4),
blurRadius: 25,
offset: const Offset(0, 12),
), ),
],
),
child: ClipOval(
child: Padding(
padding: const EdgeInsets.all(20),
child: Assets.images.logo.image(fit: BoxFit.contain),
), ),
), ),
), ),
); ),
}, );
), },
), ),
), ),
), ),

View File

@ -102,49 +102,20 @@ class AddressRoute extends _i33.PageRouteInfo<void> {
/// generated route for /// generated route for
/// [_i3.CreatePasswordPage] /// [_i3.CreatePasswordPage]
class CreatePasswordRoute extends _i33.PageRouteInfo<CreatePasswordRouteArgs> { class CreatePasswordRoute extends _i33.PageRouteInfo<void> {
CreatePasswordRoute({ const CreatePasswordRoute({List<_i33.PageRouteInfo>? children})
_i34.Key? key, : super(CreatePasswordRoute.name, initialChildren: children);
required String registrationToken,
List<_i33.PageRouteInfo>? children,
}) : super(
CreatePasswordRoute.name,
args: CreatePasswordRouteArgs(
key: key,
registrationToken: registrationToken,
),
initialChildren: children,
);
static const String name = 'CreatePasswordRoute'; static const String name = 'CreatePasswordRoute';
static _i33.PageInfo page = _i33.PageInfo( static _i33.PageInfo page = _i33.PageInfo(
name, name,
builder: (data) { builder: (data) {
final args = data.argsAs<CreatePasswordRouteArgs>(); return const _i3.CreatePasswordPage();
return _i33.WrappedRoute(
child: _i3.CreatePasswordPage(
key: args.key,
registrationToken: args.registrationToken,
),
);
}, },
); );
} }
class CreatePasswordRouteArgs {
const CreatePasswordRouteArgs({this.key, required this.registrationToken});
final _i34.Key? key;
final String registrationToken;
@override
String toString() {
return 'CreatePasswordRouteArgs{key: $key, registrationToken: $registrationToken}';
}
}
/// generated route for /// generated route for
/// [_i4.DrawDetailPage] /// [_i4.DrawDetailPage]
class DrawDetailRoute extends _i33.PageRouteInfo<void> { class DrawDetailRoute extends _i33.PageRouteInfo<void> {
@ -449,15 +420,10 @@ class OtpRoute extends _i33.PageRouteInfo<OtpRouteArgs> {
OtpRoute({ OtpRoute({
_i34.Key? key, _i34.Key? key,
required String registrationToken, required String registrationToken,
required String phoneNumber,
List<_i33.PageRouteInfo>? children, List<_i33.PageRouteInfo>? children,
}) : super( }) : super(
OtpRoute.name, OtpRoute.name,
args: OtpRouteArgs( args: OtpRouteArgs(key: key, registrationToken: registrationToken),
key: key,
registrationToken: registrationToken,
phoneNumber: phoneNumber,
),
initialChildren: children, initialChildren: children,
); );
@ -467,33 +433,24 @@ class OtpRoute extends _i33.PageRouteInfo<OtpRouteArgs> {
name, name,
builder: (data) { builder: (data) {
final args = data.argsAs<OtpRouteArgs>(); final args = data.argsAs<OtpRouteArgs>();
return _i33.WrappedRoute( return _i20.OtpPage(
child: _i20.OtpPage( key: args.key,
key: args.key, registrationToken: args.registrationToken,
registrationToken: args.registrationToken,
phoneNumber: args.phoneNumber,
),
); );
}, },
); );
} }
class OtpRouteArgs { class OtpRouteArgs {
const OtpRouteArgs({ const OtpRouteArgs({this.key, required this.registrationToken});
this.key,
required this.registrationToken,
required this.phoneNumber,
});
final _i34.Key? key; final _i34.Key? key;
final String registrationToken; final String registrationToken;
final String phoneNumber;
@override @override
String toString() { String toString() {
return 'OtpRouteArgs{key: $key, registrationToken: $registrationToken, phoneNumber: $phoneNumber}'; return 'OtpRouteArgs{key: $key, registrationToken: $registrationToken}';
} }
} }