import 'package:flutter/material.dart'; import 'package:qhd_prevention/customWidget/toast_util.dart'; import 'package:qhd_prevention/pages/my_appbar.dart'; import 'package:qhd_prevention/services/SessionService.dart'; import 'package:qhd_prevention/tools/tools.dart'; import '../../http/ApiService.dart'; class UserinfoPage extends StatefulWidget { const UserinfoPage({super.key}); @override State createState() => _UserinfoPageState(); } class _UserinfoPageState extends State { Map user = {}; @override void initState() { // TODO: implement initState super.initState(); _getUserInfo(); } Future _getUserInfo() async { try { LoadingDialogHelper.show(); // final result = await BasicInfoApi.getUserMessage(SessionService.instance.accountId ?? ""); final result = await AuthApi.getUserData(); LoadingDialogHelper.hide(); if (result['success']) { setState(() { user= result['data']; }); }else{ ToastUtil.showNormal(context, "加载数据失败"); // _showMessage('加载数据失败'); } } catch (e) { LoadingDialogHelper.hide(); // 出错时可以 Toast 或者在页面上显示错误状态 print('加载数据失败:$e'); } } @override Widget build(BuildContext context) { return Scaffold( appBar: MyAppbar(title: "人员信息"), body: SafeArea( child: ListView( children: [ _userItemCell("姓名", user["name"]??"", false), Divider(height: 1), _userItemCell("手机号", user["phone"]??"", false), Divider(height: 1), _userItemCell("部门", user["departmentName"]??"", false), Divider(height: 1), _userItemCell("职务", user["postName"]??"", false), Divider(height: 1), _userItemCell("职务级别", user["rankLevelName"]??"", false), Divider(height: 1), ], ), ), ); } Widget _userItemCell(final String title, final String detail, bool isLast) { return Container( padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 15), decoration: 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), ), ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text(title, style: const TextStyle(fontSize: 16, )), Flexible( child: Text( detail, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500,color: Colors.grey), textAlign: TextAlign.right, maxLines: 2, overflow: TextOverflow.ellipsis, ), ), ], ), ); } void _showMessage(String msg) { ToastUtil.showNormal(context, msg); } }