Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:app_finance/_classes/controller/purchase_controller.dart';
5 : import 'package:flutter/foundation.dart';
6 : import 'package:in_app_purchase/in_app_purchase.dart';
7 :
8 : class AppPurchase extends ChangeNotifier {
9 : late PurchaseController controller = PurchaseController(_update);
10 : Map<String, ProductDetails> product = {};
11 : Map<String, List<PurchaseDetails>> purchase = {};
12 :
13 0 : AppPurchase() {
14 0 : if (PurchaseController.supportsPurchases) {
15 0 : _load();
16 : }
17 : }
18 :
19 0 : Future<void> _load() async {
20 0 : for (var item in await controller.load()) {
21 0 : product[item.id] = item;
22 : }
23 0 : notifyListeners();
24 : }
25 :
26 0 : void _update(List<PurchaseDetails> scope) {
27 0 : for (var item in scope) {
28 0 : if (!product.containsKey(item.productID)) {
29 0 : purchase[item.productID] = <PurchaseDetails>[];
30 : }
31 0 : purchase[item.productID]!.add(item);
32 : }
33 0 : notifyListeners();
34 : }
35 : }
|