news_page.dart 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. Text("news -page"),
  46. // post 组件
  47. _buildPostSection(context, ref, vm),
  48. // Expanded(
  49. // child: EasyRefresh(
  50. // // 上拉加载
  51. // onLoad: () async{
  52. // Log.d("----onLoad");
  53. // vm.onLoadData();
  54. // },
  55. // // 下拉刷新
  56. // onRefresh: () async{
  57. // Log.d("----onRefresh");
  58. // vm.refreshListData();
  59. // },
  60. // child: _buildNesFeedList(context, ref, vm),
  61. // ),
  62. // )
  63. _buildNesFeedList(context, ref, vm),
  64. ],
  65. )
  66. );
  67. }
  68. Widget _buildPostSection(BuildContext context, WidgetRef ref, vm){
  69. return Container(
  70. height: 65.5,
  71. width: double.infinity,
  72. padding: const EdgeInsets.only(left: 20, right: 20),
  73. color: Colors.white,
  74. child: Row(
  75. children: [
  76. const MyAssetImage(Assets.communityNesFeed, width: 45,height: 45,),
  77. Expanded(
  78. child: Row(
  79. children: [
  80. Expanded(
  81. child: Container(
  82. // height: 65.5,
  83. // color: Colors.blue,
  84. child: MyTextView(
  85. "What’s on your mind?",
  86. textColor: ColorUtils.string2Color('#000000'),
  87. fontSize: 15,
  88. marginLeft: 15,
  89. alignment: Alignment.centerLeft,
  90. textAlign: TextAlign.left,
  91. backgroundColor: ColorUtils.string2Color('#ffffff'),
  92. maxLines: 1,
  93. isFontMedium: true,
  94. ),
  95. ),
  96. ),
  97. const MyAssetImage(
  98. Assets.communityCamera,
  99. width: 21,
  100. height: 16.5,
  101. ),
  102. ],
  103. ).onTap((){
  104. vm.handlerGotoPost(context);
  105. }),
  106. ),
  107. ],
  108. ),
  109. );
  110. }
  111. Widget _buildNewsItem(BuildContext context, WidgetRef ref, item, vm){
  112. return Container(
  113. width: double.infinity,
  114. // color: Colors.yellow,
  115. child: Stack(
  116. children: [
  117. Container(
  118. margin: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  119. color: Colors.white,
  120. padding: const EdgeInsets.only(left: 15, right: 15,top: 17,bottom: 17),
  121. height: 280,
  122. child: Column(
  123. mainAxisAlignment: MainAxisAlignment.center,
  124. crossAxisAlignment: CrossAxisAlignment.start,
  125. children: [
  126. // 卡片头部(头像 标题 时间)
  127. NewsFeedCardHeader(
  128. key: UniqueKey(),
  129. title: item['title'],
  130. avator: item['avator'],
  131. time: item['time'],
  132. ),
  133. const SizedBox(height: 15),
  134. // 卡片中间 (文字和图片)
  135. Expanded(
  136. child: NewsFeedCardContent(
  137. key: UniqueKey(),
  138. content: item['content'],
  139. imageUrls: item['imageUrls'],
  140. ),
  141. ),
  142. const SizedBox(height: 26),
  143. // // 卡片底部 (点赞 评论 分享)
  144. NewsFeedCardFooter(
  145. key: UniqueKey(),
  146. isLike: item['isLike'],
  147. onLike: (){
  148. vm.handlerClickActionBtn('like', item);
  149. },
  150. onComment: (){
  151. vm.handlerClickActionBtn('comments', item);
  152. },
  153. onShare: (){
  154. vm.handlerClickActionBtn('share', item);
  155. },
  156. ),
  157. ]
  158. ),
  159. ),
  160. // 右上角 关注/取消关注 按钮
  161. Visibility(
  162. visible: !item['isFollow'],
  163. child: Positioned(
  164. right: 40,
  165. top: 35,
  166. child: Container(
  167. width: 83.5,
  168. height: 45.5,
  169. alignment: Alignment.center,
  170. // decoration: BoxDecoration(
  171. // color: ColorUtils.string2Color('#4161D0'),
  172. // borderRadius: BorderRadius.circular(5),
  173. // ),
  174. child: MyButton(
  175. text: '+Follow',
  176. textColor: Colors.white,
  177. backgroundColor: ColorUtils.string2Color('#4161D0'),
  178. radius: 8,
  179. minHeight: 27.5,
  180. padding: const EdgeInsets.only(left: 5, right: 5,top:9,bottom:9),
  181. fontWeight: FontWeight.w400,
  182. fontSize: 14,
  183. onPressed: (){
  184. // Navigator.pop(context);
  185. },
  186. ),
  187. )
  188. ),
  189. )
  190. ],
  191. ),
  192. );
  193. }
  194. Widget _buildNesFeedList(BuildContext context, WidgetRef ref, vm){
  195. final itemList = vm.state.list?? [];
  196. if(itemList.isEmpty){
  197. return const Center(child: Text('No Data'));
  198. }else {
  199. List itemsList = vm.state.list.toList();
  200. return ListView.builder(
  201. key: UniqueKey(),
  202. itemCount: itemsList.length,
  203. itemBuilder: (context, index) {
  204. return _buildNewsItem(context, ref, itemsList[index], vm);
  205. },
  206. );
  207. }
  208. }
  209. }