384 lines
14 KiB
Dart
384 lines
14 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
|
||
import '../../apis/app.dart';
|
||
import '../../components/appbar.dart';
|
||
|
||
class MessageDetailPage extends StatefulWidget {
|
||
final dynamic id; // 修改为dynamic类型,因为可能是String或int
|
||
|
||
const MessageDetailPage({super.key, required this.id});
|
||
|
||
@override
|
||
_MessageDetailPageState createState() => _MessageDetailPageState();
|
||
}
|
||
|
||
class _MessageDetailPageState extends State<MessageDetailPage> {
|
||
Map<String, dynamic> message = {};
|
||
bool isLoading = true;
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_disableGestures();
|
||
_fetchMessageDetail();
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
_enableGestures();
|
||
super.dispose();
|
||
}
|
||
|
||
Future<void> _disableGestures() async {
|
||
// 禁用系统导航手势
|
||
await SystemChannels.platform.invokeMethod('SystemNavigator.setNavigationGestureEnabled', false);
|
||
|
||
// 设置系统UI覆盖样式
|
||
SystemChrome.setSystemUIOverlayStyle(
|
||
const SystemUiOverlayStyle(
|
||
systemNavigationBarColor: Colors.black,
|
||
statusBarColor: Colors.transparent,
|
||
),
|
||
);
|
||
|
||
// 设置首选方向为竖直方向
|
||
await SystemChrome.setPreferredOrientations([
|
||
DeviceOrientation.portraitUp,
|
||
]);
|
||
|
||
// 设置系统UI标志
|
||
await SystemChrome.setEnabledSystemUIMode(
|
||
SystemUiMode.edgeToEdge,
|
||
overlays: [SystemUiOverlay.top],
|
||
);
|
||
}
|
||
|
||
Future<void> _enableGestures() async {
|
||
// 重新启用系统导航手势
|
||
await SystemChannels.platform.invokeMethod('SystemNavigator.setNavigationGestureEnabled', true);
|
||
|
||
// 恢复系统UI覆盖样式
|
||
SystemChrome.setSystemUIOverlayStyle(
|
||
const SystemUiOverlayStyle(
|
||
systemNavigationBarColor: Colors.transparent,
|
||
statusBarColor: Colors.transparent,
|
||
),
|
||
);
|
||
|
||
// 恢复所有方向
|
||
await SystemChrome.setPreferredOrientations(DeviceOrientation.values);
|
||
|
||
// 恢复系统UI
|
||
await SystemChrome.setEnabledSystemUIMode(
|
||
SystemUiMode.edgeToEdge,
|
||
overlays: SystemUiOverlay.values,
|
||
);
|
||
}
|
||
|
||
Future<void> _fetchMessageDetail() async {
|
||
try {
|
||
// 确保id是整数类型
|
||
final messageId = widget.id is String ? int.parse(widget.id) : widget.id;
|
||
final res = await userApi.getMessageDetail(messageId);
|
||
|
||
if (!mounted) return;
|
||
|
||
if (res['code'] == 200) {
|
||
setState(() {
|
||
message = res['data'] ?? {};
|
||
isLoading = false;
|
||
});
|
||
} else {
|
||
throw Exception(res['msg'] ?? '获取消息详情失败');
|
||
}
|
||
} catch (e) {
|
||
if (!mounted) return;
|
||
setState(() {
|
||
isLoading = false;
|
||
});
|
||
ScaffoldMessenger.of(context).showSnackBar(
|
||
SnackBar(
|
||
content: Text('获取消息详情失败: ${e.toString()}'),
|
||
backgroundColor: Colors.red,
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
// 在此处禁用系统返回手势
|
||
return PopScope(
|
||
canPop: false,
|
||
onPopInvoked: (didPop) {
|
||
if (!didPop) {
|
||
Navigator.pop(context, true);
|
||
}
|
||
},
|
||
child: Scaffold(
|
||
appBar: CustomAppBar(
|
||
title: '消息详情',
|
||
onBackPressed: () {
|
||
Navigator.pop(context, true);
|
||
},
|
||
),
|
||
body: Container(
|
||
decoration: const BoxDecoration(color: Color(0xff0C0C16)),
|
||
child: isLoading
|
||
? const Center(child: CircularProgressIndicator())
|
||
: message.isEmpty
|
||
? const Center(
|
||
child: Text(
|
||
'暂无消息详情',
|
||
style: TextStyle(color: Colors.white),
|
||
),
|
||
)
|
||
: Padding(
|
||
padding: const EdgeInsets.all(16.0),
|
||
child: Column(
|
||
children: [
|
||
Center(
|
||
child: Text(
|
||
message['createTime'] ?? '',
|
||
style: const TextStyle(
|
||
fontSize: 14,
|
||
color: Colors.grey,
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(height: 20),
|
||
Container(
|
||
padding: const EdgeInsets.all(16.0),
|
||
width: MediaQuery.of(context).size.width,
|
||
decoration: BoxDecoration(
|
||
color: const Color(0xFF1F212E),
|
||
borderRadius: BorderRadius.circular(8.0),
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
_getMessageType(message['type']?.toString() ?? ''),
|
||
style: const TextStyle(
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.bold,
|
||
color: Colors.white,
|
||
),
|
||
),
|
||
const SizedBox(height: 8),
|
||
Text(
|
||
message['detail']?.toString() ?? '',
|
||
style: const TextStyle(
|
||
fontSize: 12,
|
||
color: Color(0xFFC1C1C1),
|
||
),
|
||
),
|
||
const SizedBox(height: 16),
|
||
if (message['type']?.toString() == '5') ...[
|
||
const Opacity(
|
||
opacity: 0.3,
|
||
child: Divider(color: Colors.white, height: 1),
|
||
),
|
||
const SizedBox(height: 16),
|
||
Center(
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
Navigator.pushNamedAndRemoveUntil(
|
||
context,
|
||
'/tabs',
|
||
(route) => false,
|
||
arguments: {'initialIndex': 1},
|
||
);
|
||
},
|
||
child: const Text(
|
||
'重新发布作品',
|
||
style: TextStyle(
|
||
color: Color(0xFF428DFD),
|
||
fontSize: 14,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
if (message['type']?.toString() == '4') ...[
|
||
const Opacity(
|
||
opacity: 0.3,
|
||
child: Divider(color: Colors.white, height: 1),
|
||
),
|
||
const SizedBox(height: 16),
|
||
Center(
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(
|
||
builder: (context) => const ReturnMoneyPage(),
|
||
),
|
||
);
|
||
},
|
||
child: const Text(
|
||
'查看退款详情',
|
||
style: TextStyle(
|
||
color: Color(0xFF428DFD),
|
||
fontSize: 14,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
String _getMessageType(String type) {
|
||
switch (type) {
|
||
case '3':
|
||
case '5':
|
||
return '审核消息';
|
||
case '4':
|
||
return '退款消息';
|
||
default:
|
||
return '系统消息';
|
||
}
|
||
}
|
||
}
|
||
|
||
class ReturnMoneyPage extends StatefulWidget {
|
||
const ReturnMoneyPage({super.key});
|
||
|
||
@override
|
||
State<ReturnMoneyPage> createState() => _ReturnMoneyPageState();
|
||
}
|
||
|
||
class _ReturnMoneyPageState extends State<ReturnMoneyPage> {
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
// 禁用系统导航手势
|
||
SystemChannels.platform.invokeMethod('SystemNavigator.setNavigationGestureEnabled', false);
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
// 重新启用系统导航手势
|
||
SystemChannels.platform.invokeMethod('SystemNavigator.setNavigationGestureEnabled', true);
|
||
super.dispose();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return PopScope(
|
||
canPop: false,
|
||
onPopInvoked: (didPop) {
|
||
if (!didPop) {
|
||
Navigator.pop(context);
|
||
}
|
||
},
|
||
child: Scaffold(
|
||
appBar: const CustomAppBar(title: '退款成功'),
|
||
body: Container(
|
||
padding: const EdgeInsets.all(10),
|
||
color: const Color(0xFF0C0C16),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
// 第一行:左侧图片 + 纵向展示单元信息
|
||
Container(
|
||
color: const Color(0xFF1F212E),
|
||
padding: const EdgeInsets.all(12),
|
||
child: Column(
|
||
children: [
|
||
Row(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Image.asset(
|
||
'images/item_pic.png',
|
||
width: 60,
|
||
height: 83,
|
||
),
|
||
const SizedBox(width: 8),
|
||
Expanded(
|
||
child: Container(
|
||
height: 83,
|
||
child: const Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
"展示单元",
|
||
style: TextStyle(
|
||
fontSize: 14, color: Colors.white),
|
||
),
|
||
Text(
|
||
"展示时间:",
|
||
style: TextStyle(
|
||
fontSize: 12, color: Color(0xffC1C1C1)),
|
||
),
|
||
Text(
|
||
"展示位置:",
|
||
style: TextStyle(
|
||
fontSize: 12, color: Color(0xffC1C1C1)),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 16),
|
||
// 第二行:展示剩余时间 + 退款按钮
|
||
const Column(
|
||
children: [
|
||
Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
'返回微信',
|
||
style: TextStyle(fontSize: 12, color: Colors.white),
|
||
),
|
||
Text(
|
||
'¥4.5',
|
||
style: TextStyle(
|
||
fontSize: 16, color: Color(0xffF42845)),
|
||
),
|
||
],
|
||
),
|
||
SizedBox(
|
||
height: 10,
|
||
),
|
||
Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
'退款时间',
|
||
style: TextStyle(fontSize: 12, color: Colors.white),
|
||
),
|
||
Text(
|
||
'42024-05-06 12:00:00',
|
||
style: TextStyle(fontSize: 12, color: Colors.white),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|