property_sale_page.dart 5.4 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, 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, Map<String, dynamic>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. Container(child: _buildItemRightSection(context, ref, item, _vm)).constrained(
  93. minWidth: 120,
  94. ),
  95. ],
  96. ),
  97. ),
  98. ],
  99. ).onTap((){
  100. // 去详情
  101. // _vm.goNewsDetail(item);
  102. }),
  103. ).border(color: context.appColors.dividerDefault, bottom: 0.5);
  104. }
  105. @override
  106. Widget build(BuildContext context, WidgetRef ref) {
  107. final _vm = ref.read(propertySaleVmProvider.notifier);
  108. final state = ref.watch(propertySaleVmProvider);
  109. useEffect(() {
  110. // 组件挂载时执行 - 执行接口请求
  111. Future.microtask(() => _vm.initPageData());
  112. return () {
  113. // 组件卸载时执行
  114. Log.d("property_sale_page 组件卸载时执行");
  115. };
  116. }, []);
  117. return Scaffold(
  118. // appBar: AppBar(title: Text("资产")),
  119. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  120. body: EasyRefresh(
  121. controller: _vm.refreshController,
  122. // 上拉加载
  123. onLoad: () async{
  124. Log.d("----onLoad");
  125. _vm.loadMore();
  126. },
  127. // 下拉刷新
  128. onRefresh: () async{
  129. Log.d("----onRefresh");
  130. _vm.onRefresh();
  131. },
  132. child: LoadStateLayout(
  133. state: state.loadingState,
  134. errorMessage: state.errorMessage,
  135. errorRetry: () {
  136. _vm.retryRequest();
  137. },
  138. successSliverWidget: [
  139. SliverList(
  140. delegate: SliverChildBuilderDelegate(
  141. (context, index){
  142. return _buildSaleItem(context, ref, state.list[index], _vm);
  143. },
  144. childCount: state.list.length
  145. )
  146. )
  147. ],
  148. ),
  149. ).marginOnly(top: 5, bottom: 5),
  150. );
  151. }
  152. }