account_manage_page.dart 3.0 KB

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