import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/dialog/loading/loading_dialog.dart';

// loading弹窗
class Loading {
  static LoadingDialog _dialog;
  static BuildContext _context;

  static Future show(BuildContext context, {
    String msg,
  }) async {
    dismiss();

    _context = context;
    _dialog = LoadingDialog(
      message: msg,
    );
    var result = await showDialog(context: context, child: _dialog);
    _context = null;
    _dialog = null;
    return result;
  }

  static dismiss() {
    if (_dialog != null && _context != null) {
      if (Navigator.canPop(_context)) {
        Navigator.pop(_context);
      }
    }
    _context = null;
    _dialog = null;
  }
}
