mirror of
https://github.com/supanadit/geo-smart-app.git
synced 2024-11-10 10:02:20 +00:00
39 lines
1.1 KiB
Dart
39 lines
1.1 KiB
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';
|
|
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();
|
|
}
|
|
}
|
|
}
|