property_sale_page.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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, Map<String, dynamic>item, _vm) {
  43. String price = item.getValue('price', '');
  44. return Container(
  45. color: context.appColors.textWhite,
  46. width: 120,
  47. child: TextButton(
  48. onPressed: (){},
  49. style: TextButton.styleFrom(
  50. foregroundColor: context.appColors.textBlack,
  51. backgroundColor: ColorUtils.string2Color('#EFF3FF'), // 背景颜色
  52. // minimumSize: const Size(91.5, 44), // 最小宽度和高度
  53. padding: const EdgeInsets.symmetric(horizontal: 11.0, vertical: 14), // 内边距
  54. shape: RoundedRectangleBorder(
  55. borderRadius: BorderRadius.circular(5), // 圆角
  56. side: BorderSide(
  57. color: ColorUtils.string2Color('#EFF3FF'),
  58. width: 1.0,
  59. ), // 边框
  60. ),
  61. ),
  62. child: MyTextView(
  63. price,
  64. fontSize: 17,
  65. textColor: context.appColors.textBlack,
  66. isFontMedium: true,
  67. ),
  68. ),
  69. );
  70. }
  71. // listitem
  72. Widget _buildSaleItem(BuildContext context,WidgetRef ref, item, _vm) {
  73. return Container(
  74. decoration: BoxDecoration(
  75. color: context.appColors.backgroundWhite,
  76. // borderRadius: BorderRadius.circular(5),
  77. ),
  78. child: Row(
  79. mainAxisAlignment: MainAxisAlignment.center,
  80. crossAxisAlignment: CrossAxisAlignment.center,
  81. mainAxisSize: MainAxisSize.max,
  82. children: [
  83. Container(
  84. width: MediaQuery.of(context).size.width - 30,
  85. height: 100,
  86. margin: const EdgeInsets.only(left: 15,right: 15,top: 12.5),
  87. child: Row(
  88. mainAxisAlignment: MainAxisAlignment.start,
  89. crossAxisAlignment: CrossAxisAlignment.center,
  90. children: [
  91. Expanded(child: _buildItemLeftSection(context, ref, item, _vm)),
  92. _buildItemRightSection(context, ref, item, _vm),
  93. ],
  94. ),
  95. ),
  96. ],
  97. ).onTap((){
  98. // 去详情
  99. // _vm.goNewsDetail(item);
  100. }),
  101. ).border(color: context.appColors.dividerDefault, bottom: 0.5);
  102. }
  103. @override
  104. Widget build(BuildContext context, WidgetRef ref) {
  105. final _vm = ref.read(propertySaleVmProvider.notifier);
  106. final state = ref.watch(propertySaleVmProvider);
  107. useEffect(() {
  108. // 组件挂载时执行 - 执行接口请求
  109. Future.microtask(() => _vm.initPageData());
  110. return () {
  111. // 组件卸载时执行
  112. Log.d("property_sale_page 组件卸载时执行");
  113. };
  114. }, []);
  115. return Scaffold(
  116. // appBar: AppBar(title: Text("资产")),
  117. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  118. body: EasyRefresh(
  119. controller: _vm.refreshController,
  120. // 上拉加载
  121. onLoad: () async{
  122. Log.d("----onLoad");
  123. _vm.loadMore();
  124. },
  125. // 下拉刷新
  126. onRefresh: () async{
  127. Log.d("----onRefresh");
  128. _vm.onRefresh();
  129. },
  130. child: LoadStateLayout(
  131. state: state.loadingState,
  132. errorMessage: state.errorMessage,
  133. errorRetry: () {
  134. _vm.retryRequest();
  135. },
  136. successSliverWidget: [
  137. SliverList(
  138. delegate: SliverChildBuilderDelegate(
  139. (context, index){
  140. return _buildSaleItem(context, ref, state.list[index], _vm);
  141. },
  142. childCount: state.list.length
  143. )
  144. )
  145. ],
  146. ),
  147. ).marginOnly(top: 5, bottom: 5),
  148. );
  149. }
  150. }