✨ Restore purchase
This commit is contained in:
parent
9367a515f4
commit
abd89b538c
@ -513,5 +513,12 @@
|
|||||||
"membershipFeatureAllNova": "All Nova features",
|
"membershipFeatureAllNova": "All Nova features",
|
||||||
"membershipFeatureExclusiveContent": "Exclusive content",
|
"membershipFeatureExclusiveContent": "Exclusive content",
|
||||||
"membershipFeatureVipSupport": "VIP support",
|
"membershipFeatureVipSupport": "VIP support",
|
||||||
"membershipCurrentBadge": "CURRENT"
|
"membershipCurrentBadge": "CURRENT",
|
||||||
|
"restorePurchase": "Restore Purchase",
|
||||||
|
"restorePurchaseDescription": "Enter your payment provider and order ID to restore your purchase.",
|
||||||
|
"provider": "Provider",
|
||||||
|
"selectProvider": "Select a provider",
|
||||||
|
"orderId": "Order ID",
|
||||||
|
"enterOrderId": "Enter your order ID",
|
||||||
|
"restore": "Restore"
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import 'package:island/pods/userinfo.dart';
|
|||||||
import 'package:island/services/responsive.dart';
|
import 'package:island/services/responsive.dart';
|
||||||
import 'package:island/services/time.dart';
|
import 'package:island/services/time.dart';
|
||||||
import 'package:island/widgets/account/leveling_progress.dart';
|
import 'package:island/widgets/account/leveling_progress.dart';
|
||||||
|
import 'package:island/widgets/account/restore_purchase_sheet.dart';
|
||||||
import 'package:island/widgets/alert.dart';
|
import 'package:island/widgets/alert.dart';
|
||||||
import 'package:island/widgets/app_scaffold.dart';
|
import 'package:island/widgets/app_scaffold.dart';
|
||||||
import 'package:island/widgets/payment/payment_overlay.dart';
|
import 'package:island/widgets/payment/payment_overlay.dart';
|
||||||
@ -54,6 +55,9 @@ class LevelingScreen extends HookConsumerWidget {
|
|||||||
appBar: AppBar(title: Text('levelingProgress'.tr())),
|
appBar: AppBar(title: Text('levelingProgress'.tr())),
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
padding: getTabbedPadding(context, horizontal: 20, vertical: 20),
|
padding: getTabbedPadding(context, horizontal: 20, vertical: 20),
|
||||||
|
child: Center(
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 480),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
@ -68,9 +72,9 @@ class LevelingScreen extends HookConsumerWidget {
|
|||||||
// Level Stairs Graph
|
// Level Stairs Graph
|
||||||
Text(
|
Text(
|
||||||
'levelProgress'.tr(),
|
'levelProgress'.tr(),
|
||||||
style: Theme.of(
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||||
context,
|
fontWeight: FontWeight.bold,
|
||||||
).textTheme.headlineSmall?.copyWith(fontWeight: FontWeight.bold),
|
),
|
||||||
),
|
),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
|
|
||||||
@ -96,7 +100,10 @@ class LevelingScreen extends HookConsumerWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'unlockedFeatures'.tr(),
|
'unlockedFeatures'.tr(),
|
||||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const Gap(8),
|
const Gap(8),
|
||||||
Text(
|
Text(
|
||||||
@ -111,6 +118,8 @@ class LevelingScreen extends HookConsumerWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,6 +339,17 @@ class LevelingScreen extends HookConsumerWidget {
|
|||||||
const Gap(12),
|
const Gap(12),
|
||||||
|
|
||||||
_buildMembershipTiers(context, ref, membership),
|
_buildMembershipTiers(context, ref, membership),
|
||||||
|
const Gap(12),
|
||||||
|
|
||||||
|
// Restore Purchase Button
|
||||||
|
OutlinedButton.icon(
|
||||||
|
onPressed: () => _showRestorePurchaseSheet(context, ref),
|
||||||
|
icon: const Icon(Icons.restore),
|
||||||
|
label: Text('restorePurchase'.tr()),
|
||||||
|
style: OutlinedButton.styleFrom(
|
||||||
|
minimumSize: const Size(double.infinity, 48),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -565,6 +585,16 @@ class LevelingScreen extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _showRestorePurchaseSheet(
|
||||||
|
BuildContext context,
|
||||||
|
WidgetRef ref,
|
||||||
|
) async {
|
||||||
|
await showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => const RestorePurchaseSheet(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _purchaseMembership(
|
Future<void> _purchaseMembership(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
WidgetRef ref,
|
WidgetRef ref,
|
||||||
|
142
lib/widgets/account/restore_purchase_sheet.dart
Normal file
142
lib/widgets/account/restore_purchase_sheet.dart
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
import 'package:gap/gap.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:island/pods/network.dart';
|
||||||
|
import 'package:island/screens/account/me/settings_connections.dart';
|
||||||
|
import 'package:island/services/responsive.dart';
|
||||||
|
import 'package:island/widgets/alert.dart';
|
||||||
|
import 'package:island/widgets/content/sheet.dart';
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:styled_widget/styled_widget.dart';
|
||||||
|
|
||||||
|
class RestorePurchaseSheet extends HookConsumerWidget {
|
||||||
|
const RestorePurchaseSheet({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final selectedProvider = useState<String?>(null);
|
||||||
|
final orderIdController = useTextEditingController();
|
||||||
|
final isLoading = useState(false);
|
||||||
|
|
||||||
|
final providers = ['afdian'];
|
||||||
|
|
||||||
|
Future<void> restorePurchase() async {
|
||||||
|
if (selectedProvider.value == null ||
|
||||||
|
orderIdController.text.trim().isEmpty) {
|
||||||
|
showErrorAlert('Please fill in all fields');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoading.value = true;
|
||||||
|
try {
|
||||||
|
final client = ref.read(apiClientProvider);
|
||||||
|
await client.post(
|
||||||
|
'/wallet/subscriptions/order/restore/${selectedProvider.value!}',
|
||||||
|
data: {'order_id': orderIdController.text.trim()},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
showSnackBar(context, 'Purchase restored successfully!');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
showErrorAlert(err);
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SheetScaffold(
|
||||||
|
titleText: 'restorePurchase'.tr(),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
padding: getTabbedPadding(context),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'restorePurchaseDescription'.tr(),
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Gap(24),
|
||||||
|
|
||||||
|
// Provider Selection
|
||||||
|
Text(
|
||||||
|
'provider'.tr(),
|
||||||
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
|
),
|
||||||
|
const Gap(8),
|
||||||
|
Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(
|
||||||
|
color: Theme.of(context).colorScheme.outline,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: DropdownButtonHideUnderline(
|
||||||
|
child: DropdownButton<String>(
|
||||||
|
value: selectedProvider.value,
|
||||||
|
hint: Text('selectProvider'.tr()),
|
||||||
|
isExpanded: true,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
|
items:
|
||||||
|
providers.map((provider) {
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
value: provider,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
getProviderIcon(
|
||||||
|
provider,
|
||||||
|
size: 20,
|
||||||
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
const Gap(12),
|
||||||
|
Text(getLocalizedProviderName(provider)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: (value) {
|
||||||
|
selectedProvider.value = value;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Gap(16),
|
||||||
|
|
||||||
|
// Order ID Input
|
||||||
|
Text(
|
||||||
|
'orderId'.tr(),
|
||||||
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
|
),
|
||||||
|
const Gap(8),
|
||||||
|
TextField(
|
||||||
|
controller: orderIdController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'enterOrderId'.tr(),
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Gap(24),
|
||||||
|
|
||||||
|
// Restore Button
|
||||||
|
FilledButton(
|
||||||
|
onPressed: isLoading.value ? null : restorePurchase,
|
||||||
|
child:
|
||||||
|
isLoading.value
|
||||||
|
? const SizedBox(
|
||||||
|
height: 20,
|
||||||
|
width: 20,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: Text('restore'.tr()),
|
||||||
|
),
|
||||||
|
const Gap(16),
|
||||||
|
],
|
||||||
|
).padding(all: 16),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user