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.
497 lines
16 KiB
497 lines
16 KiB
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
|
import '../../../data/models/goods.dart';
|
|
import '../../../data/models/user_Info.dart';
|
|
import '../controllers/goodsai_controller.dart';
|
|
import '../utils/goods_i18n.dart';
|
|
import 'widgets/goods_footer_section.dart';
|
|
|
|
class GoodsaiView extends GetView<GoodsaiController> {
|
|
const GoodsaiView({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(
|
|
'aiFunction'.tr,
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
),
|
|
),
|
|
centerTitle: true,
|
|
),
|
|
body: SafeArea(
|
|
top: false,
|
|
child: Obx(() {
|
|
// 访问刷新信号以建立依赖关系:用户信息变化时触发重建
|
|
final _ = User.refreshTick.value;
|
|
Widget content;
|
|
if (controller.loading.value) {
|
|
content = const Center(child: CircularProgressIndicator());
|
|
} else if (controller.error.isNotEmpty) {
|
|
content = Center(child: Text(controller.error.value));
|
|
} else {
|
|
content = ListView(
|
|
padding: EdgeInsets.all(16.w),
|
|
children: [
|
|
_buildHeader(isDarkMode),
|
|
SizedBox(height: 12.h),
|
|
_buildUsageCard(isDarkMode),
|
|
SizedBox(height: 16.h),
|
|
Text(
|
|
'availablePackages'.tr,
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
),
|
|
),
|
|
SizedBox(height: 8.h),
|
|
...controller.items.map((item) => Padding(
|
|
padding: EdgeInsets.only(bottom: 12.h),
|
|
child: _buildCard(item, isDarkMode),
|
|
)),
|
|
SizedBox(height: 16.h),
|
|
_buildFeaturesSection(isDarkMode),
|
|
SizedBox(height: 16.h),
|
|
GoodsFooterSection(isDarkMode: isDarkMode),
|
|
],
|
|
);
|
|
}
|
|
return Stack(
|
|
children: [
|
|
content,
|
|
if (controller.isPaying.value)
|
|
Positioned.fill(
|
|
child: AbsorbPointer(
|
|
absorbing: true,
|
|
child: Container(
|
|
color: Colors.black.withOpacity(0.35),
|
|
child: const Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
|
|
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.smart_toy,
|
|
color: isDarkMode ? Colors.indigo[300]! : Colors.indigo[600]!),
|
|
),
|
|
SizedBox(width: 12.w),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'aiFunction'.tr,
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
fontWeight: FontWeight.w700,
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
),
|
|
),
|
|
SizedBox(height: 6.h),
|
|
Text(
|
|
'aiHeaderDesc1'.tr,
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white70 : Colors.grey[700],
|
|
),
|
|
),
|
|
SizedBox(height: 4.h),
|
|
Text(
|
|
'aiHeaderDesc2'.tr,
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white70 : Colors.grey[700],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildUsageCard(bool isDarkMode) {
|
|
// 从 User 属性计算 aitimer 数据
|
|
int totalAi = 0;
|
|
int remainAi = 0;
|
|
if (User.isLoggedIn()) {
|
|
final u = User.instance;
|
|
totalAi = u.aichattotalintegral;
|
|
remainAi = u.aichatintegral;
|
|
}
|
|
// 进度显示为“剩余额度比例”,remain/total:
|
|
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(
|
|
'remainingQuota'.tr,
|
|
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(
|
|
'${'totalQuota'.tr}:$totalAi',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white70 : Colors.grey[700],
|
|
),
|
|
),
|
|
Text(
|
|
'${'remaining'.tr}:$remainAi',
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white70 : Colors.grey[700],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
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(
|
|
'featureDescription'.tr,
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: textColor,
|
|
),
|
|
),
|
|
SizedBox(height: 10.h),
|
|
MasonryGridView.count(
|
|
crossAxisCount: 2,
|
|
mainAxisSpacing: 12.h,
|
|
crossAxisSpacing: 12.w,
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
itemCount: 6,
|
|
itemBuilder: (context, index) {
|
|
switch (index) {
|
|
case 0:
|
|
return _buildFeatureCard(
|
|
isDarkMode,
|
|
icon: Icons.music_note,
|
|
title: 'musicAndRecommendation'.tr,
|
|
lines: [
|
|
'musicSearchPlaybackControl'.tr,
|
|
'smartPlaylistAndSimilarRecommendations'.tr,
|
|
],
|
|
colorSeed: Colors.purple,
|
|
);
|
|
case 1:
|
|
return _buildFeatureCard(
|
|
isDarkMode,
|
|
icon: Icons.navigation,
|
|
title: 'navigationAndRoutes'.tr,
|
|
lines: [
|
|
'routePlanningAndCongestionAvoidance'.tr,
|
|
'voiceBroadcastAndWaypoints'.tr,
|
|
],
|
|
colorSeed: Colors.orange,
|
|
);
|
|
case 2:
|
|
return _buildFeatureCard(
|
|
isDarkMode,
|
|
icon: Icons.wb_sunny,
|
|
title: 'weatherQuery'.tr,
|
|
lines: [
|
|
'realTimeWeatherForecast'.tr,
|
|
'clothingAdviceAndTravelReminders'.tr,
|
|
],
|
|
colorSeed: Colors.blue,
|
|
);
|
|
case 3:
|
|
return _buildFeatureCard(
|
|
isDarkMode,
|
|
icon: Icons.place,
|
|
title: 'nearbySearch'.tr,
|
|
lines: [
|
|
'poiSearchFoodGasParking'.tr,
|
|
'ratingsHoursAndDirectRoutes'.tr,
|
|
],
|
|
colorSeed: Colors.green,
|
|
);
|
|
case 4:
|
|
return _buildFeatureCard(
|
|
isDarkMode,
|
|
icon: Icons.newspaper,
|
|
title: 'newsInformation'.tr,
|
|
lines: [
|
|
'hotNewsAndTopicOverview'.tr,
|
|
'longArticleSummariesAndKeyPoints'.tr,
|
|
],
|
|
colorSeed: Colors.indigo,
|
|
);
|
|
default:
|
|
return _buildFeatureCard(
|
|
isDarkMode,
|
|
icon: Icons.call,
|
|
title: 'communicationAssistant'.tr,
|
|
lines: [
|
|
'helpCallAndSMS'.tr,
|
|
'templatedMessagesAndScheduleReminders'.tr,
|
|
],
|
|
colorSeed: Colors.teal,
|
|
);
|
|
}
|
|
},
|
|
),
|
|
SizedBox(height: 12.h),
|
|
Text(
|
|
'aiDisclaimer'.tr,
|
|
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];
|
|
return Container(
|
|
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,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 8.h),
|
|
...lines.map((line) => Padding(
|
|
padding: EdgeInsets.only(bottom: 4.h),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(Icons.check_circle, color: mainColor, size: 14.sp),
|
|
SizedBox(width: 6.w),
|
|
Expanded(
|
|
child: Text(
|
|
line,
|
|
style: TextStyle(fontSize: 12.sp, color: subColor),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
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.teal[900]!.withOpacity(0.3)
|
|
: Colors.teal[100]!,
|
|
borderRadius: BorderRadius.circular(21.r),
|
|
),
|
|
child: Icon(Icons.auto_awesome,
|
|
color: isDarkMode ? Colors.teal[300]! : Colors.teal[600]!),
|
|
),
|
|
SizedBox(width: 12.w),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(localizedGoodsName(item),
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: isDarkMode ? Colors.white : Colors.black,
|
|
)),
|
|
SizedBox(height: 4.h),
|
|
Text(localizedGoodsDesc(item),
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white70 : Colors.grey[600],
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Text(goodsDisplayPrice(item),
|
|
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(
|
|
'purchase'.tr,
|
|
style: TextStyle(fontSize: 12.sp, color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|