You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.4 KiB

import 'package:get/get.dart';
import '../../../routes/app_routes.dart';
class TradeItem {
final String id;
final String title;
final String description;
final double price;
final String productId;
TradeItem({
required this.id,
required this.title,
required this.description,
required this.price,
required this.productId,
});
}
class GoodstradeController extends GetxController {
final RxList<TradeItem> items = <TradeItem>[].obs;
final RxBool loading = false.obs;
final RxString error = ''.obs;
@override
void onInit() {
super.onInit();
_loadProducts();
}
Future<void> _loadProducts() async {
loading.value = true;
error.value = '';
try {
items.assignAll([
TradeItem(
id: 'trans_100',
title: '翻译包 100 分钟',
description: '实时翻译服务时长包',
price: 19.9,
productId: 'trans_100',
),
TradeItem(
id: 'trans_500',
title: '翻译包 500 分钟',
description: '更划算的翻译时长包',
price: 79.9,
productId: 'trans_500',
),
]);
} catch (e) {
error.value = e.toString();
} finally {
loading.value = false;
}
}
void purchase(TradeItem item) {
Get.toNamed(Routes.payment, arguments: {
'productId': item.productId,
'amount': item.price,
'description': item.title,
});
}
}