sososdk / flash

⚡️A highly customizable, powerful and easy-to-use alerting library for Flutter.

Home Page:https://sososdk.github.io/flash

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(showBlockDialog not dismissing) - Completer not completes when using it in Helper

anburocky3 opened this issue · comments

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.

@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

I was stupid, sorry. Completer was working, just i thought, i was creating multiple instances, and you confirmed it.

Thanks. Closing this.