showErrorToast static method

dynamic showErrorToast(
  1. BuildContext? context, {
  2. dynamic res,
  3. dynamic back,
})

错误提示统一

Implementation

static showErrorToast(BuildContext? context, {res, back}) async {
  try {
    if (context == null) {
      return;
    }
    var connectivityResult = await (Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.none) {
      back?.call(S.of(context).strNetworkError);
    } else {
      if (res == null) {
        back?.call(S.of(context).strAppHttpErr);
      } else if (res is String) {
        back?.call(res);
      } else if (res.data is! ResultData) {
        if (res.dataError == true) {
          back?.call(S.of(context).strAppHttpErr);
        } else {
          try {
            if (res.data?.msg == null) {
              back?.call(S.of(context).strAppHttpErr);
            } else {
              back?.call(res.data?.msg);
            }
          } catch (e) {
            back?.call(S.of(context).strAppHttpErr);
          }
        }
      } else {
        back?.call(S.of(context).strAppHttpErr);
      }
    }
  } catch (e) {
    AppConfig.printLog(e);
  }
}