refresh method

Future<void> refresh()

Refresh the store if there are any active listeners.

Implementation

Future<void> refresh() async {
  final paymentMethodFuture = _customerSession.listPaymentMethods(limit: 100);
  isLoading = true;
  notifyListeners();
  return paymentMethodFuture.then((value) {
    final List listData = value['data'] ?? <PaymentMethod>[];
    paymentMethods.clear();
    if (listData.isNotEmpty) {
      paymentMethods.addAll(listData
          .map((item) => PaymentMethod(item['id'], item['card']['last4'], item['card']['brand'],
              DateTime(item['card']['exp_year'], item['card']['exp_month'])))
          .toList());
    }
  }).whenComplete(() {
    isLoading = false;
    notifyListeners();
  });
}