mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-13 04:56:21 +01:00
Fix cancel button not working while waiting for server response
This commit is contained in:
parent
d51724a16b
commit
bb7919ff15
1 changed files with 22 additions and 16 deletions
|
@ -15,9 +15,15 @@ abstract class AppPasswordExchangeBlocEvent {
|
||||||
const AppPasswordExchangeBlocEvent();
|
const AppPasswordExchangeBlocEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Group of events that are handled sequentially
|
||||||
|
abstract class AppPasswordExchangeBlocEventGroup1
|
||||||
|
extends AppPasswordExchangeBlocEvent {
|
||||||
|
const AppPasswordExchangeBlocEventGroup1();
|
||||||
|
}
|
||||||
|
|
||||||
@toString
|
@toString
|
||||||
class AppPasswordExchangeBlocInitiateLogin
|
class AppPasswordExchangeBlocInitiateLogin
|
||||||
extends AppPasswordExchangeBlocEvent {
|
extends AppPasswordExchangeBlocEventGroup1 {
|
||||||
const AppPasswordExchangeBlocInitiateLogin(this.uri);
|
const AppPasswordExchangeBlocInitiateLogin(this.uri);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -27,7 +33,7 @@ class AppPasswordExchangeBlocInitiateLogin
|
||||||
}
|
}
|
||||||
|
|
||||||
@toString
|
@toString
|
||||||
class AppPasswordExchangeBlocPoll extends AppPasswordExchangeBlocEvent {
|
class AppPasswordExchangeBlocPoll extends AppPasswordExchangeBlocEventGroup1 {
|
||||||
const AppPasswordExchangeBlocPoll(this.pollOptions);
|
const AppPasswordExchangeBlocPoll(this.pollOptions);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -46,7 +52,7 @@ class AppPasswordExchangeBlocCancel extends AppPasswordExchangeBlocEvent {
|
||||||
|
|
||||||
@toString
|
@toString
|
||||||
class _AppPasswordExchangeBlocAppPwReceived
|
class _AppPasswordExchangeBlocAppPwReceived
|
||||||
extends AppPasswordExchangeBlocEvent {
|
extends AppPasswordExchangeBlocEventGroup1 {
|
||||||
const _AppPasswordExchangeBlocAppPwReceived(this.appPasswordResponse);
|
const _AppPasswordExchangeBlocAppPwReceived(this.appPasswordResponse);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -56,7 +62,8 @@ class _AppPasswordExchangeBlocAppPwReceived
|
||||||
}
|
}
|
||||||
|
|
||||||
@toString
|
@toString
|
||||||
class _AppPasswordExchangeBlocAppPwFailed extends AppPasswordExchangeBlocEvent {
|
class _AppPasswordExchangeBlocAppPwFailed
|
||||||
|
extends AppPasswordExchangeBlocEventGroup1 {
|
||||||
const _AppPasswordExchangeBlocAppPwFailed(this.exception);
|
const _AppPasswordExchangeBlocAppPwFailed(this.exception);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -131,14 +138,21 @@ class AppPasswordExchangeBlocResult extends AppPasswordExchangeBlocState {
|
||||||
class AppPasswordExchangeBloc
|
class AppPasswordExchangeBloc
|
||||||
extends Bloc<AppPasswordExchangeBlocEvent, AppPasswordExchangeBlocState> {
|
extends Bloc<AppPasswordExchangeBlocEvent, AppPasswordExchangeBlocState> {
|
||||||
AppPasswordExchangeBloc() : super(const AppPasswordExchangeBlocInit()) {
|
AppPasswordExchangeBloc() : super(const AppPasswordExchangeBlocInit()) {
|
||||||
on<AppPasswordExchangeBlocEvent>(_onEvent);
|
on<AppPasswordExchangeBlocEventGroup1>(_onEventGroup1);
|
||||||
|
on<AppPasswordExchangeBlocCancel>(_onEventCancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onEvent(AppPasswordExchangeBlocEvent event,
|
@override
|
||||||
|
Future<void> close() {
|
||||||
|
_pollPasswordSubscription?.cancel();
|
||||||
|
return super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onEventGroup1(AppPasswordExchangeBlocEvent event,
|
||||||
Emitter<AppPasswordExchangeBlocState> emit) async {
|
Emitter<AppPasswordExchangeBlocState> emit) async {
|
||||||
_log.info("[_onEvent] $event");
|
_log.info("[_onEventGroup1] $event");
|
||||||
if (_isCanceled) {
|
if (_isCanceled) {
|
||||||
_log.fine("[_onEvent] canceled = true, ignore event");
|
_log.fine("[_onEventGroup1] canceled = true, ignore event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event is AppPasswordExchangeBlocInitiateLogin) {
|
if (event is AppPasswordExchangeBlocInitiateLogin) {
|
||||||
|
@ -149,8 +163,6 @@ class AppPasswordExchangeBloc
|
||||||
await _onEventAppPasswordReceived(event, emit);
|
await _onEventAppPasswordReceived(event, emit);
|
||||||
} else if (event is _AppPasswordExchangeBlocAppPwFailed) {
|
} else if (event is _AppPasswordExchangeBlocAppPwFailed) {
|
||||||
await _onEventAppPasswordFailure(event, emit);
|
await _onEventAppPasswordFailure(event, emit);
|
||||||
} else if (event is AppPasswordExchangeBlocCancel) {
|
|
||||||
await _onEventCancel(event, emit);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,12 +256,6 @@ class AppPasswordExchangeBloc
|
||||||
emit(const AppPasswordExchangeBlocResult(null));
|
emit(const AppPasswordExchangeBlocResult(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> close() {
|
|
||||||
_pollPasswordSubscription?.cancel();
|
|
||||||
return super.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
static final _log =
|
static final _log =
|
||||||
Logger("bloc.app_password_exchange.AppPasswordExchangeBloc");
|
Logger("bloc.app_password_exchange.AppPasswordExchangeBloc");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue