Add a 'Restore Purchase' button

Instead of doing it automatically,

Fixes #211
This commit is contained in:
Vishesh Handa
2020-08-12 19:05:58 +02:00
parent 199b9682bc
commit 990efc8f7b
3 changed files with 31 additions and 8 deletions

View File

@ -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

View File

@ -23,7 +23,6 @@ class PurchaseScreen extends StatelessWidget {
}
Widget buildBody(BuildContext context) {
Widget w = Column(
children: <Widget>[
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,

View File

@ -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<PurchaseWidget> {
}
Future<void> 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<RestorePurchaseButton> {
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();
}
},
);
}
}