chore : change app archticle
This commit is contained in:
6
packages/core/lib/utils/README.md
Normal file
6
packages/core/lib/utils/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
```markdown
|
||||
در معماری DDD (Domain-Driven Design)، فایلهای utils یا همان ابزارهای کمکی (utility/helpers) معمولاً:
|
||||
|
||||
✅ در هیچ لایهی خاصی قرار نمیگیرند،
|
||||
❗ بلکه بهصورت cross-cutting concerns یا "مسائل متقاطع" در نظر گرفته میشن، چون در همهی لایهها ممکنه استفاده بشن.
|
||||
```
|
||||
37
packages/core/lib/utils/logger_utils.dart
Normal file
37
packages/core/lib/utils/logger_utils.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:rasadyar_core/injection/di.dart';
|
||||
|
||||
void iLog(dynamic message) {
|
||||
if(kDebugMode){
|
||||
diCore.get<Logger>().i(message.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void eLog(dynamic message) {
|
||||
if(kDebugMode){
|
||||
diCore.get<Logger>().e(message.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dLog(dynamic message) {
|
||||
if(kDebugMode){
|
||||
diCore.get<Logger>().d(message.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void fLog(dynamic message){
|
||||
if(kDebugMode){
|
||||
diCore.get<Logger>().f(message.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void tLog(dynamic message) {
|
||||
if(kDebugMode){
|
||||
diCore.get<Logger>().t(message.toString());
|
||||
}
|
||||
}
|
||||
|
||||
71
packages/core/lib/utils/safe_call_utils.dart
Normal file
71
packages/core/lib/utils/safe_call_utils.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
typedef AsyncCallback<T> = Future<T> Function();
|
||||
typedef ErrorCallback = void Function(dynamic error, StackTrace? stackTrace);
|
||||
typedef VoidCallback = void Function();
|
||||
|
||||
// تعریف دقیق تابع safeCall
|
||||
Future<T?> safeCall<T>({
|
||||
required AsyncCallback<T> call,
|
||||
Function(T result)? onSuccess,
|
||||
ErrorCallback? onError,
|
||||
VoidCallback? onComplete,
|
||||
bool showLoading = false,
|
||||
bool showError = false,
|
||||
bool showSuccess = false,
|
||||
bool showToast = false,
|
||||
bool showSnackBar = false,
|
||||
Function()? onShowLoading,
|
||||
Function()? onHideLoading,
|
||||
Function()? onShowSuccessMessage,
|
||||
Function()? onShowErrorMessage,
|
||||
}) async {
|
||||
try {
|
||||
if (showLoading) {
|
||||
(onShowLoading ?? _defaultShowLoading)();
|
||||
}
|
||||
|
||||
final result = await call();
|
||||
|
||||
if (showSuccess) {
|
||||
(onShowSuccessMessage ?? _defaultShowSuccessMessage)();
|
||||
}
|
||||
|
||||
onSuccess?.call(result);
|
||||
return result; // اضافه کردن بازگشت نتیجه
|
||||
|
||||
} catch (error, stackTrace) {
|
||||
if (showError) {
|
||||
(onShowErrorMessage ?? _defaultShowErrorMessage)();
|
||||
}
|
||||
|
||||
onError?.call(error, stackTrace);
|
||||
if (kDebugMode) {
|
||||
print('safeCall error: $error\n$stackTrace');
|
||||
}
|
||||
|
||||
return null;
|
||||
} finally {
|
||||
if (showLoading) {
|
||||
(onHideLoading ?? _defaultHideLoading)();
|
||||
}
|
||||
|
||||
onComplete?.call();
|
||||
}
|
||||
}
|
||||
|
||||
void _defaultShowLoading() {
|
||||
// پیادهسازی پیشفرض
|
||||
}
|
||||
|
||||
void _defaultHideLoading() {
|
||||
// پیادهسازی پیشفرض
|
||||
}
|
||||
|
||||
void _defaultShowSuccessMessage() {
|
||||
// پیادهسازی پیشفرض
|
||||
}
|
||||
|
||||
void _defaultShowErrorMessage() {
|
||||
// پیادهسازی پیشفرض
|
||||
}
|
||||
Reference in New Issue
Block a user