property_sale_page.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import 'package:cpt_property/modules/property/page/property_page.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:shared/utils/ext_dart.dart';
  9. import 'package:shared/utils/log_utils.dart';
  10. import 'package:shared/utils/color_utils.dart';
  11. import 'package:widgets/ext/ex_widget.dart';
  12. import 'package:widgets/load_state_layout.dart';
  13. import 'package:widgets/my_load_image.dart';
  14. import 'package:widgets/my_text_view.dart';
  15. import 'package:widgets/widget_export.dart';
  16. import 'package:cs_resources/generated/assets.dart';
  17. import '../../../router/page/property_page_router.dart';
  18. import '../vm/property_sale_vm.dart';
  19. @RoutePage()
  20. class PropertySalePage extends HookConsumerWidget {
  21. const PropertySalePage({Key? key}) : super(key: key);
  22. //启动当前页面
  23. static void startInstance({BuildContext? context}) {
  24. if (context != null) {
  25. context.router.push(const PropertySalePageRoute());
  26. } else {
  27. appRouter.push(const PropertySalePageRoute());
  28. }
  29. }
  30. Widget _buildItemLeftSection(BuildContext context,WidgetRef ref, item, _vm) {
  31. return Container(
  32. // color: Colors.blue,
  33. child:
  34. MyTextView(
  35. item['title'],
  36. fontSize: 16,
  37. textColor: context.appColors.textBlack,
  38. isFontMedium: true,
  39. ),
  40. ).marginOnly(right: 17.5);
  41. }
  42. Widget _buildItemRightSection(BuildContext context,WidgetRef ref, item, _vm) {
  43. return Container(
  44. color: Colors.white,
  45. child: TextButton(
  46. onPressed: (){},
  47. style: TextButton.styleFrom(
  48. foregroundColor: context.appColors.textBlack,
  49. backgroundColor: ColorUtils.string2Color('#EFF3FF'), // 背景颜色
  50. minimumSize: const Size(91.5, 44), // 最小宽度和高度
  51. padding: const EdgeInsets.symmetric(horizontal: 11.0, vertical: 14), // 内边距
  52. shape: RoundedRectangleBorder(
  53. borderRadius: BorderRadius.circular(5), // 圆角
  54. side: BorderSide(
  55. color: ColorUtils.string2Color('#EFF3FF'),
  56. width: 1.0,
  57. ), // 边框
  58. ),
  59. ),
  60. child:MyTextView(
  61. '${item['units']}${item['price']}',
  62. fontSize: 17,
  63. textColor: context.appColors.textBlack,
  64. isFontMedium: true,
  65. ),
  66. ),
  67. );
  68. }
  69. // listitem
  70. Widget _buildSaleItem(BuildContext context,WidgetRef ref, item, _vm) {
  71. return Container(
  72. decoration: BoxDecoration(
  73. color: context.appColors.backgroundWhite,
  74. // borderRadius: BorderRadius.circular(5),
  75. ),
  76. child: Row(
  77. mainAxisAlignment: MainAxisAlignment.center,
  78. crossAxisAlignment: CrossAxisAlignment.center,
  79. mainAxisSize: MainAxisSize.max,
  80. children: [
  81. Container(
  82. width: MediaQuery.of(context).size.width - 30,
  83. height: 100,
  84. margin: const EdgeInsets.only(left: 15,right: 15,top: 12.5),
  85. child: Row(
  86. mainAxisAlignment: MainAxisAlignment.start,
  87. crossAxisAlignment: CrossAxisAlignment.center,
  88. children: [
  89. Expanded(child: _buildItemLeftSection(context, ref, item, _vm)),
  90. SizedBox(
  91. width: 120,
  92. child: _buildItemRightSection(context, ref, item, _vm),
  93. ),
  94. ],
  95. ),
  96. ),
  97. ],
  98. ).onTap((){
  99. // 去详情
  100. _vm.goNewsDetail(item);
  101. }),
  102. ).border(color: context.appColors.dividerDefault, bottom: 0.5);
  103. }
  104. @override
  105. Widget build(BuildContext context, WidgetRef ref) {
  106. final _vm = ref.read(propertySaleVmProvider.notifier);
  107. final state = ref.watch(propertySaleVmProvider);
  108. useEffect(() {
  109. // 组件挂载时执行 - 执行接口请求
  110. Future.microtask(() => _vm.initPageData());
  111. return () {
  112. // 组件卸载时执行
  113. Log.d("property_sale_page 组件卸载时执行");
  114. };
  115. }, []);
  116. return Scaffold(
  117. // appBar: AppBar(title: Text("资产")),
  118. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  119. body: EasyRefresh(
  120. controller: _vm.refreshController,
  121. // 上拉加载
  122. onLoad: () async{
  123. Log.d("----onLoad");
  124. _vm.loadMore();
  125. },
  126. // 下拉刷新
  127. onRefresh: () async{
  128. Log.d("----onRefresh");
  129. _vm.onRefresh();
  130. },
  131. child: LoadStateLayout(
  132. state: state.loadingState,
  133. errorMessage: state.errorMessage,
  134. errorRetry: () {
  135. _vm.retryRequest();
  136. },
  137. successSliverWidget: [
  138. SliverList(
  139. delegate: SliverChildBuilderDelegate(
  140. (context, index){
  141. return _buildSaleItem(context, ref, state.list[index], _vm);
  142. },
  143. childCount: state.list.length
  144. )
  145. )
  146. ],
  147. ),
  148. ).marginOnly(top: 5, bottom: 5),
  149. );
  150. }
  151. }