following_page.dart 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import 'package:flutter/material.dart';
  2. import 'package:auto_route/auto_route.dart';
  3. import 'package:flutter/rendering.dart';
  4. import 'package:flutter_hooks/flutter_hooks.dart';
  5. import 'package:hooks_riverpod/hooks_riverpod.dart';
  6. import 'package:router/ext/auto_router_extensions.dart';
  7. import 'package:shared/utils/color_utils.dart';
  8. import 'package:shared/utils/log_utils.dart';
  9. import 'package:widgets/load_state_layout.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 'following_vm.dart';
  22. @RoutePage()
  23. class FollowingPage extends HookConsumerWidget {
  24. const FollowingPage({Key? key}) : super(key: key);
  25. //启动当前页面
  26. static void startInstance({BuildContext? context}) {
  27. if (context != null) {
  28. context.router.push(const FollowingPageRoute());
  29. } else {
  30. appRouter.push(const FollowingPageRoute());
  31. }
  32. }
  33. @override
  34. Widget build(BuildContext context, WidgetRef ref) {
  35. final vm = ref.read(followingVmProvider.notifier);
  36. final state = ref.watch(followingVmProvider);
  37. useEffect((){
  38. // 组件挂载时执行 - 执行接口请求
  39. Future.microtask(() => vm.initPageData());
  40. return () {
  41. // 组件卸载时执行
  42. };
  43. }, []);
  44. return Scaffold(
  45. // appBar: MyAppBar.appBar(
  46. // context,
  47. // "following",
  48. // backgroundColor: context.appColors.whiteBG,
  49. // ),
  50. // backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  51. body: Column(
  52. mainAxisSize: MainAxisSize.max,
  53. children: [
  54. Expanded(
  55. child: EasyRefresh(
  56. controller: vm.refreshController,
  57. key: UniqueKey(),
  58. onLoad: () async{
  59. Log.d("----onLoad");
  60. vm.loadMore();
  61. },
  62. onRefresh: () async{
  63. Log.d("----onRefresh");
  64. vm.onRefresh();
  65. },
  66. child: LoadStateLayout(
  67. state: state.loadingState,
  68. errorMessage: state.errorMessage,
  69. errorRetry: () {
  70. vm.retryRequest();
  71. },
  72. successSliverWidget: [
  73. SliverList(
  74. delegate: SliverChildBuilderDelegate(
  75. (context, index){
  76. return _buildNewsItem(context, ref, state.list![index], vm);
  77. },
  78. childCount: state.list!.length
  79. ),
  80. )
  81. ],
  82. ),
  83. ),
  84. )
  85. ],
  86. )
  87. );
  88. }
  89. Widget _buildNewsItem(BuildContext context, WidgetRef ref, item, vm){
  90. return Container(
  91. margin: const EdgeInsets.only(left: 15, right: 15,top: 14,bottom: 14),
  92. padding: const EdgeInsets.only(left: 15, right: 15,top: 17,bottom: 0),
  93. // height: 280,
  94. decoration: BoxDecoration(
  95. color: context.appColors.textWhite,
  96. borderRadius: BorderRadius.circular(10),
  97. boxShadow: [
  98. BoxShadow(
  99. color: ColorUtils.string2Color("#E4E7EB").withOpacity(0.5),
  100. spreadRadius: 0,
  101. blurRadius: 4,
  102. offset: const Offset(0, 4), // changes position of shadow
  103. ),
  104. ]
  105. ),
  106. child: Stack(
  107. children: [
  108. Column(
  109. mainAxisAlignment: MainAxisAlignment.center,
  110. crossAxisAlignment: CrossAxisAlignment.center,
  111. children: [
  112. // 卡片头部(头像 标题 时间)
  113. Container(
  114. child: NewsFeedCardHeader(
  115. key: UniqueKey(),
  116. title: item['title'],
  117. avator: item['avator'],
  118. time: item['time'],
  119. ),
  120. ),
  121. const SizedBox(height: 15),
  122. // 卡片中间 (文字和图片)
  123. NewsFeedCardContent(
  124. key: UniqueKey(),
  125. content: item['content'],
  126. imageUrls: item['imageUrls'],
  127. ),
  128. const SizedBox(height: 16),
  129. // // 卡片底部 (点赞 评论 分享)
  130. Container(
  131. decoration: BoxDecoration(
  132. // color: Colors.white,
  133. border: Border(
  134. top: BorderSide(color: context.appColors.dividerDefault, width: 0.5),
  135. )
  136. ),
  137. padding: const EdgeInsets.only(top: 10, bottom: 15),
  138. child: NewsFeedCardFooter(
  139. key: UniqueKey(),
  140. isLike: item['isLike'],
  141. onLike: (){
  142. vm.handlerClickActionBtn('like', item);
  143. },
  144. onComment: (){
  145. vm.handlerClickActionBtn('comments', item);
  146. },
  147. onShare: (){
  148. vm.handlerClickActionBtn('share', item);
  149. },
  150. ),
  151. ),
  152. ]
  153. ),
  154. // 右上角 关注/取消关注 按钮
  155. Visibility(
  156. visible: !item['isFollow'],
  157. child: Positioned(
  158. right: 10,
  159. top: -5,
  160. child: Container(
  161. width: 83.5,
  162. height: 45.5,
  163. alignment: Alignment.center,
  164. // decoration: BoxDecoration(
  165. // color: ColorUtils.string2Color('#4161D0'),
  166. // borderRadius: BorderRadius.circular(5),
  167. // ),
  168. child: MyButton(
  169. text: '+Follow',
  170. textColor: Colors.white,
  171. backgroundColor: ColorUtils.string2Color('#4161D0'),
  172. radius: 8,
  173. minHeight: 27.5,
  174. padding: const EdgeInsets.only(left: 5, right: 5,top:9,bottom:9),
  175. fontWeight: FontWeight.w400,
  176. fontSize: 14,
  177. onPressed: (){
  178. // Navigator.pop(context);
  179. },
  180. ),
  181. )
  182. ),
  183. )
  184. ],
  185. ),
  186. ).constrained(
  187. width: double.infinity,
  188. // height: 580,
  189. // minHeight: 300,
  190. ).onTap((){
  191. vm.handlerClickActionBtn(null, item);
  192. });
  193. }
  194. }