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

35 lines
1005 B
Dart

// import 'package:alice/alice.dart';
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> {
// final Alice alice;
final Dio dio;
AuthenticationBloc({
// @required this.alice,
required this.dio,
}) : super(AuthenticationInitial()) {
on<AuthenticationStarted>((event, emit) async {
emit(AuthenticationProgress());
final s = await SettingService().getSetting();
if (s.isValid()) {
emit(AuthenticationSuccess());
} else {
emit(AuthenticationFailed());
}
});
on<AuthenticationClear>(
(event, emit) async {
await SettingService().clearSetting();
emit(AuthenticationFailed());
},
);
}
}