From 990efc8f7bb583c9d1abcc4976025879ab4a38f9 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 12 Aug 2020 19:05:58 +0200 Subject: [PATCH] Add a 'Restore Purchase' button Instead of doing it automatically, Fixes #211 --- assets/langs/en.yaml | 1 + lib/screens/purchase_screen.dart | 3 ++- lib/widgets/purchase_widget.dart | 35 +++++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/assets/langs/en.yaml b/assets/langs/en.yaml index e453cfdf..cc52b519 100644 --- a/assets/langs/en.yaml +++ b/assets/langs/en.yaml @@ -221,3 +221,4 @@ purchase_screen: Paying a monthly subscription helps you support development and gives you access to a number of "Pro" only features. We operate on a "pay what you want model". No matter what you pay you will get access to all the Pro features.' + restore: Restore Purchase diff --git a/lib/screens/purchase_screen.dart b/lib/screens/purchase_screen.dart index 6f46d506..1bfc90dc 100644 --- a/lib/screens/purchase_screen.dart +++ b/lib/screens/purchase_screen.dart @@ -23,7 +23,6 @@ class PurchaseScreen extends StatelessWidget { } Widget buildBody(BuildContext context) { - Widget w = Column( children: [ Text( @@ -43,6 +42,8 @@ class PurchaseScreen extends StatelessWidget { ), const SizedBox(height: 64.0), PurchaseWidget(), + const SizedBox(height: 32.0), + RestorePurchaseButton(), ], mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.min, diff --git a/lib/widgets/purchase_widget.dart b/lib/widgets/purchase_widget.dart index 7d109812..f3ed2873 100644 --- a/lib/widgets/purchase_widget.dart +++ b/lib/widgets/purchase_widget.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:in_app_purchase/in_app_purchase.dart'; @@ -74,13 +75,6 @@ class _PurchaseWidgetState extends State { } Future initPlatformState() async { - // In parallel check if the purchase has been made - InAppPurchases.confirmProPurchase().then((void _) { - if (Settings.instance.proMode) { - Navigator.of(context).pop(); - } - }); - final iapCon = InAppPurchaseConnection.instance; final bool available = await iapCon.isAvailable(); @@ -335,3 +329,30 @@ class PurchaseFailedDialog extends StatelessWidget { ); } } + +class RestorePurchaseButton extends StatefulWidget { + @override + _RestorePurchaseButtonState createState() => _RestorePurchaseButtonState(); +} + +class _RestorePurchaseButtonState extends State { + bool computing = false; + + @override + Widget build(BuildContext context) { + var text = computing ? '...' : tr('purchase_screen.restore'); + + return OutlineButton( + child: Text(text), + onPressed: () async { + setState(() { + computing = true; + }); + await InAppPurchases.confirmProPurchase(); + if (Settings.instance.proMode) { + Navigator.of(context).pop(); + } + }, + ); + } +}