news_page.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import 'package:cs_resources/generated/assets.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:auto_route/auto_route.dart';
  4. import 'package:flutter/rendering.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/color_utils.dart';
  9. import 'package:shared/utils/log_utils.dart';
  10. import 'package:widgets/my_button.dart';
  11. import 'package:widgets/my_load_image.dart';
  12. import 'package:widgets/ext/ex_widget.dart';
  13. import 'package:widgets/my_text_view.dart';
  14. import 'package:widgets/my_appbar.dart';
  15. import 'package:cs_resources/theme/app_colors_theme.dart';
  16. import 'package:widgets/widget_export.dart';
  17. import '../../../components/newfeed_card_header.dart';
  18. import '../../../components/newsfeed_card_content.dart';
  19. import '../../../components/newsfeed_card_footer.dart';
  20. import '../../../router/page/community_page_router.dart';
  21. import 'news_vm.dart';
  22. @RoutePage()
  23. class NewsPage extends HookConsumerWidget {
  24. const NewsPage({Key? key}) : super(key: key);
  25. //启动当前页面
  26. static void startInstance({BuildContext? context}) {
  27. if (context != null) {
  28. context.router.push(const NewsPageRoute());
  29. } else {
  30. appRouter.push(const NewsPageRoute());
  31. }
  32. }
  33. @override
  34. Widget build(BuildContext context, WidgetRef ref) {
  35. final vm = ref.read(newsVmProvider.notifier);
  36. return Scaffold(
  37. // appBar: MyAppBar.appBar(
  38. // context,
  39. // "news",
  40. // backgroundColor: context.appColors.whiteBG,
  41. // ),
  42. // backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  43. body: Column(
  44. children: [
  45. Expanded(
  46. child: EasyRefresh(
  47. // 上拉加载
  48. onLoad: () async{
  49. Log.d("----onLoad");
  50. vm.onLoadData();
  51. },
  52. // 下拉刷新
  53. onRefresh: () async{
  54. Log.d("----onRefresh");
  55. vm.refreshListData();
  56. },
  57. child: _buildNewsFeedList(context, ref, vm),
  58. ),
  59. )
  60. ],
  61. )
  62. );
  63. }
  64. Widget _buildNewsItem(BuildContext context, WidgetRef ref, item, vm){
  65. return Container(
  66. width: double.infinity,
  67. // color: Colors.yellow,
  68. child: Stack(
  69. children: [
  70. Container(
  71. margin: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  72. color: Colors.white,
  73. padding: const EdgeInsets.only(left: 15, right: 15,top: 17,bottom: 17),
  74. height: 280,
  75. child: Column(
  76. mainAxisAlignment: MainAxisAlignment.center,
  77. crossAxisAlignment: CrossAxisAlignment.start,
  78. children: [
  79. // 卡片头部(头像 标题 时间)
  80. NewsFeedCardHeader(
  81. key: UniqueKey(),
  82. title: item['title'],
  83. avator: item['avator'],
  84. time: item['time'],
  85. ),
  86. const SizedBox(height: 15),
  87. // 卡片中间 (文字和图片)
  88. Expanded(
  89. child: NewsFeedCardContent(
  90. key: UniqueKey(),
  91. content: item['content'],
  92. imageUrls: item['imageUrls'],
  93. ),
  94. ),
  95. const SizedBox(height: 26),
  96. // // 卡片底部 (点赞 评论 分享)
  97. NewsFeedCardFooter(
  98. key: UniqueKey(),
  99. isLike: item['isLike'],
  100. onLike: (){
  101. vm.handlerClickActionBtn('like', item);
  102. },
  103. onComment: (){
  104. vm.handlerClickActionBtn('comments', item);
  105. },
  106. onShare: (){
  107. vm.handlerClickActionBtn('share', item);
  108. },
  109. ),
  110. ]
  111. ),
  112. ),
  113. // 右上角 关注/取消关注 按钮
  114. Visibility(
  115. visible: !item['isFollow'],
  116. child: Positioned(
  117. right: 40,
  118. top: 35,
  119. child: Container(
  120. width: 83.5,
  121. height: 45.5,
  122. alignment: Alignment.center,
  123. // decoration: BoxDecoration(
  124. // color: ColorUtils.string2Color('#4161D0'),
  125. // borderRadius: BorderRadius.circular(5),
  126. // ),
  127. child: MyButton(
  128. text: '+Follow',
  129. textColor: Colors.white,
  130. backgroundColor: ColorUtils.string2Color('#4161D0'),
  131. radius: 8,
  132. minHeight: 27.5,
  133. padding: const EdgeInsets.only(left: 5, right: 5,top:9,bottom:9),
  134. fontWeight: FontWeight.w400,
  135. fontSize: 14,
  136. onPressed: (){
  137. // Navigator.pop(context);
  138. },
  139. ),
  140. )
  141. ),
  142. )
  143. ],
  144. ),
  145. );
  146. }
  147. Widget _buildNewsFeedList(BuildContext context, WidgetRef ref, vm){
  148. final itemList = vm.state.list?? [];
  149. if(itemList.isEmpty){
  150. return const Center(child: Text('No Data'));
  151. }else {
  152. List itemsList = vm.state.list.toList();
  153. return ListView.builder(
  154. key: UniqueKey(),
  155. itemCount: itemsList.length,
  156. itemBuilder: (context, index) {
  157. return _buildNewsItem(context, ref, itemsList[index], vm);
  158. },
  159. );
  160. }
  161. // return Text("879424");
  162. }
  163. }