my_household_page.dart 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'package:cs_resources/generated/l10n.dart';
  2. import 'package:cs_resources/theme/app_colors_theme.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:auto_route/auto_route.dart';
  5. import 'package:flutter_hooks/flutter_hooks.dart';
  6. import 'package:hooks_riverpod/hooks_riverpod.dart';
  7. import 'package:router/ext/auto_router_extensions.dart';
  8. import 'package:widgets/ext/ex_widget.dart';
  9. import 'package:widgets/load_state_layout.dart';
  10. import 'package:widgets/my_appbar.dart';
  11. import 'package:widgets/my_text_view.dart';
  12. import 'package:widgets/widget_export.dart';
  13. import '../../router/page/profile_page_router.dart';
  14. import 'item_household.dart';
  15. import 'my_household_view_model.dart';
  16. @RoutePage()
  17. class MyHouseholdPage extends HookConsumerWidget {
  18. const MyHouseholdPage({Key? key}) : super(key: key);
  19. //启动当前页面
  20. static void startInstance({BuildContext? context}) {
  21. if (context != null) {
  22. context.router.push(const MyHouseholdPageRoute());
  23. } else {
  24. appRouter.push(const MyHouseholdPageRoute());
  25. }
  26. }
  27. @override
  28. Widget build(BuildContext context, WidgetRef ref) {
  29. final viewModel = ref.watch(myHouseholdViewModelProvider.notifier);
  30. final state = ref.watch(myHouseholdViewModelProvider);
  31. useEffect(() {
  32. // 组件挂载时执行 - 执行接口请求
  33. Future.microtask(() => viewModel.fetchList());
  34. return () {
  35. // 组件卸载时执行
  36. };
  37. }, []);
  38. return Scaffold(
  39. appBar: MyAppBar.appBar(
  40. context,
  41. S.current.household_members,
  42. backgroundColor: context.appColors.whiteBG,
  43. ),
  44. backgroundColor: context.appColors.backgroundDark,
  45. body: SizedBox(
  46. width: double.infinity,
  47. height: double.infinity,
  48. child: EasyRefresh(
  49. controller: viewModel.refreshController,
  50. onRefresh: viewModel.onRefresh,
  51. onLoad: viewModel.loadMore,
  52. child: LoadStateLayout(
  53. state: state.loadingState,
  54. errorMessage: state.errorMessage,
  55. errorRetry: () {
  56. viewModel.retryRequest();
  57. },
  58. successSliverWidget: [
  59. //顶部的房产显示
  60. _buildEstateWidget(context),
  61. //房产内成员的列表
  62. SliverList(
  63. delegate: SliverChildBuilderDelegate(
  64. (context, index) {
  65. return HouseholdItem(index: index, item: state.datas[index]);
  66. },
  67. childCount: state.datas.length,
  68. ))
  69. ],
  70. ),
  71. ),
  72. ),
  73. );
  74. }
  75. //顶部的房产布局
  76. Widget _buildEstateWidget(BuildContext context) {
  77. return SliverToBoxAdapter(
  78. child: MyTextView(
  79. "Owner 35 #08-29",
  80. fontSize: 20,
  81. paddingLeft: 15,
  82. paddingRight: 15,
  83. paddingTop: 19,
  84. paddingBottom: 19,
  85. isFontMedium: true,
  86. textColor: context.appColors.textBlack,
  87. ),
  88. );
  89. }
  90. }