geo-smart-app/lib/bloc/authentication/authentication_bloc.dart

35 lines
1005 B
Dart
Raw Normal View History

2024-09-22 06:41:32 +00:00
// import 'package:alice/alice.dart';
2020-07-28 18:11:47 +00:00
import 'package:dio/dio.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:geosmart/bloc/authentication/authentication_event.dart';
import 'package:geosmart/bloc/authentication/authentication_state.dart';
import 'package:geosmart/service/setting_service.dart';
class AuthenticationBloc
extends Bloc<AuthenticationEvent, AuthenticationState> {
2024-09-22 06:41:32 +00:00
// final Alice alice;
2020-07-28 18:11:47 +00:00
final Dio dio;
AuthenticationBloc({
2024-09-22 06:41:32 +00:00
// @required this.alice,
2024-12-25 05:37:16 +00:00
required this.dio,
}) : super(AuthenticationInitial()) {
on<AuthenticationStarted>((event, emit) async {
emit(AuthenticationProgress());
2020-07-28 18:11:47 +00:00
final s = await SettingService().getSetting();
if (s.isValid()) {
2024-12-25 05:37:16 +00:00
emit(AuthenticationSuccess());
2020-07-28 18:11:47 +00:00
} else {
2024-12-25 05:37:16 +00:00
emit(AuthenticationFailed());
2020-07-28 18:11:47 +00:00
}
2024-12-25 05:37:16 +00:00
});
2020-07-28 18:11:47 +00:00
2024-12-25 05:37:16 +00:00
on<AuthenticationClear>(
(event, emit) async {
await SettingService().clearSetting();
emit(AuthenticationFailed());
},
);
2020-07-28 18:11:47 +00:00
}
}