qhd-prevention-flutter/lib/pages/home/userInfo_page.dart

112 lines
3.0 KiB
Dart
Raw Normal View History

2025-07-03 09:45:15 +08:00
import 'package:flutter/material.dart';
2025-08-20 09:56:31 +08:00
import 'package:qhd_prevention/pages/http/ApiService.dart';
2025-07-03 09:45:15 +08:00
import 'package:qhd_prevention/pages/my_appbar.dart';
2025-08-20 09:56:31 +08:00
2025-07-03 09:45:15 +08:00
class UserinfoPage extends StatefulWidget {
const UserinfoPage({super.key});
@override
State<UserinfoPage> createState() => _UserinfoPageState();
}
class _UserinfoPageState extends State<UserinfoPage> {
2025-08-20 09:56:31 +08:00
Map<String, dynamic> user = {};
@override
void initState() {
// TODO: implement initState
super.initState();
_getUserInfo();
}
Future<void> _getUserInfo() async {
try {
final result = await ApiService.getUserInfo();
if (result['result'] == 'success') {
setState(() {
user= result['data'];
});
}else{
_showMessage('加载数据失败');
}
} catch (e) {
// 出错时可以 Toast 或者在页面上显示错误状态
print('加载数据失败:$e');
}
}
2025-07-03 09:45:15 +08:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppbar(title: "人员信息"),
body: SafeArea(
child: ListView(
children: [
2025-08-20 09:56:31 +08:00
_userItemCell("姓名", user["name"]??"", false),
Divider(height: 1),
_userItemCell("电话", user["phone"]??"", false),
Divider(height: 1),
_userItemCell("部门", user["departmentName"]??"", false),
Divider(height: 1),
_userItemCell("岗位", user["postName"]??"", true),
Divider(height: 1),
// _userItemCell("人员类型", user["PERSONNEL_TYPE_NAME"]??"", false),
// Divider(height: 1),
// _userItemCell("入职时间", user["ENTRY_DATE"]??"", false),
// Divider(height: 1),
// _userItemCell("工种", user["TYPE_OF_WORK_NAME"]??"", false),
2025-07-03 09:45:15 +08:00
],
),
),
);
}
Widget _userItemCell(final String title, final String detail, bool isLast) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 15),
decoration:
2025-08-20 09:56:31 +08:00
isLast
? const BoxDecoration(
color: Colors.white,
border: Border(
bottom: BorderSide(color: Colors.grey, width: 0),
),
)
: const BoxDecoration(
color: Colors.white,
border: Border(
bottom: BorderSide(color: Colors.grey, width: 0.5),
),
),
2025-07-03 09:45:15 +08:00
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
2025-08-20 09:56:31 +08:00
Text(title, style: const TextStyle(fontSize: 16, )),
2025-07-03 09:45:15 +08:00
Flexible(
child: Text(
detail,
2025-08-20 09:56:31 +08:00
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500,color: Colors.grey),
2025-07-03 09:45:15 +08:00
textAlign: TextAlign.right,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
],
),
);
}
2025-08-20 09:56:31 +08:00
void _showMessage(String msg) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
}
2025-07-03 09:45:15 +08:00
}