app/lib/common/utils/async.dart

18 lines
479 B
Dart
Raw Normal View History

2024-03-10 18:00:46 +08:00
import 'package:fluent_ui/fluent_ui.dart';
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
import 'package:starcitizen_doctor/common/utils/log.dart';
extension AsyncError on Future {
2024-03-10 18:00:46 +08:00
Future<T?> unwrap<T>({BuildContext? context}) async {
try {
return await this;
} catch (e) {
dPrint("unwrap error:$e");
if (context != null && context.mounted) {
2024-03-10 18:00:46 +08:00
showToast(context, "出现错误: $e");
}
return null;
}
}
}