small fixes

This commit is contained in:
Arseni
2026-02-11 15:26:11 +03:00
parent edb43f9909
commit 0a1e04d0d6
7 changed files with 138 additions and 53 deletions

View File

@@ -0,0 +1,70 @@
import 'package:flutter/foundation.dart';
import 'package:pshared/provider/payment/multiple/quotation.dart';
import 'package:pweb/providers/quotation/auto_refresh.dart';
class MultiQuotationController extends ChangeNotifier {
static const Duration _autoRefreshLead = Duration(seconds: 5);
MultiQuotationProvider? _quotation;
final QuotationAutoRefreshController _autoRefreshController =
QuotationAutoRefreshController();
void update(MultiQuotationProvider quotation) {
if (identical(_quotation, quotation)) return;
_quotation?.removeListener(_handleQuotationChanged);
_quotation = quotation;
_quotation?.addListener(_handleQuotationChanged);
_handleQuotationChanged();
}
bool get isLoading => _quotation?.isLoading ?? false;
Exception? get error => _quotation?.error;
bool get canRefresh => _quotation?.canRefresh ?? false;
bool get isReady => _quotation?.isReady ?? false;
DateTime? get quoteExpiresAt => _quotation?.quoteExpiresAt;
void refreshQuotation() {
_quotation?.refreshQuotation();
}
void _handleQuotationChanged() {
_syncAutoRefresh();
notifyListeners();
}
void _syncAutoRefresh() {
final quotation = _quotation;
if (quotation == null) {
_autoRefreshController.reset();
return;
}
final expiresAt = quoteExpiresAt;
final scheduledAt = expiresAt == null
? null
: expiresAt.subtract(_autoRefreshLead);
_autoRefreshController.setEnabled(true);
_autoRefreshController.sync(
isLoading: quotation.isLoading,
canRefresh: quotation.canRefresh,
expiresAt: scheduledAt,
onRefresh: _refreshQuotation,
);
}
Future<void> _refreshQuotation() async {
await _quotation?.refreshQuotation();
}
@override
void dispose() {
_quotation?.removeListener(_handleQuotationChanged);
_autoRefreshController.dispose();
super.dispose();
}
}