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

39 lines
1.1 KiB
Dart
Raw Normal View History

2020-07-28 18:11:47 +00:00
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';
import 'package:meta/meta.dart';
class AuthenticationBloc
extends Bloc<AuthenticationEvent, AuthenticationState> {
final Alice alice;
final Dio dio;
AuthenticationBloc({
@required this.alice,
@required this.dio,
}) : super(AuthenticationInitial());
@override
Stream<AuthenticationState> mapEventToState(
AuthenticationEvent event,
) async* {
if (event is AuthenticationStarted) {
yield AuthenticationProgress();
final s = await SettingService().getSetting();
if (s.isValid()) {
yield AuthenticationSuccess();
} else {
yield AuthenticationFailed();
}
}
if (event is AuthenticationClear) {
await SettingService().clearSetting();
yield AuthenticationFailed();
}
}
}