|
@@ -4,6 +4,7 @@ import 'package:auto_route/auto_route.dart';
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
import 'package:router/ext/auto_router_extensions.dart';
|
|
|
import 'package:shared/utils/log_utils.dart';
|
|
|
+import 'package:shared/utils/util.dart';
|
|
|
import 'package:widgets/ext/ex_widget.dart';
|
|
|
import 'package:widgets/my_load_image.dart';
|
|
|
import 'package:widgets/widget_export.dart';
|
|
@@ -25,14 +26,15 @@ class PropertyNewsPage extends HookConsumerWidget {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Widget _buildItemLeftSection(BuildContext context,WidgetRef ref, String item, _vm) {
|
|
|
+ Widget _buildItemLeftSection(BuildContext context,WidgetRef ref, item, _vm) {
|
|
|
return Container(
|
|
|
// color: Colors.blue,
|
|
|
width: 100,
|
|
|
height: 117.5,
|
|
|
- child: const Center(
|
|
|
- child: MyAssetImage(
|
|
|
- Assets.propertyNewsItemBg,
|
|
|
+ child: Center(
|
|
|
+ child: MyLoadImage(
|
|
|
+ item['pic'],
|
|
|
+ placeholderPath: Assets.propertyNewsItemBg,
|
|
|
width: 60.5,
|
|
|
height: 50.5,
|
|
|
),
|
|
@@ -40,14 +42,24 @@ class PropertyNewsPage extends HookConsumerWidget {
|
|
|
).marginOnly(right: 17.5);
|
|
|
}
|
|
|
|
|
|
- Widget _buildItemRightSection(BuildContext context,WidgetRef ref, String item, _vm) {
|
|
|
+ Widget _buildItemRightSection(BuildContext context,WidgetRef ref, item, _vm) {
|
|
|
+
|
|
|
+ // 使用 ref.select 监听 list 中 item 的 Map 对象中的 isCollection 字段
|
|
|
+ final isCollection = ref.watch(propertyNewsVmProvider.select((state) {
|
|
|
+ final curItem = state.list.firstWhere(
|
|
|
+ (valueItem) => valueItem['id'] == item['id'],
|
|
|
+ orElse: () => {'isCollection': false},
|
|
|
+ );
|
|
|
+ return curItem['isCollection'] as bool;
|
|
|
+ }));
|
|
|
+
|
|
|
return Container(
|
|
|
color: Colors.white,
|
|
|
- padding: EdgeInsets.only(top: 10.5, bottom: 10.5),
|
|
|
+ padding: const EdgeInsets.only(top: 10.5, bottom: 10.5),
|
|
|
child: Container(
|
|
|
child: Stack(
|
|
|
children: [
|
|
|
- const Column(
|
|
|
+ Column(
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
children: [
|
|
@@ -55,36 +67,36 @@ class PropertyNewsPage extends HookConsumerWidget {
|
|
|
children: [
|
|
|
Expanded(
|
|
|
child: Text(
|
|
|
- "Developer'snew homesales shrink to lowest forthe",
|
|
|
+ item['title'],
|
|
|
maxLines: 2, // 设置最大行数为2
|
|
|
overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
|
|
|
- style: TextStyle(fontSize: 16.0, color: Colors.black, fontWeight: FontWeight.w500), // 设置字体大小
|
|
|
+ style: const TextStyle(fontSize: 16.0, color: Colors.black, fontWeight: FontWeight.w400), // 设置字体大小
|
|
|
),
|
|
|
)
|
|
|
],
|
|
|
),
|
|
|
- SizedBox(height: 10.5),
|
|
|
+ const SizedBox(height: 10.5),
|
|
|
Row(
|
|
|
children: [
|
|
|
Expanded(
|
|
|
child: Text(
|
|
|
- 'New home sales in August shrank 64% and are downand are downand are downand are down and are down',
|
|
|
+ item['description'],
|
|
|
maxLines: 2, // 设置最大行数为2
|
|
|
overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
|
|
|
- style: TextStyle(fontSize: 12.0, color: Colors.black), // 设置字体大小
|
|
|
+ style: const TextStyle(fontSize: 12.0, color: Colors.black), // 设置字体大小
|
|
|
),
|
|
|
)
|
|
|
]
|
|
|
),
|
|
|
- SizedBox(height: 12.5),
|
|
|
+ const SizedBox(height: 12.5),
|
|
|
Row(
|
|
|
children: [
|
|
|
Expanded(
|
|
|
child: Text(
|
|
|
- '1H Ago',
|
|
|
+ Utils.getTimeAgo(item['time']),
|
|
|
maxLines: 1, // 设置最大行数为2
|
|
|
overflow: TextOverflow.ellipsis, // 超出部分用省略号表示
|
|
|
- style: TextStyle(fontSize: 12.0, color: Colors.black), // 设置字体大小
|
|
|
+ style: const TextStyle(fontSize: 12.0, color: Colors.black), // 设置字体大小
|
|
|
),
|
|
|
)
|
|
|
]
|
|
@@ -94,8 +106,9 @@ class PropertyNewsPage extends HookConsumerWidget {
|
|
|
Positioned(
|
|
|
right: 5,
|
|
|
bottom: 0,
|
|
|
- child: const MyAssetImage(Assets.propertyCollection,width:22,height: 20.5,).onTap((){
|
|
|
+ child: MyAssetImage(isCollection? Assets.propertyCollectionActive:Assets.propertyCollection,width:22,height: 20.5,).onTap((){
|
|
|
Log.d("点击了收藏按钮");
|
|
|
+ _vm.handlerCollection(item, isCollection);
|
|
|
}),
|
|
|
),
|
|
|
],
|
|
@@ -105,7 +118,7 @@ class PropertyNewsPage extends HookConsumerWidget {
|
|
|
}
|
|
|
|
|
|
// listitem
|
|
|
- Widget _buildNewsItem(BuildContext context,WidgetRef ref, String item, _vm) {
|
|
|
+ Widget _buildNewsItem(BuildContext context,WidgetRef ref, item, _vm) {
|
|
|
return Row(
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
@@ -134,11 +147,13 @@ class PropertyNewsPage extends HookConsumerWidget {
|
|
|
|
|
|
// list
|
|
|
Widget _buildNewsList(BuildContext context, WidgetRef ref, _vm) {
|
|
|
- List items = List.generate(20, (index) => "Item $index");
|
|
|
+ // List items = List.generate(20, (index) => "Item $index");
|
|
|
+ // List items = _vm.state.list.fromJson();
|
|
|
+ List itemsList = _vm.state.list.toList();
|
|
|
return ListView.builder(
|
|
|
- itemCount: items.length,
|
|
|
+ itemCount: itemsList.length,
|
|
|
itemBuilder: (context, index) {
|
|
|
- return _buildNewsItem(context, ref, items[index], _vm);
|
|
|
+ return _buildNewsItem(context, ref, itemsList[index], _vm);
|
|
|
},
|
|
|
);
|
|
|
}
|
|
@@ -151,10 +166,14 @@ class PropertyNewsPage extends HookConsumerWidget {
|
|
|
// appBar: AppBar(title: Text("资产")),
|
|
|
body: Container(
|
|
|
child: EasyRefresh(
|
|
|
+ // 上拉加载
|
|
|
onLoad: () async{
|
|
|
- _vm.initListData();
|
|
|
+ Log.d("----onLoad");
|
|
|
+ _vm.onLoadData();
|
|
|
},
|
|
|
+ // 下拉刷新
|
|
|
onRefresh: () async{
|
|
|
+ Log.d("----onRefresh");
|
|
|
_vm.refreshListData();
|
|
|
},
|
|
|
child: _buildNewsList(context, ref, _vm),
|