newsfeed_page.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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(tabsList: vm.state.tabsList, activeIndex: vm.state.activeIndex),
  34. );
  35. }
  36. Widget _buildPostSection(BuildContext context, WidgetRef ref, vm){
  37. return Container(
  38. height: 65.5,
  39. width: double.infinity,
  40. padding: const EdgeInsets.only(left: 20, right: 20),
  41. color: Colors.white,
  42. child: Row(
  43. children: [
  44. const MyAssetImage(Assets.communityNesFeed, width: 45,height: 45,),
  45. Expanded(
  46. child: Container(
  47. // height: 65.5,
  48. // color: Colors.blue,
  49. child: MyTextView(
  50. "What’s on your mind?",
  51. textColor: ColorUtils.string2Color('#000000'),
  52. fontSize: 15,
  53. marginLeft: 15,
  54. alignment: Alignment.centerLeft,
  55. textAlign: TextAlign.left,
  56. backgroundColor: ColorUtils.string2Color('#ffffff'),
  57. maxLines: 1,
  58. isFontMedium: true,
  59. ),
  60. ),
  61. ),
  62. const MyAssetImage(
  63. Assets.communityCamera,
  64. width: 21,
  65. height: 16.5,
  66. ).onTap(() {
  67. // 点击 发布的按钮
  68. vm.handlerGotoPost();
  69. }),
  70. ],
  71. ),
  72. );
  73. }
  74. Widget _buildNewsItem(BuildContext context, WidgetRef ref, item, vm){
  75. print("1111111${item}");
  76. return Container(
  77. width: double.infinity,
  78. // padding: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  79. color: Colors.yellow,
  80. child: Container(
  81. margin: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  82. color: Colors.white,
  83. padding: const EdgeInsets.only(left: 15, right: 15,top: 17,bottom: 17),
  84. height: 280,
  85. child: Column(
  86. mainAxisAlignment: MainAxisAlignment.center,
  87. crossAxisAlignment: CrossAxisAlignment.start,
  88. children: [
  89. // 卡片头部(头像 标题 时间)
  90. NewsFeedCardHeader(
  91. title: item['title'],
  92. avator: item['avator'],
  93. time: item['time'],
  94. ),
  95. const SizedBox(height: 15),
  96. // 卡片中间 (文字和图片)
  97. Expanded(
  98. child: NewsFeedCardContent(
  99. content: item['content'],
  100. imageUrls: item['imageUrls'],
  101. ),
  102. ),
  103. const SizedBox(height: 26),
  104. // // 卡片底部 (点赞 评论 分享)
  105. NewsFeedCardFooter(
  106. isLike: item['isLike'],
  107. ),
  108. ]
  109. ),
  110. )
  111. );
  112. }
  113. Widget _buildNesFeedList(BuildContext context, WidgetRef ref, vm){
  114. // return Container(
  115. // height: 100,
  116. // color: Colors.blue,
  117. // );
  118. // List items = List.generate(20, (index) => "Item $index");
  119. // List items = _vm.state.list.fromMap();
  120. final itemList = vm.state.list?? [];
  121. if(itemList.isEmpty){
  122. return const Center(child: Text('No Data'));
  123. }else {
  124. List itemsList = vm.state.list.toList();
  125. return ListView.builder(
  126. itemCount: itemsList.length,
  127. itemBuilder: (context, index) {
  128. return _buildNewsItem(context, ref, itemsList[index], vm);
  129. },
  130. );
  131. }
  132. }
  133. @override
  134. Widget build(BuildContext context, WidgetRef ref) {
  135. final vm = ref.read(newsfeedVmProvider.notifier);
  136. return Scaffold(
  137. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  138. body: Column(
  139. children: [
  140. _buildTabsSection(context, ref, vm),
  141. _buildPostSection(context, ref, vm),
  142. // Expanded(
  143. // child: EasyRefresh(
  144. // // 上拉加载
  145. // onLoad: () async{
  146. // Log.d("----onLoad");
  147. // vm.onLoadData();
  148. // },
  149. // // 下拉刷新
  150. // onRefresh: () async{
  151. // Log.d("----onRefresh");
  152. // vm.refreshListData();
  153. // },
  154. // child: _buildNesFeedList(context, ref, vm),
  155. // ),
  156. // )
  157. Expanded(
  158. child: _buildNesFeedList(context, ref, vm),
  159. )
  160. ],
  161. ),
  162. );
  163. }
  164. }