diff --git a/lib/screens/purchase_screen.dart b/lib/screens/purchase_screen.dart index 4d71a600..5da0b79e 100644 --- a/lib/screens/purchase_screen.dart +++ b/lib/screens/purchase_screen.dart @@ -23,9 +23,6 @@ class PurchaseScreen extends StatelessWidget { } Widget buildBody(BuildContext context) { - var theme = Theme.of(context); - var textTheme = theme.textTheme; - Widget w = Column( children: [ Text( @@ -33,21 +30,7 @@ class PurchaseScreen extends StatelessWidget { style: Theme.of(context).textTheme.bodyText2, ), const SizedBox(height: 32.0), - Card( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(15.0), - ), - child: Padding( - padding: const EdgeInsets.fromLTRB(16.0, 32.0, 16.0, 32.0), - child: Column( - children: [ - Text("Monthly Subscription", style: textTheme.headline5), - const SizedBox(height: 32.0), - PurchaseWidget(), - ], - ), - ), - ), + const MonthlyRentalWidget(), const SizedBox(height: 32.0), Row( children: [ @@ -85,3 +68,84 @@ class PurchaseScreen extends StatelessWidget { return true; } } + +class MonthlyRentalWidget extends StatelessWidget { + const MonthlyRentalWidget({ + Key key, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + var textTheme = Theme.of(context).textTheme; + + return Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15.0), + ), + child: Padding( + padding: const EdgeInsets.fromLTRB(16.0, 32.0, 16.0, 32.0), + child: Column( + children: [ + Text("Monthly Subscription", style: textTheme.headline5), + const SizedBox(height: 32.0), + PurchaseWidget( + skus: _generateSkus(), + defaultSku: "sku_monthly_min3", + timePeriod: "Month", + ), + ], + ), + ), + ); + } + + Set _generateSkus() { + var list = {}; + for (var i = 0; i <= 50; i++) { + list.add("sku_monthly_min$i"); + } + return list; + } +} + +class YearlyPurchaseWidget extends StatelessWidget { + const YearlyPurchaseWidget({ + Key key, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + var textTheme = Theme.of(context).textTheme; + + return Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15.0), + ), + child: Padding( + padding: const EdgeInsets.fromLTRB(16.0, 32.0, 16.0, 32.0), + child: Column( + children: [ + Text("Yearly Purchase", style: textTheme.headline5), + const SizedBox(height: 32.0), + PurchaseWidget( + skus: _generateSkus(), + defaultSku: "sku_sub_yearly_0", + timePeriod: "Year", + ), + const SizedBox(height: 8.0), + const Text( + "Enables all Pro features currently in GitJournal and new ones added the next year. These features will be yours forever.") + ], + ), + ), + ); + } + + Set _generateSkus() { + var list = {}; + for (var i = 0; i <= 20; i++) { + list.add("sku_sub_yearly_$i"); + } + return list; + } +} diff --git a/lib/widgets/purchase_widget.dart b/lib/widgets/purchase_widget.dart index a626f317..32550113 100644 --- a/lib/widgets/purchase_widget.dart +++ b/lib/widgets/purchase_widget.dart @@ -15,15 +15,16 @@ import 'package:gitjournal/widgets/purchase_slider.dart'; class PurchaseButton extends StatelessWidget { final ProductDetails product; + final String timePeriod; - PurchaseButton(this.product); + PurchaseButton(this.product, this.timePeriod); @override Widget build(BuildContext context) { var price = product != null ? product.price : "Dev Mode"; return RaisedButton( - child: Text('Subscribe for $price / month'), + child: Text('Subscribe for $price / $timePeriod'), color: Theme.of(context).primaryColor, padding: const EdgeInsets.fromLTRB(32.0, 16.0, 32.0, 16.0), onPressed: product != null ? () => _initPurchase(context) : null, @@ -46,15 +47,17 @@ class PurchaseButton extends StatelessWidget { } } -Set _generateSkus() { - var list = {}; - for (var i = 0; i <= 50; i++) { - list.add("sku_monthly_min$i"); - } - return list; -} - class PurchaseWidget extends StatefulWidget { + final Set skus; + final String defaultSku; + final String timePeriod; + + PurchaseWidget({ + @required this.skus, + @required this.defaultSku, + @required this.timePeriod, + }); + @override _PurchaseWidgetState createState() => _PurchaseWidgetState(); } @@ -64,7 +67,6 @@ class _PurchaseWidgetState extends State { ProductDetails _selectedProduct; StreamSubscription> _subscription; - final defaultSku = "sku_monthly_min3"; String error = ""; bool pendingPurchase = false; @@ -86,7 +88,7 @@ class _PurchaseWidgetState extends State { return; } - final response = await iapCon.queryProductDetails(_generateSkus()); + final response = await iapCon.queryProductDetails(widget.skus); if (response.error != null) { Log.e("IAP queryProductDetails: ${response.error}"); } @@ -112,7 +114,7 @@ class _PurchaseWidgetState extends State { if (_products.length > 1) { for (var p in _products) { - if (p.id == defaultSku) { + if (p.id == widget.defaultSku) { _selectedProduct = p; break; } @@ -264,7 +266,7 @@ class _PurchaseWidgetState extends State { mainAxisSize: MainAxisSize.max, ), const SizedBox(height: 16.0), - PurchaseButton(_selectedProduct), + PurchaseButton(_selectedProduct, widget.timePeriod), ], mainAxisAlignment: MainAxisAlignment.spaceAround, );