Commit e44879c0 authored by skeyboy's avatar skeyboy

同步Android、iOS支付页

parent 5487a56b
...@@ -110,120 +110,123 @@ class UserStore extends GetxController { ...@@ -110,120 +110,123 @@ class UserStore extends GetxController {
} }
void logout() { void logout() {
_profile.value = IntegralEntity(
id: '', token: '', username: '', integral: 0, expireTime: null);
_isLogin.value = false;
}
Future refreshInfo() async { StorageService.to.remove(STORAGE_USER_TOKEN_KEY);
if (GetPlatform.isIOS) { StorageService.to.remove(STORAGE_USER_PROFILE_KEY);
IosDeviceInfo iosInfo = await deviceInfo.iosInfo; _profile.value = IntegralEntity(
id: '', token: '', username: '', integral: 0, expireTime: null);
_isLogin.value = false;
}
final res = await UserAPI.appleLogin({ Future refreshInfo() async {
"phone": iosInfo.data['identifierForVendor'], if (GetPlatform.isIOS) {
}); IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
final value = IntegralEntity( final res = await UserAPI.appleLogin({
expireTime: res.expireTime == null ? null : res.expireTime, "phone": iosInfo.data['identifierForVendor'],
id: res.id, });
token: res.token,
username: res.username, final value = IntegralEntity(
integral: res.integral, expireTime: res.expireTime == null ? null : res.expireTime,
); id: res.id,
token = res.token; token: res.token,
_profile.value = _profile(value); username: res.username,
integral: res.integral,
);
token = res.token;
_profile.value = _profile(value);
if (profile.id != '') { if (profile.id != '') {
_isLogin.value = true; _isLogin.value = true;
}
// await MainController.to.asyncLoadBannerData();
} }
}
// await MainController.to.asyncLoadBannerData(); handleLogin(IntegralEntity res) async {
await setToken(res.token);
// IntegralEntity userInfo = await UserAPI.getUserIntegral();
await getUserInfo(IntegralEntity(
id: res.id,
username: res.username,
token: res.token,
integral: res.integral,
expireTime: res.expireTime,
));
_isLogin.value = true;
Get.back();
// Get.put(ApplicationController());
// Get.offAndToNamed(AppRoutes.Application);
} }
}
handleLogin(IntegralEntity res) async { getUserInfo(IntegralEntity userInfo) async {
await setToken(res.token); await setToken(userInfo.token);
// IntegralEntity userInfo = await UserAPI.getUserIntegral();
await getUserInfo(IntegralEntity(
id: res.id,
username: res.username,
token: res.token,
integral: res.integral,
expireTime: res.expireTime,
));
_isLogin.value = true;
Get.back();
// Get.put(ApplicationController());
// Get.offAndToNamed(AppRoutes.Application);
}
getUserInfo(IntegralEntity userInfo) async { await saveProfile(userInfo);
await setToken(userInfo.token);
await saveProfile(userInfo); // token = StorageService.to.getString(STORAGE_USER_TOKEN_KEY);
// token = StorageService.to.getString(STORAGE_USER_TOKEN_KEY); // if (token.isNotEmpty) {
// return;
// }
// IntegralEntity userInfo = await UserAPI.getUserIntegral();
// if (token.isNotEmpty) { // print("$userInfo");
// return;
// }
// IntegralEntity userInfo = await UserAPI.getUserIntegral();
// print("$userInfo"); // var info = await UserAPI.getUserIntegral();
// if (token.isEmpty) {
// var info = await UserAPI.getUserIntegral(); // }
// if (token.isEmpty) { }
// } @override
} dispose() {
subscription?.cancel();
super.dispose();
}
@override // 保存 token
dispose() { Future<void> setToken(String value) async {
subscription?.cancel(); await StorageService.to.setString(STORAGE_USER_TOKEN_KEY, value);
super.dispose(); token = value;
} }
// 保存 token // 获取 profile
Future<void> setToken(String value) async { Future<void> getProfile() async {
await StorageService.to.setString(STORAGE_USER_TOKEN_KEY, value); // print("objectobjectobjectobjectobjectobject");
token = value; // if (token.isEmpty) return;
} // var result = await UserAPI.profile();
// _profile(result);
// _isLogin.value = true;
// StorageService.to.setString(STORAGE_USER_PROFILE_KEY, jsonEncode(result));
}
// 获取 profile // 保存 profile
Future<void> getProfile() async { Future<void> saveProfile(IntegralEntity profile) async {
// print("objectobjectobjectobjectobjectobject"); _profile.value = profile;
// if (token.isEmpty) return; var copiedMap = Map.from(profile.toMap());
// var result = await UserAPI.profile();
// _profile(result);
// _isLogin.value = true;
// StorageService.to.setString(STORAGE_USER_PROFILE_KEY, jsonEncode(result));
}
// 保存 profile copiedMap.update("expireTime", (value) => value?.toIso8601String());
Future<void> saveProfile(IntegralEntity profile) async {
_profile.value = profile;
var copiedMap = Map.from(profile.toMap());
copiedMap.update("expireTime", (value) => value?.toIso8601String()); StorageService.to
.setString(STORAGE_USER_PROFILE_KEY, jsonEncode(copiedMap));
}
StorageService.to // // 保存 profile
.setString(STORAGE_USER_PROFILE_KEY, jsonEncode(copiedMap)); // Future<void> saveProfile(UserLoginResponseEntity profile) async {
} // _isLogin.value = true;
// StorageService.to.setString(STORAGE_USER_PROFILE_KEY, jsonEncode(profile));
// }
// // 保存 profile // 注销
// Future<void> saveProfile(UserLoginResponseEntity profile) async { Future<void> onLogout() async {
// _isLogin.value = true; // if (_isLogin.value) await UserAPI.logout();
// StorageService.to.setString(STORAGE_USER_PROFILE_KEY, jsonEncode(profile)); await StorageService.to.remove(STORAGE_USER_TOKEN_KEY);
// } _isLogin.value = false;
token = '';
// 注销 saveProfile(IntegralEntity(
Future<void> onLogout() async { id: '', username: '', token: '', expireTime: null, integral: 0));
// if (_isLogin.value) await UserAPI.logout(); Get.toNamed(AppRoutes.Application);
await StorageService.to.remove(STORAGE_USER_TOKEN_KEY);
_isLogin.value = false;
token = '';
saveProfile(IntegralEntity(
id: '', username: '', token: '', expireTime: null, integral: 0));
Get.toNamed(AppRoutes.Application);
} }
} }
...@@ -48,9 +48,19 @@ class AndroidPayListController extends GetxController { ...@@ -48,9 +48,19 @@ class AndroidPayListController extends GetxController {
@override @override
void onInit() async { void onInit() async {
super.onInit(); super.onInit();
await initializedPlugins();
await _getProduct(); try {
await initializedPlugins();
EasyLoading.show(status: "正在获取套餐中...");
await _getProduct();
state.loadingList = false;
EasyLoading.dismiss();
} catch(e){
state.loadingList = false;
}
// EasyLoading.dismiss(); // EasyLoading.dismiss();
// await initializedPlugins(); // await initializedPlugins();
// new 对象 // new 对象
...@@ -110,6 +120,9 @@ class AndroidPayListController extends GetxController { ...@@ -110,6 +120,9 @@ class AndroidPayListController extends GetxController {
// print(goodsList); // print(goodsList);
state.items.addAll(goodsList); state.items.addAll(goodsList);
EasyLoading.dismiss(); EasyLoading.dismiss();
if(goodsList.isNotEmpty) {
state.setSelectedItem = goodsList.first;
}
} catch (e) { } catch (e) {
print(e); print(e);
EasyLoading.dismiss(); EasyLoading.dismiss();
...@@ -130,13 +143,12 @@ class AndroidPayListController extends GetxController { ...@@ -130,13 +143,12 @@ class AndroidPayListController extends GetxController {
} }
void requestPurchase() async { void requestPurchase() async {
Vibrate.feedback(FeedbackType.selection); Vibrate.feedback(FeedbackType.impact);
// print("${item.productId}"); // print("${item.productId}");
EasyLoading.show(status: '支付中...'); EasyLoading.show(status: '支付中...');
// List<String> newList = list.where((element) => element.compareTo('b') > 0).toList(); // ['c', 'd'] // List<String> newList = list.where((element) => element.compareTo('b') > 0).toList(); // ['c', 'd']
final actSelected = state.items final actSelected = state.selectedItem;
.firstWhere((element) => element.appleProductId == state.selected);
String orderInfo = await NewsAPI.doPay({ String orderInfo = await NewsAPI.doPay({
"goodsId": "${actSelected.id}", "goodsId": "${actSelected.id}",
......
...@@ -2,7 +2,19 @@ import 'package:chart/common/entities/good.dart'; ...@@ -2,7 +2,19 @@ import 'package:chart/common/entities/good.dart';
import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart'; import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../../../common/entities/good.dart';
class AndroidPayListState { class AndroidPayListState {
final _loadingList = false.obs;
set loadingList(value) => _loadingList.value = value;
get loadingList => _loadingList.value;
final _loading = false.obs;
set loading(value) => _loading.value = value;
get loading => _loading.value;
// title // title
final _title = "".obs; final _title = "".obs;
set title(value) => this._title.value = value; set title(value) => this._title.value = value;
...@@ -12,5 +24,9 @@ class AndroidPayListState { ...@@ -12,5 +24,9 @@ class AndroidPayListState {
set selected(value) => _selected.value = value; set selected(value) => _selected.value = value;
get selected => _selected.value; get selected => _selected.value;
final _selectedItem = GoodEntity(id: 0).obs;
set setSelectedItem(value) => _selectedItem.value = value;
get selectedItem => _selectedItem.value;
RxList<GoodEntity> items = <GoodEntity>[].obs; RxList<GoodEntity> items = <GoodEntity>[].obs;
} }
...@@ -20,47 +20,48 @@ class AndroidPayListPage extends GetView<AndroidPayListController> { ...@@ -20,47 +20,48 @@ class AndroidPayListPage extends GetView<AndroidPayListController> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final c = Get.put(AndroidPayListController()); final c = Get.put(AndroidPayListController());
return Scaffold( return Container(
// appBar: transparentAppBar( // color: Colors.amber,
// title: Text( height: double.infinity,
// "套餐选择", // width: Get.width,
// style: TextStyle( decoration: BoxDecoration(
// color: AppColors.primaryElementText, image: DecorationImage(
// fontFamily: 'Montserrat', image: Image.asset("assets/images/background.png").image,
// fontSize: 18, fit: BoxFit.cover),
// fontWeight: FontWeight.w600, ),
// ), child: Scaffold(
// ), appBar: AppBar(
// leading: IconButton( elevation: 0,
// tooltip: '返回上一页', backgroundColor: const Color.fromARGB(0, 0, 0, 0),
// icon: const Icon( title: Text("订阅中心"),
// Icons.arrow_back, // actions: <Widget>[
// color: AppColors.primaryElementText, // GestureDetector(
// ), // onTap: () {
// onPressed: () async { // // controller.restorePurchases();
// // Get.back(); // },
// // Get.offAll(ApplicationPage()); // child: Container(
// // await Get.off(ApplicationPage()); // padding: EdgeInsets.only(right: 10),
// // Get.toNamed(AppRoutes.Application); // child: Center(
// child: Text("恢复购买"),
// Get.back(); // )),
// // await Get.toNamed(); // )
// // Navigator.of(context).pop(); // ],
// //_nextPage(-1);
// },
// ),
// ),
// _buildView
body: Container(
width: double.infinity,
height: double.infinity,
// padding: EdgeInsets.symmetric(horizontal: 20),
decoration: BoxDecoration(
image: DecorationImage(
image: Image.asset("assets/images/bg1.png").image,
fit: BoxFit.cover),
), ),
child: _buildView()), backgroundColor: const Color.fromARGB(0, 0, 0, 0),
body: _buildView()
// Container(
// // child: Text("12312"),
// // width: double.infinity,
// // height: double.infinity,
// // // padding: EdgeInsets.symmetric(horizontal: 20),
// // decoration: BoxDecoration(
// // image: DecorationImage(
// // image: Image.asset("assets/images/bg1.png").image,
// // fit: BoxFit.cover),
// // ),
// // child:
// ),
),
); );
} }
} }
...@@ -388,11 +388,23 @@ class HomeController extends GetxController with SingleGetTickerProviderMixin { ...@@ -388,11 +388,23 @@ class HomeController extends GetxController with SingleGetTickerProviderMixin {
} catch (e) {} } catch (e) {}
} }
virtualPay() { bool get isLogin => UserStore.to.isLogin;
if (GetPlatform.isAndroid) {
Get.toNamed(AppRoutes.AN_PAY_LIST); virtualPay() async {
if (!isLogin) {
//只有Android才会存在登录情况
if (GetPlatform.isAndroid) {
var rev = await Get.toNamed(AppRoutes.SIGN_IN);
if (isLogin) {
virtualPay();
}
}
} else { } else {
Get.toNamed(AppRoutes.PAY_LIST); if (GetPlatform.isAndroid) {
Get.toNamed(AppRoutes.AN_PAY_LIST);
} else {
Get.toNamed(AppRoutes.PAY_LIST);
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment