nsgFutureProgressAndException function

Future nsgFutureProgressAndException({
  1. required Future<void> func(),
  2. String? text,
  3. BuildContext? context,
  4. bool showProgress = true,
  5. int? delay,
})

Вызов Future функции с прогресс индикатором и проверкой на ошибки

Implementation

Future nsgFutureProgressAndException({required Future<void> Function() func, String? text, BuildContext? context, bool showProgress = true, int? delay}) async {
  var progress = NsgProgressDialog(textDialog: text ?? '', context: context, delay: delay);
  try {
    if (showProgress) {
      progress.show();
    }
    await func();
    if (showProgress) {
      progress.hide();
      await Future.delayed(const Duration(milliseconds: 100));
    }
  } catch (ex) {
    if (showProgress) {
      progress.hide();
      await Future.delayed(const Duration(milliseconds: 100));
    }
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      if (ex is Exception) {
        await NsgErrorWidget.showError(ex);
      } else {
        await NsgErrorWidget.showErrorByString(ex.toString());
      }
    });
    rethrow;
  }
}