property_rent_page.dart 6.0 KB

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