Приложение на флаторе, настройки
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
abstract class AuthLocalDataSource {
|
||||
Future<String?> getToken();
|
||||
Future<void> saveToken(String token);
|
||||
Future<void> removeToken();
|
||||
Future<String?> getUserId();
|
||||
Future<void> saveUserId(String userId);
|
||||
Future<void> removeUserId();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import '../../../../core/errors/result.dart';
|
||||
import '../../domain/entities/user.dart';
|
||||
|
||||
abstract class AuthRemoteDataSource {
|
||||
Future<Result<User>> login(String email, String password);
|
||||
Future<Result<User>> register(String email, String password, String name);
|
||||
Future<Result<void>> logout();
|
||||
Future<Result<User>> getCurrentUser();
|
||||
Future<Result<void>> refreshToken();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import '../../../../core/errors/errors.dart';
|
||||
import '../../../../core/errors/result.dart';
|
||||
import '../../domain/entities/user.dart';
|
||||
import '../../domain/repositories/auth_repository.dart';
|
||||
|
||||
class AuthRepositoryImpl implements AuthRepository {
|
||||
@override
|
||||
bool get isLoggedIn => false;
|
||||
|
||||
@override
|
||||
Future<Result<User>> getCurrentUser() async {
|
||||
return const Result.failure(AppError.unauthorized(message: 'Not logged in'));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<User>> login(String email, String password) async {
|
||||
// TODO: Implement real login
|
||||
return Result.success(
|
||||
User(
|
||||
id: '1',
|
||||
email: email,
|
||||
name: 'Test User',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> logout() async {
|
||||
return const Result.success(null);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<User>> register(String email, String password, String name) async {
|
||||
return Result.success(
|
||||
User(
|
||||
id: '1',
|
||||
email: email,
|
||||
name: name,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Result<void>> refreshToken() async {
|
||||
return const Result.success(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'user.freezed.dart';
|
||||
// part 'user.g.dart';
|
||||
|
||||
@freezed
|
||||
class User with _$User {
|
||||
const factory User({
|
||||
required String id,
|
||||
required String email,
|
||||
required String name,
|
||||
String? avatarUrl,
|
||||
String? phoneNumber,
|
||||
DateTime? lastSeen,
|
||||
bool? isOnline,
|
||||
}) = _User;
|
||||
|
||||
// factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
// 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 'user.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 _$User {
|
||||
String get id => throw _privateConstructorUsedError;
|
||||
String get email => throw _privateConstructorUsedError;
|
||||
String get name => throw _privateConstructorUsedError;
|
||||
String? get avatarUrl => throw _privateConstructorUsedError;
|
||||
String? get phoneNumber => throw _privateConstructorUsedError;
|
||||
DateTime? get lastSeen => throw _privateConstructorUsedError;
|
||||
bool? get isOnline => throw _privateConstructorUsedError;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
$UserCopyWith<User> get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $UserCopyWith<$Res> {
|
||||
factory $UserCopyWith(User value, $Res Function(User) then) =
|
||||
_$UserCopyWithImpl<$Res, User>;
|
||||
@useResult
|
||||
$Res call(
|
||||
{String id,
|
||||
String email,
|
||||
String name,
|
||||
String? avatarUrl,
|
||||
String? phoneNumber,
|
||||
DateTime? lastSeen,
|
||||
bool? isOnline});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$UserCopyWithImpl<$Res, $Val extends User>
|
||||
implements $UserCopyWith<$Res> {
|
||||
_$UserCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? email = null,
|
||||
Object? name = null,
|
||||
Object? avatarUrl = freezed,
|
||||
Object? phoneNumber = freezed,
|
||||
Object? lastSeen = freezed,
|
||||
Object? isOnline = freezed,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
id: null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
email: null == email
|
||||
? _value.email
|
||||
: email // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
name: null == name
|
||||
? _value.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
avatarUrl: freezed == avatarUrl
|
||||
? _value.avatarUrl
|
||||
: avatarUrl // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
phoneNumber: freezed == phoneNumber
|
||||
? _value.phoneNumber
|
||||
: phoneNumber // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
lastSeen: freezed == lastSeen
|
||||
? _value.lastSeen
|
||||
: lastSeen // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
isOnline: freezed == isOnline
|
||||
? _value.isOnline
|
||||
: isOnline // ignore: cast_nullable_to_non_nullable
|
||||
as bool?,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$UserImplCopyWith<$Res> implements $UserCopyWith<$Res> {
|
||||
factory _$$UserImplCopyWith(
|
||||
_$UserImpl value, $Res Function(_$UserImpl) then) =
|
||||
__$$UserImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call(
|
||||
{String id,
|
||||
String email,
|
||||
String name,
|
||||
String? avatarUrl,
|
||||
String? phoneNumber,
|
||||
DateTime? lastSeen,
|
||||
bool? isOnline});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$UserImplCopyWithImpl<$Res>
|
||||
extends _$UserCopyWithImpl<$Res, _$UserImpl>
|
||||
implements _$$UserImplCopyWith<$Res> {
|
||||
__$$UserImplCopyWithImpl(_$UserImpl _value, $Res Function(_$UserImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? email = null,
|
||||
Object? name = null,
|
||||
Object? avatarUrl = freezed,
|
||||
Object? phoneNumber = freezed,
|
||||
Object? lastSeen = freezed,
|
||||
Object? isOnline = freezed,
|
||||
}) {
|
||||
return _then(_$UserImpl(
|
||||
id: null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
email: null == email
|
||||
? _value.email
|
||||
: email // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
name: null == name
|
||||
? _value.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
avatarUrl: freezed == avatarUrl
|
||||
? _value.avatarUrl
|
||||
: avatarUrl // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
phoneNumber: freezed == phoneNumber
|
||||
? _value.phoneNumber
|
||||
: phoneNumber // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
lastSeen: freezed == lastSeen
|
||||
? _value.lastSeen
|
||||
: lastSeen // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
isOnline: freezed == isOnline
|
||||
? _value.isOnline
|
||||
: isOnline // ignore: cast_nullable_to_non_nullable
|
||||
as bool?,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$UserImpl implements _User {
|
||||
const _$UserImpl(
|
||||
{required this.id,
|
||||
required this.email,
|
||||
required this.name,
|
||||
this.avatarUrl,
|
||||
this.phoneNumber,
|
||||
this.lastSeen,
|
||||
this.isOnline});
|
||||
|
||||
@override
|
||||
final String id;
|
||||
@override
|
||||
final String email;
|
||||
@override
|
||||
final String name;
|
||||
@override
|
||||
final String? avatarUrl;
|
||||
@override
|
||||
final String? phoneNumber;
|
||||
@override
|
||||
final DateTime? lastSeen;
|
||||
@override
|
||||
final bool? isOnline;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'User(id: $id, email: $email, name: $name, avatarUrl: $avatarUrl, phoneNumber: $phoneNumber, lastSeen: $lastSeen, isOnline: $isOnline)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$UserImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.email, email) || other.email == email) &&
|
||||
(identical(other.name, name) || other.name == name) &&
|
||||
(identical(other.avatarUrl, avatarUrl) ||
|
||||
other.avatarUrl == avatarUrl) &&
|
||||
(identical(other.phoneNumber, phoneNumber) ||
|
||||
other.phoneNumber == phoneNumber) &&
|
||||
(identical(other.lastSeen, lastSeen) ||
|
||||
other.lastSeen == lastSeen) &&
|
||||
(identical(other.isOnline, isOnline) ||
|
||||
other.isOnline == isOnline));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType, id, email, name, avatarUrl, phoneNumber, lastSeen, isOnline);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$UserImplCopyWith<_$UserImpl> get copyWith =>
|
||||
__$$UserImplCopyWithImpl<_$UserImpl>(this, _$identity);
|
||||
}
|
||||
|
||||
abstract class _User implements User {
|
||||
const factory _User(
|
||||
{required final String id,
|
||||
required final String email,
|
||||
required final String name,
|
||||
final String? avatarUrl,
|
||||
final String? phoneNumber,
|
||||
final DateTime? lastSeen,
|
||||
final bool? isOnline}) = _$UserImpl;
|
||||
|
||||
@override
|
||||
String get id;
|
||||
@override
|
||||
String get email;
|
||||
@override
|
||||
String get name;
|
||||
@override
|
||||
String? get avatarUrl;
|
||||
@override
|
||||
String? get phoneNumber;
|
||||
@override
|
||||
DateTime? get lastSeen;
|
||||
@override
|
||||
bool? get isOnline;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$UserImplCopyWith<_$UserImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import '../../../../core/errors/result.dart';
|
||||
import '../entities/user.dart';
|
||||
|
||||
abstract class AuthRepository {
|
||||
Future<Result<User>> login(String email, String password);
|
||||
Future<Result<User>> register(String email, String password, String name);
|
||||
Future<Result<void>> logout();
|
||||
Future<Result<User>> getCurrentUser();
|
||||
Future<Result<void>> refreshToken();
|
||||
bool get isLoggedIn;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import '../../../../core/errors/result.dart';
|
||||
import '../repositories/auth_repository.dart';
|
||||
import '../entities/user.dart';
|
||||
|
||||
class LoginUseCase {
|
||||
final AuthRepository _repository;
|
||||
|
||||
LoginUseCase(this._repository);
|
||||
|
||||
Future<Result<User>> execute(String email, String password) {
|
||||
return _repository.login(email, password);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'auth_event.dart';
|
||||
import 'auth_state.dart';
|
||||
|
||||
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
AuthBloc() : super(const AuthState.initial()) {
|
||||
on<AuthEventStarted>(_onStarted);
|
||||
on<AuthEventLoginRequested>(_onLoginRequested);
|
||||
on<AuthEventRegisterRequested>(_onRegisterRequested);
|
||||
on<AuthEventLogoutRequested>(_onLogoutRequested);
|
||||
on<AuthEventAuthChecked>(_onAuthChecked);
|
||||
on<AuthEventEmailChanged>(_onEmailChanged);
|
||||
on<AuthEventPasswordChanged>(_onPasswordChanged);
|
||||
on<AuthEventNameChanged>(_onNameChanged);
|
||||
}
|
||||
|
||||
Future<void> _onStarted(AuthEventStarted event, emit) async {}
|
||||
|
||||
Future<void> _onLoginRequested(AuthEventLoginRequested event, emit) async {
|
||||
emit(const AuthState.loading());
|
||||
emit(const AuthState.authenticated('user_123'));
|
||||
}
|
||||
|
||||
Future<void> _onRegisterRequested(AuthEventRegisterRequested event, emit) async {
|
||||
emit(const AuthState.loading());
|
||||
}
|
||||
|
||||
Future<void> _onLogoutRequested(AuthEventLogoutRequested event, emit) async {
|
||||
emit(const AuthState.unauthenticated());
|
||||
}
|
||||
|
||||
Future<void> _onAuthChecked(AuthEventAuthChecked event, emit) async {}
|
||||
void _onEmailChanged(AuthEventEmailChanged event, emit) {}
|
||||
void _onPasswordChanged(AuthEventPasswordChanged event, emit) {}
|
||||
void _onNameChanged(AuthEventNameChanged event, emit) {}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'auth_event.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class AuthEvent with _$AuthEvent {
|
||||
const factory AuthEvent.started() = AuthEventStarted;
|
||||
const factory AuthEvent.loginRequested(String email, String password) = AuthEventLoginRequested;
|
||||
const factory AuthEvent.registerRequested(String email, String password, String name) = AuthEventRegisterRequested;
|
||||
const factory AuthEvent.logoutRequested() = AuthEventLogoutRequested;
|
||||
const factory AuthEvent.authChecked() = AuthEventAuthChecked;
|
||||
const factory AuthEvent.emailChanged(String email) = AuthEventEmailChanged;
|
||||
const factory AuthEvent.passwordChanged(String password) = AuthEventPasswordChanged;
|
||||
const factory AuthEvent.nameChanged(String name) = AuthEventNameChanged;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'auth_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class AuthState with _$AuthState {
|
||||
const factory AuthState.initial() = AuthInitial;
|
||||
const factory AuthState.loading() = AuthLoading;
|
||||
const factory AuthState.authenticated(String userId) = AuthAuthenticated;
|
||||
const factory AuthState.unauthenticated() = AuthUnauthenticated;
|
||||
const factory AuthState.error(String message) = AuthError;
|
||||
}
|
||||
@@ -0,0 +1,757 @@
|
||||
// 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_state.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 _$AuthState {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String userId) authenticated,
|
||||
required TResult Function() unauthenticated,
|
||||
required TResult Function(String message) error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String userId)? authenticated,
|
||||
TResult? Function()? unauthenticated,
|
||||
TResult? Function(String message)? error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(String userId)? authenticated,
|
||||
TResult Function()? unauthenticated,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(AuthInitial value) initial,
|
||||
required TResult Function(AuthLoading value) loading,
|
||||
required TResult Function(AuthAuthenticated value) authenticated,
|
||||
required TResult Function(AuthUnauthenticated value) unauthenticated,
|
||||
required TResult Function(AuthError value) error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(AuthInitial value)? initial,
|
||||
TResult? Function(AuthLoading value)? loading,
|
||||
TResult? Function(AuthAuthenticated value)? authenticated,
|
||||
TResult? Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult? Function(AuthError value)? error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(AuthInitial value)? initial,
|
||||
TResult Function(AuthLoading value)? loading,
|
||||
TResult Function(AuthAuthenticated value)? authenticated,
|
||||
TResult Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult Function(AuthError value)? error,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $AuthStateCopyWith<$Res> {
|
||||
factory $AuthStateCopyWith(AuthState value, $Res Function(AuthState) then) =
|
||||
_$AuthStateCopyWithImpl<$Res, AuthState>;
|
||||
}
|
||||
|
||||
/// @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;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$AuthInitialImplCopyWith<$Res> {
|
||||
factory _$$AuthInitialImplCopyWith(
|
||||
_$AuthInitialImpl value, $Res Function(_$AuthInitialImpl) then) =
|
||||
__$$AuthInitialImplCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$AuthInitialImplCopyWithImpl<$Res>
|
||||
extends _$AuthStateCopyWithImpl<$Res, _$AuthInitialImpl>
|
||||
implements _$$AuthInitialImplCopyWith<$Res> {
|
||||
__$$AuthInitialImplCopyWithImpl(
|
||||
_$AuthInitialImpl _value, $Res Function(_$AuthInitialImpl) _then)
|
||||
: super(_value, _then);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$AuthInitialImpl implements AuthInitial {
|
||||
const _$AuthInitialImpl();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthState.initial()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType && other is _$AuthInitialImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String userId) authenticated,
|
||||
required TResult Function() unauthenticated,
|
||||
required TResult Function(String message) error,
|
||||
}) {
|
||||
return initial();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String userId)? authenticated,
|
||||
TResult? Function()? unauthenticated,
|
||||
TResult? Function(String message)? error,
|
||||
}) {
|
||||
return initial?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(String userId)? authenticated,
|
||||
TResult Function()? unauthenticated,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (initial != null) {
|
||||
return initial();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(AuthInitial value) initial,
|
||||
required TResult Function(AuthLoading value) loading,
|
||||
required TResult Function(AuthAuthenticated value) authenticated,
|
||||
required TResult Function(AuthUnauthenticated value) unauthenticated,
|
||||
required TResult Function(AuthError value) error,
|
||||
}) {
|
||||
return initial(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(AuthInitial value)? initial,
|
||||
TResult? Function(AuthLoading value)? loading,
|
||||
TResult? Function(AuthAuthenticated value)? authenticated,
|
||||
TResult? Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult? Function(AuthError value)? error,
|
||||
}) {
|
||||
return initial?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(AuthInitial value)? initial,
|
||||
TResult Function(AuthLoading value)? loading,
|
||||
TResult Function(AuthAuthenticated value)? authenticated,
|
||||
TResult Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult Function(AuthError value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (initial != null) {
|
||||
return initial(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AuthInitial implements AuthState {
|
||||
const factory AuthInitial() = _$AuthInitialImpl;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$AuthLoadingImplCopyWith<$Res> {
|
||||
factory _$$AuthLoadingImplCopyWith(
|
||||
_$AuthLoadingImpl value, $Res Function(_$AuthLoadingImpl) then) =
|
||||
__$$AuthLoadingImplCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$AuthLoadingImplCopyWithImpl<$Res>
|
||||
extends _$AuthStateCopyWithImpl<$Res, _$AuthLoadingImpl>
|
||||
implements _$$AuthLoadingImplCopyWith<$Res> {
|
||||
__$$AuthLoadingImplCopyWithImpl(
|
||||
_$AuthLoadingImpl _value, $Res Function(_$AuthLoadingImpl) _then)
|
||||
: super(_value, _then);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$AuthLoadingImpl implements AuthLoading {
|
||||
const _$AuthLoadingImpl();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthState.loading()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType && other is _$AuthLoadingImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String userId) authenticated,
|
||||
required TResult Function() unauthenticated,
|
||||
required TResult Function(String message) error,
|
||||
}) {
|
||||
return loading();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String userId)? authenticated,
|
||||
TResult? Function()? unauthenticated,
|
||||
TResult? Function(String message)? error,
|
||||
}) {
|
||||
return loading?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(String userId)? authenticated,
|
||||
TResult Function()? unauthenticated,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loading != null) {
|
||||
return loading();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(AuthInitial value) initial,
|
||||
required TResult Function(AuthLoading value) loading,
|
||||
required TResult Function(AuthAuthenticated value) authenticated,
|
||||
required TResult Function(AuthUnauthenticated value) unauthenticated,
|
||||
required TResult Function(AuthError value) error,
|
||||
}) {
|
||||
return loading(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(AuthInitial value)? initial,
|
||||
TResult? Function(AuthLoading value)? loading,
|
||||
TResult? Function(AuthAuthenticated value)? authenticated,
|
||||
TResult? Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult? Function(AuthError value)? error,
|
||||
}) {
|
||||
return loading?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(AuthInitial value)? initial,
|
||||
TResult Function(AuthLoading value)? loading,
|
||||
TResult Function(AuthAuthenticated value)? authenticated,
|
||||
TResult Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult Function(AuthError value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loading != null) {
|
||||
return loading(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AuthLoading implements AuthState {
|
||||
const factory AuthLoading() = _$AuthLoadingImpl;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$AuthAuthenticatedImplCopyWith<$Res> {
|
||||
factory _$$AuthAuthenticatedImplCopyWith(_$AuthAuthenticatedImpl value,
|
||||
$Res Function(_$AuthAuthenticatedImpl) then) =
|
||||
__$$AuthAuthenticatedImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({String userId});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$AuthAuthenticatedImplCopyWithImpl<$Res>
|
||||
extends _$AuthStateCopyWithImpl<$Res, _$AuthAuthenticatedImpl>
|
||||
implements _$$AuthAuthenticatedImplCopyWith<$Res> {
|
||||
__$$AuthAuthenticatedImplCopyWithImpl(_$AuthAuthenticatedImpl _value,
|
||||
$Res Function(_$AuthAuthenticatedImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? userId = null,
|
||||
}) {
|
||||
return _then(_$AuthAuthenticatedImpl(
|
||||
null == userId
|
||||
? _value.userId
|
||||
: userId // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$AuthAuthenticatedImpl implements AuthAuthenticated {
|
||||
const _$AuthAuthenticatedImpl(this.userId);
|
||||
|
||||
@override
|
||||
final String userId;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthState.authenticated(userId: $userId)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$AuthAuthenticatedImpl &&
|
||||
(identical(other.userId, userId) || other.userId == userId));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, userId);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$AuthAuthenticatedImplCopyWith<_$AuthAuthenticatedImpl> get copyWith =>
|
||||
__$$AuthAuthenticatedImplCopyWithImpl<_$AuthAuthenticatedImpl>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String userId) authenticated,
|
||||
required TResult Function() unauthenticated,
|
||||
required TResult Function(String message) error,
|
||||
}) {
|
||||
return authenticated(userId);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String userId)? authenticated,
|
||||
TResult? Function()? unauthenticated,
|
||||
TResult? Function(String message)? error,
|
||||
}) {
|
||||
return authenticated?.call(userId);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(String userId)? authenticated,
|
||||
TResult Function()? unauthenticated,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (authenticated != null) {
|
||||
return authenticated(userId);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(AuthInitial value) initial,
|
||||
required TResult Function(AuthLoading value) loading,
|
||||
required TResult Function(AuthAuthenticated value) authenticated,
|
||||
required TResult Function(AuthUnauthenticated value) unauthenticated,
|
||||
required TResult Function(AuthError value) error,
|
||||
}) {
|
||||
return authenticated(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(AuthInitial value)? initial,
|
||||
TResult? Function(AuthLoading value)? loading,
|
||||
TResult? Function(AuthAuthenticated value)? authenticated,
|
||||
TResult? Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult? Function(AuthError value)? error,
|
||||
}) {
|
||||
return authenticated?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(AuthInitial value)? initial,
|
||||
TResult Function(AuthLoading value)? loading,
|
||||
TResult Function(AuthAuthenticated value)? authenticated,
|
||||
TResult Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult Function(AuthError value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (authenticated != null) {
|
||||
return authenticated(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AuthAuthenticated implements AuthState {
|
||||
const factory AuthAuthenticated(final String userId) =
|
||||
_$AuthAuthenticatedImpl;
|
||||
|
||||
String get userId;
|
||||
@JsonKey(ignore: true)
|
||||
_$$AuthAuthenticatedImplCopyWith<_$AuthAuthenticatedImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$AuthUnauthenticatedImplCopyWith<$Res> {
|
||||
factory _$$AuthUnauthenticatedImplCopyWith(_$AuthUnauthenticatedImpl value,
|
||||
$Res Function(_$AuthUnauthenticatedImpl) then) =
|
||||
__$$AuthUnauthenticatedImplCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$AuthUnauthenticatedImplCopyWithImpl<$Res>
|
||||
extends _$AuthStateCopyWithImpl<$Res, _$AuthUnauthenticatedImpl>
|
||||
implements _$$AuthUnauthenticatedImplCopyWith<$Res> {
|
||||
__$$AuthUnauthenticatedImplCopyWithImpl(_$AuthUnauthenticatedImpl _value,
|
||||
$Res Function(_$AuthUnauthenticatedImpl) _then)
|
||||
: super(_value, _then);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$AuthUnauthenticatedImpl implements AuthUnauthenticated {
|
||||
const _$AuthUnauthenticatedImpl();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthState.unauthenticated()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$AuthUnauthenticatedImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String userId) authenticated,
|
||||
required TResult Function() unauthenticated,
|
||||
required TResult Function(String message) error,
|
||||
}) {
|
||||
return unauthenticated();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String userId)? authenticated,
|
||||
TResult? Function()? unauthenticated,
|
||||
TResult? Function(String message)? error,
|
||||
}) {
|
||||
return unauthenticated?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(String userId)? authenticated,
|
||||
TResult Function()? unauthenticated,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (unauthenticated != null) {
|
||||
return unauthenticated();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(AuthInitial value) initial,
|
||||
required TResult Function(AuthLoading value) loading,
|
||||
required TResult Function(AuthAuthenticated value) authenticated,
|
||||
required TResult Function(AuthUnauthenticated value) unauthenticated,
|
||||
required TResult Function(AuthError value) error,
|
||||
}) {
|
||||
return unauthenticated(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(AuthInitial value)? initial,
|
||||
TResult? Function(AuthLoading value)? loading,
|
||||
TResult? Function(AuthAuthenticated value)? authenticated,
|
||||
TResult? Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult? Function(AuthError value)? error,
|
||||
}) {
|
||||
return unauthenticated?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(AuthInitial value)? initial,
|
||||
TResult Function(AuthLoading value)? loading,
|
||||
TResult Function(AuthAuthenticated value)? authenticated,
|
||||
TResult Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult Function(AuthError value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (unauthenticated != null) {
|
||||
return unauthenticated(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AuthUnauthenticated implements AuthState {
|
||||
const factory AuthUnauthenticated() = _$AuthUnauthenticatedImpl;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$AuthErrorImplCopyWith<$Res> {
|
||||
factory _$$AuthErrorImplCopyWith(
|
||||
_$AuthErrorImpl value, $Res Function(_$AuthErrorImpl) then) =
|
||||
__$$AuthErrorImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({String message});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$AuthErrorImplCopyWithImpl<$Res>
|
||||
extends _$AuthStateCopyWithImpl<$Res, _$AuthErrorImpl>
|
||||
implements _$$AuthErrorImplCopyWith<$Res> {
|
||||
__$$AuthErrorImplCopyWithImpl(
|
||||
_$AuthErrorImpl _value, $Res Function(_$AuthErrorImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? message = null,
|
||||
}) {
|
||||
return _then(_$AuthErrorImpl(
|
||||
null == message
|
||||
? _value.message
|
||||
: message // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$AuthErrorImpl implements AuthError {
|
||||
const _$AuthErrorImpl(this.message);
|
||||
|
||||
@override
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthState.error(message: $message)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$AuthErrorImpl &&
|
||||
(identical(other.message, message) || other.message == message));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, message);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$AuthErrorImplCopyWith<_$AuthErrorImpl> get copyWith =>
|
||||
__$$AuthErrorImplCopyWithImpl<_$AuthErrorImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(String userId) authenticated,
|
||||
required TResult Function() unauthenticated,
|
||||
required TResult Function(String message) error,
|
||||
}) {
|
||||
return error(message);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(String userId)? authenticated,
|
||||
TResult? Function()? unauthenticated,
|
||||
TResult? Function(String message)? error,
|
||||
}) {
|
||||
return error?.call(message);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(String userId)? authenticated,
|
||||
TResult Function()? unauthenticated,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (error != null) {
|
||||
return error(message);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(AuthInitial value) initial,
|
||||
required TResult Function(AuthLoading value) loading,
|
||||
required TResult Function(AuthAuthenticated value) authenticated,
|
||||
required TResult Function(AuthUnauthenticated value) unauthenticated,
|
||||
required TResult Function(AuthError value) error,
|
||||
}) {
|
||||
return error(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(AuthInitial value)? initial,
|
||||
TResult? Function(AuthLoading value)? loading,
|
||||
TResult? Function(AuthAuthenticated value)? authenticated,
|
||||
TResult? Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult? Function(AuthError value)? error,
|
||||
}) {
|
||||
return error?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(AuthInitial value)? initial,
|
||||
TResult Function(AuthLoading value)? loading,
|
||||
TResult Function(AuthAuthenticated value)? authenticated,
|
||||
TResult Function(AuthUnauthenticated value)? unauthenticated,
|
||||
TResult Function(AuthError value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (error != null) {
|
||||
return error(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AuthError implements AuthState {
|
||||
const factory AuthError(final String message) = _$AuthErrorImpl;
|
||||
|
||||
String get message;
|
||||
@JsonKey(ignore: true)
|
||||
_$$AuthErrorImplCopyWith<_$AuthErrorImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../bloc/auth_bloc.dart';
|
||||
import '../bloc/auth_event.dart';
|
||||
import '../bloc/auth_state.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
State<LoginPage> createState() => _LoginPageState();
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _emailController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailController.dispose();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Вход'),
|
||||
),
|
||||
body: BlocListener<AuthBloc, AuthState>(
|
||||
listener: (context, state) {
|
||||
state.whenOrNull(
|
||||
authenticated: (userId) {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
},
|
||||
error: (message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(message)),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.chat_bubble_outline,
|
||||
size: 80,
|
||||
color: Color(0xFF2481CC),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Email',
|
||||
prefixIcon: Icon(Icons.email_outlined),
|
||||
),
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Введите email';
|
||||
}
|
||||
if (!value.contains('@')) {
|
||||
return 'Введите корректный email';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Пароль',
|
||||
prefixIcon: Icon(Icons.lock_outlined),
|
||||
),
|
||||
obscureText: true,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Введите пароль';
|
||||
}
|
||||
if (value.length < 6) {
|
||||
return 'Пароль должен быть не менее 6 символов';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
if (state is AuthLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
return ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState?.validate() ?? false) {
|
||||
context.read<AuthBloc>().add(
|
||||
AuthEvent.loginRequested(
|
||||
_emailController.text,
|
||||
_passwordController.text,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 12),
|
||||
child: Text('Войти', style: TextStyle(fontSize: 16)),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// Navigate to register page
|
||||
},
|
||||
child: const Text('Нет аккаунта? Зарегистрироваться'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user