property_rent_page.dart 5.8 KB

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