File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ REVENUE_CAT_API_KEY =
Original file line number Diff line number Diff line change 1+ * .env
2+
13# Miscellaneous
24* .class
35* .log
Original file line number Diff line number Diff line change 1- import 'package:flutter/material.dart' ;
2-
31abstract interface class IInAppPurchaseDataSource {
42 Future <bool > buyProduct (String productId);
53 Future <bool > checkStatus (String productId);
6- void init (ValueNotifier <bool > notifier);
74}
Original file line number Diff line number Diff line change 1- import 'package:flutter/material.dart' ;
21import 'package:frontend/data_sources/in_app_purchase_data_source.dart' ;
32import 'package:purchases_flutter/purchases_flutter.dart' ;
43
54class RevenueCatDataSource implements IInAppPurchaseDataSource {
6- //The key of a product should be the same as an entitlement name attached to it
7- static const _proVersionKey = 'chessknock_pro_version' ;
85 @override
96 Future <bool > buyProduct (String productId) async {
107 final product = (await Purchases .getProducts ([productId])).first;
@@ -18,17 +15,4 @@ class RevenueCatDataSource implements IInAppPurchaseDataSource {
1815 final customerInfo = await Purchases .getCustomerInfo ();
1916 return customerInfo.entitlements.active.containsKey (productId);
2017 }
21-
22- @override
23- void init (ValueNotifier <bool > notifier) {
24- try {
25- Purchases .addCustomerInfoUpdateListener ((info) {
26- info.entitlements.active.containsKey (_proVersionKey)
27- ? notifier.value = true
28- : notifier.value = false ;
29- });
30- } catch (e) {
31- throw Exception ('function type should be void Function(bool)' );
32- }
33- }
3418}
Original file line number Diff line number Diff line change 11import "dart:io" ;
22
3+ import "package:flutter_dotenv/flutter_dotenv.dart" ;
34import "package:frontend/data_sources/revenuecat_data_source.dart" ;
45import "package:frontend/exports.dart" ;
56import "package:flutter/material.dart" ;
@@ -10,18 +11,18 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
1011import "package:purchases_flutter/purchases_flutter.dart" ;
1112
1213void main () async {
14+ await dotenv.load (fileName: ".env" );
1315 WidgetsFlutterBinding .ensureInitialized ();
1416 if (Platform .isIOS) {
1517 await configureRevenueCat ();
1618 }
1719 runApp (const MyApp ());
1820}
1921
20- const _revenueCatApiKey = 'appl_XXuSbFegqvobEdAwmWZnhIlglOX' ;
21-
2222Future <void > configureRevenueCat () async {
2323 Purchases .setLogLevel (LogLevel .debug);
24- Purchases .configure (PurchasesConfiguration (_revenueCatApiKey));
24+ final apiKey = dotenv.env['REVENUE_CAT_API_KEY' ];
25+ Purchases .configure (PurchasesConfiguration (apiKey! ));
2526}
2627
2728class MyApp extends StatelessWidget {
@@ -43,7 +44,6 @@ class MyApp extends StatelessWidget {
4344 repository: InAppPurchaseRepository (
4445 //TODO: choose data source based off of a platform
4546 dataSource: RevenueCatDataSource (),
46- proStatusNotifier: ValueNotifier <bool >(false ),
4747 ),
4848 ),
4949 )
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ class ProVersionProvider extends ChangeNotifier {
1616 }
1717
1818 void _init () async {
19- _setProStatus (_repository.getStatus ());
19+ final isPro = await _repository.checkStatus (_proVersionKey);
20+ _setProStatus (isPro);
2021 }
2122
2223 void _setProStatus (bool status) {
@@ -32,7 +33,7 @@ class ProVersionProvider extends ChangeNotifier {
3233 Future <void > upgradeToPro () async {
3334 try {
3435 await _repository.buyProduct (_proVersionKey);
35- final isPro = _repository.getStatus ( );
36+ final isPro = await _repository.checkStatus (_proVersionKey );
3637 _setProStatus (isPro);
3738 _setPurchaseError (false );
3839 } catch (_) {
Original file line number Diff line number Diff line change 1- import 'package:flutter/material.dart' ;
21import 'package:frontend/data_sources/in_app_purchase_data_source.dart' ;
32
43class InAppPurchaseRepository {
54 final IInAppPurchaseDataSource _dataSource;
6- final ValueNotifier <bool > _proStatusNotifier;
75
8- InAppPurchaseRepository (
9- {required IInAppPurchaseDataSource dataSource,
10- required ValueNotifier <bool > proStatusNotifier})
11- : _dataSource = dataSource,
12- _proStatusNotifier = proStatusNotifier {
13- _init ();
14- }
6+ InAppPurchaseRepository ({
7+ required IInAppPurchaseDataSource dataSource,
8+ }) : _dataSource = dataSource;
159
1610 Future <bool > buyProduct (String productId) {
1711 return _dataSource.buyProduct (productId);
@@ -20,12 +14,4 @@ class InAppPurchaseRepository {
2014 Future <bool > checkStatus (String productId) {
2115 return _dataSource.checkStatus (productId);
2216 }
23-
24- void _init () {
25- _dataSource.init (_proStatusNotifier);
26- }
27-
28- bool getStatus () {
29- return _proStatusNotifier.value;
30- }
3117}
Original file line number Diff line number Diff line change @@ -126,6 +126,14 @@ packages:
126126 description: flutter
127127 source: sdk
128128 version: "0.0.0"
129+ flutter_dotenv:
130+ dependency: "direct main"
131+ description:
132+ name: flutter_dotenv
133+ sha256: b7c7be5cd9f6ef7a78429cabd2774d3c4af50e79cb2b7593e3d5d763ef95c61b
134+ url: "https://pub.dev"
135+ source: hosted
136+ version: "5.2.1"
129137 flutter_launcher_icons:
130138 dependency: "direct dev"
131139 description:
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ dependencies:
2828 flutter_localizations :
2929 sdk : flutter
3030 purchases_flutter : ^5.8.0
31+ flutter_dotenv : ^5.2.1
3132
3233dev_dependencies :
3334 flutter_test :
@@ -52,6 +53,7 @@ flutter:
5253 - assets/images/small_pieces/
5354 - assets/images/icons/
5455 - assets/images/guide_boards/
56+ - .env
5557
5658 fonts :
5759 - family : Roboto
You can’t perform that action at this time.
0 commit comments