property_rent_page.dart 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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_rent_vm.dart';
  19. @RoutePage()
  20. class PropertyRentPage extends HookConsumerWidget {
  21. const PropertyRentPage({Key? key}) : super(key: key);
  22. //启动当前页面
  23. static void startInstance({BuildContext? context}) {
  24. if (context != null) {
  25. context.router.push(const PropertyRentPageRoute());
  26. } else {
  27. appRouter.push(const PropertyRentPageRoute());
  28. }
  29. }
  30. Widget _buildItemLeftSection(BuildContext context,WidgetRef ref, item, _vm) {
  31. return Container(
  32. // color: Colors.blue,
  33. child: MyTextView(
  34. item['title'],
  35. maxLines: 2, // 设置最大行数为2
  36. isTextEllipsis: true, // 超出部分用省略号表示
  37. fontSize: 16,
  38. textColor: context.appColors.textBlack,
  39. isFontMedium: true,
  40. )
  41. ).marginOnly(right: 17.5);
  42. }
  43. Widget _buildItemRightSection(BuildContext context,WidgetRef ref, Map<String, dynamic> item, _vm) {
  44. String price = item.getValue('price', '');
  45. return Container(
  46. color: context.appColors.textWhite,
  47. child: TextButton(
  48. onPressed: (){},
  49. style: TextButton.styleFrom(
  50. foregroundColor: context.appColors.textBlack,
  51. backgroundColor: ColorUtils.string2Color('#EFF3FF'), // 背景颜色
  52. // minimumSize: const Size(71, 30), // 最小宽度和高度
  53. padding: const EdgeInsets.symmetric(horizontal: 17.5, vertical: 7.5), // 内边距
  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: Container(
  63. height: 44,
  64. child: Column(
  65. mainAxisAlignment: MainAxisAlignment.center,
  66. children: [
  67. MyTextView(
  68. price,
  69. fontSize: 17,
  70. isFontMedium: true,
  71. ),
  72. MyTextView(
  73. 'per month',
  74. fontSize: 12,
  75. ),
  76. ],
  77. ),
  78. ),
  79. ),
  80. );
  81. }
  82. // listitem
  83. Widget _buildRentItem(BuildContext context,WidgetRef ref, item, _vm) {
  84. return Container(
  85. decoration: BoxDecoration(
  86. color: context.appColors.backgroundWhite,
  87. // borderRadius: BorderRadius.circular(5),
  88. ),
  89. child: Row(
  90. mainAxisAlignment: MainAxisAlignment.center,
  91. crossAxisAlignment: CrossAxisAlignment.center,
  92. mainAxisSize: MainAxisSize.max,
  93. children: [
  94. Container(
  95. width: MediaQuery.of(context).size.width - 30,
  96. height: 100,
  97. margin: const EdgeInsets.only(left: 15,right: 15,top: 12.5),
  98. child: Row(
  99. mainAxisAlignment: MainAxisAlignment.start,
  100. crossAxisAlignment: CrossAxisAlignment.center,
  101. children: [
  102. Expanded(child: _buildItemLeftSection(context, ref, item, _vm)),
  103. Container(
  104. child: _buildItemRightSection(context, ref, item, _vm),
  105. ).constrained(
  106. minWidth: 100,
  107. ),
  108. ],
  109. ),
  110. ),
  111. ],
  112. ).onTap((){
  113. // 去详情
  114. // _vm.goNewsDetail(item);
  115. }),
  116. ).border(color: context.appColors.dividerDefault, bottom: 0.5);
  117. }
  118. @override
  119. Widget build(BuildContext context, WidgetRef ref) {
  120. final _vm = ref.read(propertyRentVmProvider.notifier);
  121. final state = ref.watch(propertyRentVmProvider);
  122. useEffect(() {
  123. // 组件挂载时执行 - 执行接口请求
  124. Future.microtask(() => _vm.initPageData());
  125. return () {
  126. // 组件卸载时执行
  127. Log.d("property_rent_page 组件卸载时执行");
  128. };
  129. }, []);
  130. return Scaffold(
  131. // appBar: AppBar(title: Text("资产")),
  132. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  133. body: SizedBox(
  134. width: double.infinity,
  135. height: double.infinity,
  136. child: EasyRefresh(
  137. controller: _vm.refreshController,
  138. // 上拉加载
  139. onLoad: () async{
  140. Log.d("----onLoad");
  141. _vm.loadMore();
  142. },
  143. // 下拉刷新
  144. onRefresh: () async{
  145. Log.d("----onRefresh");
  146. _vm.onRefresh();
  147. },
  148. child: LoadStateLayout(
  149. state: state.loadingState,
  150. errorMessage: state.errorMessage,
  151. errorRetry: () {
  152. _vm.retryRequest();
  153. },
  154. successSliverWidget: [
  155. SliverList(
  156. delegate: SliverChildBuilderDelegate(
  157. (context, index) {
  158. return _buildRentItem(context, ref, state.list[index], _vm);
  159. },
  160. childCount: state.list.length
  161. ),
  162. )
  163. ],
  164. ),
  165. ).marginOnly(top: 5, bottom: 5)
  166. ),
  167. );
  168. }
  169. }