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