my_estate_page.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import 'package:cpt_profile/modules/change_mobile/change_mobile_page.dart';
  2. import 'package:cs_resources/generated/l10n.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:auto_route/auto_route.dart';
  6. import 'package:flutter_hooks/flutter_hooks.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:router/componentRouter/component_service_manager.dart';
  9. import 'package:router/ext/auto_router_extensions.dart';
  10. import 'package:widgets/ext/ex_widget.dart';
  11. import 'package:widgets/load_state_layout.dart';
  12. import 'package:widgets/my_appbar.dart';
  13. import 'package:widgets/my_button.dart';
  14. import 'package:widgets/widget_export.dart';
  15. import '../../router/page/profile_page_router.dart';
  16. import 'item_estate.dart';
  17. import 'item_estate_header.dart';
  18. import 'my_estate_view_model.dart';
  19. @RoutePage()
  20. class MyEstatePage extends HookConsumerWidget {
  21. const MyEstatePage({Key? key}) : super(key: key);
  22. //启动当前页面
  23. static void startInstance({BuildContext? context}) {
  24. if (context != null) {
  25. context.router.push(const MyEstatePageRoute());
  26. } else {
  27. appRouter.push(const MyEstatePageRoute());
  28. }
  29. }
  30. @override
  31. Widget build(BuildContext context, WidgetRef ref) {
  32. final viewModel = ref.watch(myEstateViewModelProvider.notifier);
  33. final state = ref.watch(myEstateViewModelProvider);
  34. useEffect(() {
  35. // 组件挂载时执行 - 执行接口请求
  36. Future.microtask(() => viewModel.fetchList());
  37. return () {
  38. // 组件卸载时执行
  39. };
  40. }, []);
  41. return Scaffold(
  42. appBar: MyAppBar.appBar(
  43. context,
  44. S.current.yy_home_accounts,
  45. backgroundColor: context.appColors.whiteBG,
  46. ),
  47. backgroundColor: context.appColors.backgroundDark,
  48. body: Column(
  49. mainAxisSize: MainAxisSize.max,
  50. children: [
  51. EasyRefresh(
  52. controller: viewModel.refreshController,
  53. onRefresh: viewModel.onRefresh,
  54. onLoad: viewModel.loadMore,
  55. child: LoadStateLayout(
  56. state: state.loadingState,
  57. errorMessage: state.errorMessage,
  58. errorRetry: () {
  59. viewModel.retryRequest();
  60. },
  61. successSliverWidget: [
  62. SliverList(
  63. delegate: SliverChildBuilderDelegate(
  64. (context, index) {
  65. return StickyHeader(
  66. header: EstateItemHeader(state.datas[index].groupId),
  67. content: Column(
  68. children: _buildGroup(state.datas[index].groupDatas!, index,viewModel),
  69. ),
  70. );
  71. },
  72. childCount: state.datas.length,
  73. ))
  74. ],
  75. ),
  76. ).expanded(),
  77. MyButton(
  78. onPressed: () {
  79. ComponentServiceManager().authService.startSelectEstatePage();
  80. },
  81. text: S.current.add,
  82. textColor: Colors.white,
  83. backgroundColor: context.appColors.btnBgDefault,
  84. fontWeight: FontWeight.w500,
  85. type: ClickType.throttle,
  86. fontSize: 16,
  87. minHeight: 50,
  88. radius: 0,
  89. )
  90. ],
  91. ),
  92. );
  93. }
  94. //当前组内的子数据
  95. List<Widget> _buildGroup(List<String> list, int index, MyEstateViewModel viewModel) {
  96. return list
  97. .asMap()
  98. .map((childIndex, item) {
  99. return MapEntry(
  100. childIndex,
  101. EstateItem(
  102. item: item,
  103. childIndex: childIndex,
  104. deleteAction: () {
  105. viewModel.showRemoveEstateDialog();
  106. },
  107. ));
  108. })
  109. .values
  110. .toList();
  111. }
  112. }