account_manage_page.dart 2.9 KB

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