import 'package:flutter/material.dart';

class BaseUIModel with ChangeNotifier {
  static Function? staticNotifyListeners;
  BuildContext? context;
  bool showProgressHUD = false;

  bool initialPage = true;

  /// 判断页面是否被销毁
  bool disposed = false;

  dismissKeyboard(BuildContext? context) {
    if (context == null) {
      return;
    }
    FocusScope.of(context).requestFocus(FocusNode());
  }

  showLoadingHud() {
    showProgressHUD = true;
    notifyListeners();
  }

  dismissLoadingHud() {
    showProgressHUD = false;
    notifyListeners();
  }

  @override
  void notifyListeners() {
    if (!hasListeners) {
      return;
    }
    if (disposed) {
      return;
    }
    super.notifyListeners();
  }

  @override
  void dispose() {
    disposed = true;
    super.dispose();
  }
}
