Commit e44879c0 authored by skeyboy's avatar skeyboy

同步Android、iOS支付页

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