property_rent_page.dart 6.3 KB

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