newsfeed_page.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import 'package:cpt_community/components/custom_tabs.dart';
  2. import 'package:cpt_community/components/newsfeed_card_content.dart';
  3. import 'package:cpt_community/components/newsfeed_card_footer.dart';
  4. import 'package:cs_resources/generated/assets.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:auto_route/auto_route.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:router/ext/auto_router_extensions.dart';
  9. import 'package:shared/utils/color_utils.dart';
  10. import 'package:shared/utils/log_utils.dart';
  11. import 'package:widgets/ext/ex_widget.dart';
  12. import 'package:widgets/my_load_image.dart';
  13. import 'package:widgets/my_text_view.dart';
  14. import 'package:widgets/widget_export.dart';
  15. import '../../components/newfeed_card_header.dart';
  16. import '../../router/page/community_page_router.dart';
  17. import 'newsfeed_vm.dart';
  18. @RoutePage()
  19. class NewsfeedPage extends HookConsumerWidget {
  20. const NewsfeedPage({Key? key}) : super(key: key);
  21. //启动当前页面
  22. static void startInstance({BuildContext? context}) {
  23. if (context != null) {
  24. context.router.push(const NewsfeedPageRoute());
  25. } else {
  26. appRouter.push(const NewsfeedPageRoute());
  27. }
  28. }
  29. Widget _buildTabsSection(BuildContext context, WidgetRef ref, vm){
  30. return Container(
  31. width: double.infinity,
  32. padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  33. child: CustomTabs(
  34. key: UniqueKey(),
  35. tabsList: vm.state.tabsList,
  36. ),
  37. );
  38. }
  39. Widget _buildPostSection(BuildContext context, WidgetRef ref, vm){
  40. return Container(
  41. height: 65.5,
  42. width: double.infinity,
  43. padding: const EdgeInsets.only(left: 20, right: 20),
  44. color: Colors.white,
  45. child: Row(
  46. children: [
  47. const MyAssetImage(Assets.communityNesFeed, width: 45,height: 45,),
  48. Expanded(
  49. child: Row(
  50. children: [
  51. Expanded(
  52. child: Container(
  53. // height: 65.5,
  54. // color: Colors.blue,
  55. child: MyTextView(
  56. "What’s on your mind?",
  57. textColor: ColorUtils.string2Color('#000000'),
  58. fontSize: 15,
  59. marginLeft: 15,
  60. alignment: Alignment.centerLeft,
  61. textAlign: TextAlign.left,
  62. backgroundColor: ColorUtils.string2Color('#ffffff'),
  63. maxLines: 1,
  64. isFontMedium: true,
  65. ),
  66. ),
  67. ),
  68. const MyAssetImage(
  69. Assets.communityCamera,
  70. width: 21,
  71. height: 16.5,
  72. ),
  73. ],
  74. ).onTap((){
  75. vm.handlerGotoPost(context);
  76. }),
  77. ),
  78. ],
  79. ),
  80. );
  81. }
  82. Widget _buildNewsItem(BuildContext context, WidgetRef ref, item, vm){
  83. return Container(
  84. width: double.infinity,
  85. // padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  86. color: Colors.yellow,
  87. child: Container(
  88. margin: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  89. color: Colors.white,
  90. padding: const EdgeInsets.only(left: 15, right: 15,top: 17,bottom: 17),
  91. height: 280,
  92. child: Column(
  93. mainAxisAlignment: MainAxisAlignment.center,
  94. crossAxisAlignment: CrossAxisAlignment.start,
  95. children: [
  96. // 卡片头部(头像 标题 时间)
  97. NewsFeedCardHeader(
  98. title: item['title'],
  99. avator: item['avator'],
  100. time: item['time'],
  101. ),
  102. const SizedBox(height: 15),
  103. // 卡片中间 (文字和图片)
  104. Expanded(
  105. child: NewsFeedCardContent(
  106. content: item['content'],
  107. imageUrls: item['imageUrls'],
  108. ),
  109. ),
  110. const SizedBox(height: 26),
  111. // // 卡片底部 (点赞 评论 分享)
  112. NewsFeedCardFooter(
  113. isLike: item['isLike'],
  114. ),
  115. ]
  116. ),
  117. )
  118. );
  119. }
  120. Widget _buildNesFeedList(BuildContext context, WidgetRef ref, vm){
  121. // return Container(
  122. // height: 100,
  123. // color: Colors.blue,
  124. // );
  125. // List items = List.generate(20, (index) => "Item $index");
  126. // List items = _vm.state.list.fromMap();
  127. final itemList = vm.state.list?? [];
  128. if(itemList.isEmpty){
  129. return const Center(child: Text('No Data'));
  130. }else {
  131. List itemsList = vm.state.list.toList();
  132. return ListView.builder(
  133. itemCount: itemsList.length,
  134. itemBuilder: (context, index) {
  135. return _buildNewsItem(context, ref, itemsList[index], vm);
  136. },
  137. );
  138. }
  139. }
  140. @override
  141. Widget build(BuildContext context, WidgetRef ref) {
  142. final vm = ref.read(newsfeedVmProvider.notifier);
  143. return Scaffold(
  144. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  145. body: Column(
  146. children: [
  147. _buildTabsSection(context, ref, vm),
  148. _buildPostSection(context, ref, vm),
  149. // Expanded(
  150. // child: EasyRefresh(
  151. // // 上拉加载
  152. // onLoad: () async{
  153. // Log.d("----onLoad");
  154. // vm.onLoadData();
  155. // },
  156. // // 下拉刷新
  157. // onRefresh: () async{
  158. // Log.d("----onRefresh");
  159. // vm.refreshListData();
  160. // },
  161. // child: _buildNesFeedList(context, ref, vm),
  162. // ),
  163. // )
  164. Expanded(
  165. child: _buildNesFeedList(context, ref, vm),
  166. )
  167. ],
  168. ),
  169. );
  170. }
  171. }