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.
451 lines
14 KiB
451 lines
14 KiB
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:voitrans/data/models/goods.dart';
|
|
import '../../../data/models/user_Info.dart';
|
|
import '../controllers/goodstrade_controller.dart';
|
|
|
|
class GoodstradeView extends GetView<GoodstradeController> {
|
|
const GoodstradeView({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
return Scaffold(
|
|
backgroundColor: isDarkMode ? Colors.black : Colors.grey[50],
|
|
appBar: AppBar(
|
|
backgroundColor: isDarkMode ? Colors.black : Colors.white,
|
|
elevation: 0.5,
|
|
title: Text(
|
|
'simultaneousTranslation'.tr,
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
),
|
|
),
|
|
centerTitle: true,
|
|
),
|
|
body: Obx(() {
|
|
// 访问刷新信号以建立依赖关系:用户信息变化时触发重建
|
|
final _ = User.refreshTick.value;
|
|
if (controller.loading.value) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
if (controller.error.isNotEmpty) {
|
|
return Center(child: Text(controller.error.value));
|
|
}
|
|
return ListView.separated(
|
|
padding: EdgeInsets.all(16.w),
|
|
itemCount: controller.items.length + 4,
|
|
separatorBuilder: (_, __) => SizedBox(height: 12.h),
|
|
itemBuilder: (_, index) {
|
|
if (index == 0) {
|
|
return _buildHeader(isDarkMode);
|
|
}
|
|
if (index == 1) {
|
|
return _buildUsageCard(isDarkMode);
|
|
}
|
|
final itemIndex = index - 2;
|
|
if (itemIndex < controller.items.length) {
|
|
final item = controller.items[itemIndex];
|
|
return _buildCard(item, isDarkMode);
|
|
}
|
|
if (index == controller.items.length + 2) {
|
|
return _buildFeaturesSection(isDarkMode);
|
|
}
|
|
return _buildFooterSection(isDarkMode);
|
|
},
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeader(bool isDarkMode) {
|
|
return Container(
|
|
padding: EdgeInsets.all(16.w),
|
|
decoration: BoxDecoration(
|
|
color: isDarkMode ? Colors.grey[900] : Colors.white,
|
|
borderRadius: BorderRadius.circular(12.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: isDarkMode
|
|
? Colors.black.withOpacity(0.2)
|
|
: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
width: 44.w,
|
|
height: 44.w,
|
|
decoration: BoxDecoration(
|
|
color: isDarkMode
|
|
? Colors.indigo[900]!.withOpacity(0.3)
|
|
: Colors.indigo[100]!,
|
|
borderRadius: BorderRadius.circular(22.r),
|
|
),
|
|
child: Icon(Icons.translate,
|
|
color: isDarkMode ? Colors.indigo[300]! : Colors.indigo[600]!),
|
|
),
|
|
SizedBox(width: 12.w),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'翻译功能',
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
fontWeight: FontWeight.w700,
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
),
|
|
),
|
|
SizedBox(height: 6.h),
|
|
Text(
|
|
'多语种实时同传与文本翻译,低延时语音播报。',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white70 : Colors.grey[700],
|
|
),
|
|
),
|
|
SizedBox(height: 4.h),
|
|
Text(
|
|
'适用于出行、商务、演讲与教学等场景。',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white70 : Colors.grey[700],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildUsageCard(bool isDarkMode) {
|
|
int totalAi = 0;
|
|
int remainAi = 0;
|
|
if (User.isLoggedIn()) {
|
|
final u = User.instance;
|
|
totalAi = u.tradetotalintegral;
|
|
remainAi = u.tradeintegral;
|
|
}
|
|
final progress = (totalAi > 0) ? (remainAi / totalAi).clamp(0.0, 1.0) : 0.0;
|
|
|
|
return Container(
|
|
padding: EdgeInsets.all(16.w),
|
|
decoration: BoxDecoration(
|
|
color: isDarkMode ? Colors.grey[900] : Colors.white,
|
|
borderRadius: BorderRadius.circular(12.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: isDarkMode
|
|
? Colors.black.withOpacity(0.2)
|
|
: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(Icons.timeline,
|
|
color: isDarkMode ? Colors.blue[300]! : Colors.blue[600]!),
|
|
SizedBox(width: 8.w),
|
|
Text(
|
|
'剩余额度',
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 12.h),
|
|
LinearProgressIndicator(
|
|
value: progress,
|
|
minHeight: 8.h,
|
|
backgroundColor: isDarkMode ? Colors.grey[800] : Colors.grey[300],
|
|
valueColor: AlwaysStoppedAnimation<Color>(
|
|
isDarkMode ? Colors.blue[300]! : Colors.blue[600]!),
|
|
),
|
|
SizedBox(height: 8.h),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'总次数:$totalAi',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white70 : Colors.grey[700],
|
|
),
|
|
),
|
|
Text(
|
|
'剩余:$remainAi',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white70 : Colors.grey[700],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildCard(DBGoods item, bool isDarkMode) {
|
|
return Container(
|
|
padding: EdgeInsets.all(16.w),
|
|
decoration: BoxDecoration(
|
|
color: isDarkMode ? Colors.grey[900] : Colors.white,
|
|
borderRadius: BorderRadius.circular(12.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: isDarkMode
|
|
? Colors.black.withOpacity(0.2)
|
|
: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 42.w,
|
|
height: 42.w,
|
|
decoration: BoxDecoration(
|
|
color: isDarkMode
|
|
? Colors.indigo[900]!.withOpacity(0.3)
|
|
: Colors.indigo[100]!,
|
|
borderRadius: BorderRadius.circular(21.r),
|
|
),
|
|
child: Icon(Icons.translate,
|
|
color: isDarkMode ? Colors.indigo[300]! : Colors.indigo[600]!),
|
|
),
|
|
SizedBox(width: 12.w),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(item.name,
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
)),
|
|
SizedBox(height: 4.h),
|
|
Text(item.desc,
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white70 : Colors.grey[600],
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Text('¥${item.price.toStringAsFixed(2)}',
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
)),
|
|
SizedBox(height: 8.h),
|
|
GestureDetector(
|
|
onTap: () => controller.purchase(item),
|
|
child: Container(
|
|
padding:
|
|
EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
|
|
decoration: BoxDecoration(
|
|
color: Colors.blue[600],
|
|
borderRadius: BorderRadius.circular(20.r),
|
|
),
|
|
child: Text(
|
|
'购买',
|
|
style: TextStyle(fontSize: 12.sp, color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildFeaturesSection(bool isDarkMode) {
|
|
final textColor = isDarkMode ? Colors.white : Colors.black;
|
|
final subColor = isDarkMode ? Colors.white70 : Colors.grey[700];
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'功能说明',
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: textColor,
|
|
),
|
|
),
|
|
SizedBox(height: 10.h),
|
|
Wrap(
|
|
spacing: 12.w,
|
|
runSpacing: 12.h,
|
|
alignment: WrapAlignment.start,
|
|
crossAxisAlignment: WrapCrossAlignment.start,
|
|
children: [
|
|
_buildFeatureCard(
|
|
isDarkMode,
|
|
icon: Icons.translate,
|
|
title: '实时同传',
|
|
lines: ['中英互译', '低延时语音播报'],
|
|
colorSeed: Colors.indigo,
|
|
),
|
|
_buildFeatureCard(
|
|
isDarkMode,
|
|
icon: Icons.text_snippet,
|
|
title: '文本翻译',
|
|
lines: ['多语种文本翻译', '术语优化与语境保持'],
|
|
colorSeed: Colors.blue,
|
|
),
|
|
_buildFeatureCard(
|
|
isDarkMode,
|
|
icon: Icons.library_books,
|
|
title: '场景词库',
|
|
lines: ['旅游/商务/生活词库', '专属词汇记忆'],
|
|
colorSeed: Colors.teal,
|
|
),
|
|
_buildFeatureCard(
|
|
isDarkMode,
|
|
icon: Icons.subtitles,
|
|
title: '字幕显示',
|
|
lines: ['对话字幕/大字模式', '颜色高对比度'],
|
|
colorSeed: Colors.purple,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 12.h),
|
|
Text(
|
|
'翻译效果受麦克风、网络时延与环境噪声影响,具体以实际表现为准。',
|
|
style: TextStyle(fontSize: 12.sp, color: subColor),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildFeatureCard(
|
|
bool isDarkMode, {
|
|
required IconData icon,
|
|
required String title,
|
|
required List<String> lines,
|
|
required MaterialColor colorSeed,
|
|
}) {
|
|
final bgColor = isDarkMode ? Colors.grey[900] : Colors.white;
|
|
final mainColor = isDarkMode ? colorSeed[300]! : colorSeed[600]!;
|
|
final subColor = isDarkMode ? Colors.white70 : Colors.grey[700];
|
|
final width = (Get.width - 16.w * 2 - 12.w) / 2;
|
|
return Container(
|
|
width: width,
|
|
padding: EdgeInsets.all(12.w),
|
|
decoration: BoxDecoration(
|
|
color: bgColor,
|
|
borderRadius: BorderRadius.circular(12.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: isDarkMode
|
|
? Colors.black.withOpacity(0.2)
|
|
: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
width: 36.w,
|
|
height: 36.w,
|
|
decoration: BoxDecoration(
|
|
color: isDarkMode
|
|
? mainColor.withOpacity(0.25)
|
|
: mainColor.withOpacity(0.15),
|
|
borderRadius: BorderRadius.circular(18.r),
|
|
),
|
|
child: Icon(icon, color: mainColor),
|
|
),
|
|
SizedBox(width: 8.w),
|
|
Expanded(
|
|
child: Text(
|
|
title,
|
|
style: TextStyle(
|
|
fontSize: 14.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 8.h),
|
|
...lines.map((l) => Padding(
|
|
padding: EdgeInsets.only(bottom: 4.h),
|
|
child:
|
|
Text(l, style: TextStyle(fontSize: 12.sp, color: subColor)),
|
|
)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildFooterSection(bool isDarkMode) {
|
|
final subColor = isDarkMode ? Colors.white60 : Colors.grey[600];
|
|
return Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 12.h),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: Divider(color: isDarkMode ? Colors.white24 : Colors.black12),
|
|
),
|
|
SizedBox(height: 8.h),
|
|
Text(
|
|
'应用名称:VoiTrans · 服务提供:VoiTrans',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 11.sp, color: subColor),
|
|
),
|
|
SizedBox(height: 4.h),
|
|
Text(
|
|
'更多信息请前往 设置 > 关于 查看',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 11.sp, color: subColor),
|
|
),
|
|
SizedBox(height: 4.h),
|
|
Text(
|
|
'© 2025 VoiTrans',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 11.sp, color: subColor),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|