(showBlockDialog not dismissing) - Completer not completes when using it in Helper
anburocky3 opened this issue · comments
Anbuselvan Annamalai commented
I have this class, and initiated the showBlockDialog
functionality in model.
PageLoader.dart
import 'dart:async';
import 'package:flash/flash.dart';
import 'package:flutter/material.dart';
class PageLoader {
final _completer = Completer();
final BuildContext context;
PageLoader(this.context);
void init() {
context.showBlockDialog(dismissCompleter: _completer);
}
void complete() {
_completer.complete();
print("is completed");
}
}
And using it like MyUI.dart
try {
PageLoader(context).init(); // init
await provider.login(
emailController.text, passwordController.text, deviceName);
PageLoader(context).complete(); // triggering to completer to complete the job to dismiss the dialog
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => VerificationPage(email: emailController.text)));
} catch (exception) {
setState(() {
errorMessage = exception.toString().replaceAll('Exception: ', '');
});
PageLoader(context).complete(); // triggering to completer to complete the job to dismiss the dialog
While respective actions, the showBlockDialog
is displaying, but the complete is not completing.
sososdk commented
@anburocky3 Try using the same instance:
final loader = PageLoader(context);
try {
loader.init(); // init
await provider.login(
emailController.text, passwordController.text, deviceName);
loader.complete(); // triggering to completer to complete the job to dismiss the dialog
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => VerificationPage(email: emailController.text)));
} catch (exception) {
setState(() {
errorMessage = exception.toString().replaceAll('Exception: ', '');
});
loader.complete(); // triggering to completer to complete the job to dismiss the dialog
Anbuselvan Annamalai commented
I was stupid, sorry. Completer
was working, just i thought, i was creating multiple instances, and you confirmed it.
Thanks. Closing this.