account_manage_page.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:lszlgl/base/base_lifecycle_state.dart';
  4. import 'package:lszlgl/base/base_state.dart';
  5. import 'package:lszlgl/model/rsp/user_rsp.dart';
  6. import 'package:lszlgl/service/user_service.dart';
  7. import 'package:lszlgl/widget/button.dart';
  8. import 'package:lszlgl/widget/card_item.dart';
  9. /// 账号管理
  10. class AccountManagePage extends StatefulWidget {
  11. const AccountManagePage({Key? key}) : super(key: key);
  12. @override
  13. State<AccountManagePage> createState() => _AccountManagePageState();
  14. }
  15. class _AccountManagePageState extends BaseLifecycleState<AccountManagePage> {
  16. UserRsp? user;
  17. void startChangePwd() {
  18. MyRouter.startChangePwd();
  19. }
  20. void onLogout() {
  21. UserService.get().logout();
  22. }
  23. @override
  24. void onInit() {
  25. user = UserService.get().getUser();
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. return myScaffold(child: buildBody());
  30. }
  31. Widget buildBody() {
  32. return Column(
  33. children: [
  34. myAppBar(title: '账号管理'),
  35. buildList(),
  36. const SizedBox(height: 32),
  37. MyButton(
  38. '退出登录',
  39. onTap: onLogout,
  40. gradient: const LinearGradient(colors: [Color(0xFF3BD2E5), Color(0xFF247AF8)]),
  41. margin: const EdgeInsets.symmetric(horizontal: 24),
  42. ),
  43. ],
  44. );
  45. }
  46. Widget buildList() {
  47. return Container(
  48. margin: const EdgeInsets.symmetric(horizontal: 14),
  49. clipBehavior: Clip.hardEdge,
  50. decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(10))),
  51. child: Column(
  52. children: [
  53. CardItemWidget(
  54. '头像',
  55. rightChild: buildAvatar(),
  56. bottomLine: true,
  57. ),
  58. CardItemWidget(
  59. '单位名称',
  60. rightText: user?.dept?.name ?? '',
  61. bottomLine: true,
  62. ),
  63. CardItemWidget(
  64. '姓名',
  65. rightText: user?.nickname ?? '',
  66. bottomLine: true,
  67. ),
  68. CardItemWidget(
  69. '账号',
  70. rightText: user?.username ?? '',
  71. bottomLine: true,
  72. ),
  73. CardItemWidget(
  74. '修改密码',
  75. trailing: Image.asset(imgItemArrowRight, height: 16),
  76. onTap: startChangePwd,
  77. ),
  78. ],
  79. ),
  80. );
  81. }
  82. Widget buildAvatar() {
  83. return Container(
  84. width: 48,
  85. height: 48,
  86. clipBehavior: Clip.antiAlias,
  87. decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(200))),
  88. child: CachedNetworkImage(
  89. fit: BoxFit.cover,
  90. imageUrl: user?.avatar ?? '',
  91. placeholder: (_, __) => const Center(child: CircularProgressIndicator()),
  92. errorWidget: (context, url, error) => const Center(child: Icon(Icons.error, color: Colors.grey)),
  93. ),
  94. );
  95. }
  96. }