property_rent_page.dart 5.0 KB

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