mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
stableee
This commit is contained in:
@@ -4,8 +4,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class ExchangeRateService {
|
||||
static const String _primaryUrl = 'https://open.er-api.com/v6/latest/USD';
|
||||
static const String _fallbackUrl =
|
||||
'https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.json';
|
||||
static const String _fallbackUrl = 'https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.json';
|
||||
static const String _cacheKey = 'exchange_rates';
|
||||
|
||||
static const Map<String, double> _fallbackRates = {
|
||||
|
||||
@@ -16,7 +16,6 @@ class StorageService {
|
||||
|
||||
StorageService(this._prefs);
|
||||
|
||||
/// Load all transactions with error handling
|
||||
Result<List<Transaction>> loadTransactions() {
|
||||
return resultOf(() {
|
||||
final raw = _prefs.getString(_transactionsKey);
|
||||
@@ -29,13 +28,11 @@ class StorageService {
|
||||
});
|
||||
}
|
||||
|
||||
/// Load transactions (legacy - throws on error)
|
||||
List<Transaction> loadTransactionsUnsafe() {
|
||||
final result = loadTransactions();
|
||||
return result.getOrDefault([]);
|
||||
}
|
||||
|
||||
/// Save transactions with error handling
|
||||
Future<Result<void>> saveTransactions(List<Transaction> transactions) async {
|
||||
return asyncResultOf(() async {
|
||||
final encoded = jsonEncode(transactions.map((t) => t.toJson()).toList());
|
||||
@@ -43,7 +40,6 @@ class StorageService {
|
||||
});
|
||||
}
|
||||
|
||||
/// Add transaction with error handling
|
||||
Future<Result<void>> addTransaction(Transaction transaction) async {
|
||||
return asyncResultOf(() async {
|
||||
final listResult = loadTransactions();
|
||||
@@ -57,7 +53,6 @@ class StorageService {
|
||||
});
|
||||
}
|
||||
|
||||
/// Update transaction with error handling
|
||||
Future<Result<void>> updateTransaction(Transaction transaction) async {
|
||||
return asyncResultOf(() async {
|
||||
final listResult = loadTransactions();
|
||||
@@ -76,7 +71,6 @@ class StorageService {
|
||||
});
|
||||
}
|
||||
|
||||
/// Delete transaction with error handling
|
||||
Future<Result<void>> deleteTransaction(String id) async {
|
||||
return asyncResultOf(() async {
|
||||
final listResult = loadTransactions();
|
||||
@@ -100,7 +94,6 @@ class StorageService {
|
||||
return _prefs.getDouble(_budgetKey);
|
||||
}
|
||||
|
||||
/// Save budget with error handling
|
||||
Future<Result<void>> saveBudget(double? budget) async {
|
||||
return asyncResultOf(() async {
|
||||
if (budget == null) {
|
||||
@@ -196,7 +189,6 @@ class StorageService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Process recurring transactions with error handling (returns count)
|
||||
Future<Result<int>> processRecurringTransactionsWithResult() async {
|
||||
return asyncResultOf(() async {
|
||||
final transactionsResult = loadTransactions();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../core/utils/result.dart';
|
||||
|
||||
/// Show error snackbar with custom styling
|
||||
void showErrorSnackbar(BuildContext context, String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
@@ -28,7 +27,6 @@ void showErrorSnackbar(BuildContext context, String message) {
|
||||
);
|
||||
}
|
||||
|
||||
/// Show success snackbar with custom styling
|
||||
void showSuccessSnackbar(BuildContext context, String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
@@ -48,7 +46,6 @@ void showSuccessSnackbar(BuildContext context, String message) {
|
||||
);
|
||||
}
|
||||
|
||||
/// Show warning snackbar with custom styling
|
||||
void showWarningSnackbar(BuildContext context, String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
@@ -68,31 +65,25 @@ void showWarningSnackbar(BuildContext context, String message) {
|
||||
);
|
||||
}
|
||||
|
||||
/// Extension to handle Result with UI feedback
|
||||
extension ResultUIExtension<T> on Result<T> {
|
||||
/// Show snackbar on failure
|
||||
Result<T> showErrorOnFailure(BuildContext context) {
|
||||
onFailure((message) => showErrorSnackbar(context, message));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// Show snackbar on success with custom message
|
||||
Result<T> showSuccessMessage(BuildContext context, String message) {
|
||||
onSuccess((_) => showSuccessSnackbar(context, message));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension for Future<Result<T>>
|
||||
extension FutureResultUIExtension<T> on Future<Result<T>> {
|
||||
/// Show snackbar on failure
|
||||
Future<Result<T>> showErrorOnFailure(BuildContext context) async {
|
||||
final result = await this;
|
||||
result.onFailure((message) => showErrorSnackbar(context, message));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Show snackbar on success with custom message
|
||||
Future<Result<T>> showSuccessMessage(
|
||||
BuildContext context,
|
||||
String message,
|
||||
@@ -102,7 +93,6 @@ extension FutureResultUIExtension<T> on Future<Result<T>> {
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Show both success and error messages
|
||||
Future<Result<T>> showFeedback(
|
||||
BuildContext context, {
|
||||
required String successMessage,
|
||||
@@ -115,7 +105,6 @@ extension FutureResultUIExtension<T> on Future<Result<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Error dialog widget
|
||||
class ErrorDialog extends StatelessWidget {
|
||||
final String title;
|
||||
final String message;
|
||||
|
||||
Reference in New Issue
Block a user