Files
sure/mobile/lib/providers/merchants_provider.dart
ghost 5372a08788 feat(mobile): add transaction metadata editing (#2131)
* feat(mobile): add transaction metadata editing

* fix(mobile): preserve explicit metadata clears

* fix(mobile): derive persisted tag metadata state

* fix(mobile): avoid logging transaction details

* fix(mobile): harden transaction edit sync

Pass the edited transaction context through provider updates, refresh or fall back after empty update responses, surface field-level API errors, and avoid forced metadata refetches on every edit screen open.

* fix(mobile): keep transaction edit selects ci-compatible

Use the DropdownButtonFormField API supported by the Flutter version pinned in upstream mobile CI.
2026-06-04 23:02:57 +02:00

63 lines
1.7 KiB
Dart

import 'package:flutter/foundation.dart';
import '../models/merchant.dart';
import '../services/log_service.dart';
import '../services/merchants_service.dart';
class MerchantsProvider with ChangeNotifier {
final MerchantsService _merchantsService = MerchantsService();
final LogService _log = LogService.instance;
List<Merchant> _merchants = [];
bool _isLoading = false;
String? _error;
bool _hasFetched = false;
List<Merchant> get merchants => List.unmodifiable(_merchants);
bool get isLoading => _isLoading;
String? get error => _error;
bool get hasFetched => _hasFetched;
Future<void> fetchMerchants({
required String accessToken,
bool forceRefresh = false,
}) async {
if (_isLoading || (_hasFetched && !forceRefresh)) return;
_isLoading = true;
_error = null;
notifyListeners();
try {
final result = await _merchantsService.getMerchants(
accessToken: accessToken,
);
if (result['success'] == true) {
_merchants =
(result['merchants'] as List? ?? const []).cast<Merchant>();
_hasFetched = true;
_log.info(
'MerchantsProvider',
'Fetched ${_merchants.length} merchants',
);
} else {
_error = result['error'] as String?;
_log.error('MerchantsProvider', 'Failed to fetch merchants: $_error');
}
} catch (e) {
_error = 'Failed to load merchants';
_log.error('MerchantsProvider', 'Exception fetching merchants: $e');
} finally {
_isLoading = false;
notifyListeners();
}
}
void clear() {
_merchants = [];
_hasFetched = false;
_error = null;
notifyListeners();
}
}