property_news_page.dart 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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:widgets/ext/ex_widget.dart';
  8. import 'package:widgets/my_load_image.dart';
  9. import 'package:widgets/widget_export.dart';
  10. import 'package:cs_resources/generated/assets.dart';
  11. import '../../../router/page/property_page_router.dart';
  12. import '../vm/property_news_vm.dart';
  13. @RoutePage()
  14. class PropertyNewsPage extends HookConsumerWidget {
  15. const PropertyNewsPage({Key? key}) : super(key: key);
  16. //启动当前页面
  17. static void startInstance({BuildContext? context}) {
  18. if (context != null) {
  19. context.router.push(const PropertyNewsPageRoute());
  20. } else {
  21. appRouter.push(const PropertyNewsPageRoute());
  22. }
  23. }
  24. Widget _buildItemLeftSection(BuildContext context,WidgetRef ref, String item, _vm) {
  25. return Container(
  26. // color: Colors.blue,
  27. width: 100,
  28. height: 117.5,
  29. child: const Center(
  30. child: MyAssetImage(
  31. Assets.propertyNewsItemBg,
  32. width: 60.5,
  33. height: 50.5,
  34. ),
  35. )
  36. ).marginOnly(right: 17.5);
  37. }
  38. Widget _buildItemRightSection(BuildContext context,WidgetRef ref, String item, _vm) {
  39. return Container(
  40. color: Colors.white,
  41. padding: EdgeInsets.only(top: 10.5, bottom: 10.5),
  42. child: Container(
  43. child: Stack(
  44. children: [
  45. const Column(
  46. mainAxisAlignment: MainAxisAlignment.start,
  47. crossAxisAlignment: CrossAxisAlignment.start,
  48. children: [
  49. Row(
  50. children: [
  51. Expanded(
  52. child: Text(
  53. "Developer'snew homesales shrink to lowest forthe",
  54. maxLines: 2, // 设置最大行数为2
  55. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  56. style: TextStyle(fontSize: 16.0, color: Colors.black, fontWeight: FontWeight.w500), // 设置字体大小
  57. ),
  58. )
  59. ],
  60. ),
  61. SizedBox(height: 10.5),
  62. Row(
  63. children: [
  64. Expanded(
  65. child: Text(
  66. 'New home sales in August shrank 64% and are downand are downand are downand are down and are down',
  67. maxLines: 2, // 设置最大行数为2
  68. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  69. style: TextStyle(fontSize: 12.0, color: Colors.black), // 设置字体大小
  70. ),
  71. )
  72. ]
  73. ),
  74. SizedBox(height: 12.5),
  75. Row(
  76. children: [
  77. Expanded(
  78. child: Text(
  79. '1H Ago',
  80. maxLines: 1, // 设置最大行数为2
  81. overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
  82. style: TextStyle(fontSize: 12.0, color: Colors.black), // 设置字体大小
  83. ),
  84. )
  85. ]
  86. ),
  87. ],
  88. ),
  89. Positioned(
  90. right: 5,
  91. bottom: 0,
  92. child: const MyAssetImage(Assets.propertyCollection,width:22,height: 20.5,).onTap((){
  93. Log.d("点击了收藏按钮");
  94. }),
  95. ),
  96. ],
  97. ),
  98. ),
  99. );
  100. }
  101. // listitem
  102. Widget _buildNewsItem(BuildContext context,WidgetRef ref, String item, _vm) {
  103. return Row(
  104. mainAxisAlignment: MainAxisAlignment.center,
  105. crossAxisAlignment: CrossAxisAlignment.center,
  106. mainAxisSize: MainAxisSize.max,
  107. children: [
  108. Container(
  109. width: MediaQuery.of(context).size.width - 30,
  110. margin: const EdgeInsets.only(left: 15,right: 15,top: 12.5),
  111. child: Row(
  112. mainAxisAlignment: MainAxisAlignment.start,
  113. crossAxisAlignment: CrossAxisAlignment.start,
  114. children: [
  115. _buildItemLeftSection(context, ref, item, _vm),
  116. Expanded(child: _buildItemRightSection(context, ref, item, _vm)),
  117. ],
  118. ),
  119. ).constrained(
  120. minHeight: 117.5,
  121. ),
  122. ],
  123. ).onTap((){
  124. // 去详情
  125. _vm.goNewsDetail(item);
  126. });
  127. }
  128. // list
  129. Widget _buildNewsList(BuildContext context, WidgetRef ref, _vm) {
  130. List items = List.generate(20, (index) => "Item $index");
  131. return ListView.builder(
  132. itemCount: items.length,
  133. itemBuilder: (context, index) {
  134. return _buildNewsItem(context, ref, items[index], _vm);
  135. },
  136. );
  137. }
  138. @override
  139. Widget build(BuildContext context, WidgetRef ref) {
  140. final _vm = ref.read(propertyNewsVmProvider.notifier);
  141. return Scaffold(
  142. // appBar: AppBar(title: Text("资产")),
  143. body: Container(
  144. child: EasyRefresh(
  145. onLoad: () async{
  146. _vm.initListData();
  147. },
  148. onRefresh: () async{
  149. _vm.refreshListData();
  150. },
  151. child: _buildNewsList(context, ref, _vm),
  152. )
  153. ),
  154. );
  155. }
  156. }