Initial draft
This commit is contained in:
28
lib/feature/authentication/bloc/auth_bloc.dart
Normal file
28
lib/feature/authentication/bloc/auth_bloc.dart
Normal file
@ -0,0 +1,28 @@
|
||||
import 'package:hl_lieferservice/feature/authentication/bloc/auth_event.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/bloc/auth_state.dart';
|
||||
import 'package:hl_lieferservice/repository/user_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_event.dart';
|
||||
|
||||
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
UserRepository repository;
|
||||
OperationBloc operationBloc;
|
||||
|
||||
AuthBloc({required this.repository, required this.operationBloc})
|
||||
: super(Unauthenticated()) {
|
||||
on<Authenticate>(_auth);
|
||||
on<Logout>(_logout);
|
||||
}
|
||||
|
||||
Future<void> _auth(Authenticate event, Emitter<AuthState> emit) async {
|
||||
operationBloc.add(LoadOperation());
|
||||
await Future.delayed(Duration(seconds: 5));
|
||||
emit(Authenticated(teamId: event.username));
|
||||
operationBloc.add(FinishOperation());
|
||||
}
|
||||
|
||||
Future<void> _logout(Logout event, Emitter<AuthState> emit) async {
|
||||
emit(Unauthenticated());
|
||||
}
|
||||
}
|
||||
14
lib/feature/authentication/bloc/auth_event.dart
Normal file
14
lib/feature/authentication/bloc/auth_event.dart
Normal file
@ -0,0 +1,14 @@
|
||||
abstract class AuthEvent {}
|
||||
|
||||
class Authenticate extends AuthEvent {
|
||||
String username;
|
||||
String password;
|
||||
|
||||
Authenticate({required this.username, required this.password});
|
||||
}
|
||||
|
||||
class Logout extends AuthEvent {
|
||||
String username;
|
||||
|
||||
Logout({required this.username});
|
||||
}
|
||||
9
lib/feature/authentication/bloc/auth_state.dart
Normal file
9
lib/feature/authentication/bloc/auth_state.dart
Normal file
@ -0,0 +1,9 @@
|
||||
abstract class AuthState {}
|
||||
|
||||
class Unauthenticated extends AuthState {}
|
||||
class Authenticated extends AuthState {
|
||||
String teamId;
|
||||
|
||||
Authenticated({required this.teamId});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user