优化:支付页面取消支付的时候恢复页面状态
This commit is contained in:
parent
8f92b9a61d
commit
01362f00a5
@ -4,7 +4,6 @@
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="29" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<uses-permission
|
||||
android:name="android.permission.READ_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="32" />
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
]
|
||||
},
|
||||
"analytics": {
|
||||
"debugLogs": false,
|
||||
"debugLogs": true,
|
||||
"adjust": {
|
||||
"appToken": "chflzzr4x5hc",
|
||||
"environment": "sandbox",
|
||||
|
||||
@ -27,7 +27,8 @@ class PurchaseScreen extends StatefulWidget {
|
||||
State<PurchaseScreen> createState() => _PurchaseScreenState();
|
||||
}
|
||||
|
||||
class _PurchaseScreenState extends State<PurchaseScreen> {
|
||||
class _PurchaseScreenState extends State<PurchaseScreen>
|
||||
with WidgetsBindingObserver {
|
||||
List<PaymentProductItem> _products = [];
|
||||
bool _loading = true;
|
||||
String? _loadError;
|
||||
@ -35,8 +36,17 @@ class _PurchaseScreenState extends State<PurchaseScreen> {
|
||||
int? _selectedIndex;
|
||||
ThirdPartyPaymentWatch? _thirdPartyWatch;
|
||||
|
||||
void _resetPayingState() {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_paying = false;
|
||||
_selectedIndex = null;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_thirdPartyWatch?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@ -44,6 +54,7 @@ class _PurchaseScreenState extends State<PurchaseScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
// Defer network + setState until after first frame so the route can paint and
|
||||
// the main isolate stays responsive (avoids input ANR when opening this screen).
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
@ -53,6 +64,14 @@ class _PurchaseScreenState extends State<PurchaseScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
// 对齐 app_client:从 Google Play 返回时先解锁支付按钮,避免取消/失败后长时间转圈等待超时。
|
||||
if (state == AppLifecycleState.resumed && _paying && mounted) {
|
||||
_resetPayingState();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadProducts({bool isInitial = false}) async {
|
||||
if (!isInitial) {
|
||||
setState(() {
|
||||
@ -243,7 +262,10 @@ class _PurchaseScreenState extends State<PurchaseScreen> {
|
||||
});
|
||||
|
||||
final picked = await _pickPaymentMethod(methods);
|
||||
if (!mounted || picked == null) return;
|
||||
if (!mounted || picked == null) {
|
||||
_resetPayingState();
|
||||
return;
|
||||
}
|
||||
|
||||
final pm = picked.paymentMethod?.trim() ?? '';
|
||||
if (pm.isEmpty) {
|
||||
@ -339,6 +361,7 @@ class _PurchaseScreenState extends State<PurchaseScreen> {
|
||||
createResponse: created,
|
||||
createPaymentApp: currentBackendAppType(),
|
||||
);
|
||||
_resetPayingState();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -418,6 +441,7 @@ class _PurchaseScreenState extends State<PurchaseScreen> {
|
||||
analyticsProduct: item,
|
||||
);
|
||||
|
||||
try {
|
||||
await NativeIapCoordinator.purchaseGooglePlay(
|
||||
sink: sink,
|
||||
userId: uid,
|
||||
@ -425,11 +449,8 @@ class _PurchaseScreenState extends State<PurchaseScreen> {
|
||||
storeProductId: pid,
|
||||
createPaymentApp: currentBackendAppType(),
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_paying = false;
|
||||
});
|
||||
} finally {
|
||||
_resetPayingState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ name: funymee_ai
|
||||
description: "FunyMee AI Application."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 1.0.0+1
|
||||
version: 1.0.14+14
|
||||
|
||||
environment:
|
||||
sdk: ^3.11.1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user