property_rent_page.dart 5.5 KB

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