android
assets
ios
lib
database
models
pods
screens
services
widgets
account
chat
content
alert.native.dart
alert.web.dart
cloud_file_collection.dart
cloud_file_picker.dart
cloud_files.dart
image.dart
image.native.dart
image.web.dart
markdown.dart
video.dart
video.native.dart
video.web.dart
post
realms
alert.dart
app_scaffold.dart
check_in.dart
check_in.g.dart
context_menu.dart
response.dart
firebase_options.dart
main.dart
route.dart
route.gr.dart
linux
macos
web
windows
.gitignore
.metadata
README.md
analysis_options.yaml
build.yaml
devtools_options.yaml
firebase.json
pubspec.lock
pubspec.yaml
47 lines
1.3 KiB
Dart
47 lines
1.3 KiB
Dart
// ignore_for_file: avoid_web_libraries_in_flutter
|
|
|
|
import 'dart:developer';
|
|
import 'dart:js' as js;
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
String _parseRemoteError(DioException err) {
|
|
log('${err.requestOptions.method} ${err.requestOptions.uri} ${err.message}');
|
|
if (err.response?.data is String) return err.response?.data;
|
|
if (err.response?.data?['errors'] != null) {
|
|
final errors = err.response?.data['errors'] as Map<String, dynamic>;
|
|
return errors.values
|
|
.map(
|
|
(ele) =>
|
|
(ele as List<dynamic>).map((ele) => ele.toString()).join('\n'),
|
|
)
|
|
.join('\n');
|
|
}
|
|
return err.message ?? err.toString();
|
|
}
|
|
|
|
void showErrorAlert(dynamic err) async {
|
|
final text = switch (err) {
|
|
String _ => err,
|
|
DioException _ => _parseRemoteError(err),
|
|
Exception _ => err.toString(),
|
|
_ => err.toString(),
|
|
};
|
|
js.context.callMethod('swal', ['somethingWentWrong'.tr(), text, 'error']);
|
|
}
|
|
|
|
void showInfoAlert(String message, String title) async {
|
|
js.context.callMethod('swal', [title, message, 'info']);
|
|
}
|
|
|
|
Future<bool> showConfirmAlert(String message, String title) async {
|
|
final result = await js.context.callMethod('swal', [
|
|
title,
|
|
message,
|
|
'question',
|
|
{'buttons': true},
|
|
]);
|
|
return result == true;
|
|
}
|