my_following_page.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import 'package:cpt_community/components/newsfeed_card_content.dart';
  2. import 'package:cpt_community/components/newsfeed_card_footer.dart';
  3. import 'package:cs_resources/generated/assets.dart';
  4. import 'package:cs_resources/theme/app_colors_theme.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:auto_route/auto_route.dart';
  7. import 'package:flutter/rendering.dart';
  8. import 'package:flutter_hooks/flutter_hooks.dart';
  9. import 'package:hooks_riverpod/hooks_riverpod.dart';
  10. import 'package:router/ext/auto_router_extensions.dart';
  11. import 'package:shared/utils/color_utils.dart';
  12. import 'package:shared/utils/log_utils.dart';
  13. import 'package:widgets/ext/ex_widget.dart';
  14. import 'package:widgets/my_appbar.dart';
  15. import 'package:widgets/my_load_image.dart';
  16. import 'package:widgets/my_text_view.dart';
  17. import 'package:widgets/search_app_bar.dart';
  18. import 'package:widgets/widget_export.dart';
  19. import '../../components/newfeed_card_header.dart';
  20. import '../../router/page/community_page_router.dart';
  21. import 'my_following_vm.dart';
  22. import 'my_following_tabs.dart';
  23. import 'my_following_vm.dart';
  24. final myFollowingPageTabsRouterKey = GlobalKey<AutoTabsRouterState>();
  25. @RoutePage()
  26. class MyFollowingPage extends HookConsumerWidget {
  27. const MyFollowingPage({Key? key}) : super(key: key);
  28. //启动当前页面
  29. static void startInstance({BuildContext? context}) {
  30. if (context != null) {
  31. context.router.push(const MyFollowingPageRoute());
  32. } else {
  33. appRouter.push(const MyFollowingPageRoute());
  34. }
  35. }
  36. Widget _buildTabsSection(BuildContext context, WidgetRef ref, tabsRouter, state){
  37. final vm = ref.read(myFollowingVmProvider.notifier);
  38. return Container(
  39. width: double.infinity,
  40. child: MyFollowingTabs(
  41. key: UniqueKey(),
  42. tabsList: state.tabsList,
  43. tabsRouter: tabsRouter,
  44. margin: EdgeInsets.only(top: 14,bottom: 12, left: 20, right: 20),
  45. onClickAction:(activeTabIdx){
  46. vm.handlerChangeTab.call(activeTabIdx, tabsRouter);
  47. }
  48. ),
  49. );
  50. }
  51. @override
  52. Widget build(BuildContext context, WidgetRef ref) {
  53. final vm = ref.read(myFollowingVmProvider.notifier);
  54. final state = ref.watch(myFollowingVmProvider);
  55. useEffect((){
  56. // 延迟监听
  57. WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
  58. if(myFollowingPageTabsRouterKey.currentState?.controller != null){
  59. myFollowingPageTabsRouterKey.currentState?.controller?.addListener((){
  60. vm.tabsRouterChange();
  61. });
  62. }
  63. });
  64. return (){
  65. Log.d("My_followingPage dispose");
  66. myFollowingPageTabsRouterKey.currentState?.controller?.removeListener(vm.tabsRouterChange);
  67. };
  68. },[]);
  69. PreferredSizeWidget _buildPageAppBar(BuildContext context, WidgetRef ref, state){
  70. if(state.currentPageViewIdx == 0){
  71. return state.followPageIsSearchBarStatus!? MyAppBar.searchAppBar(context, backgroundColor: context.appColors.backgroundWhite): MyAppBar.appBar(
  72. context,
  73. state.currentPageViewIdx == 0 ? "My Follow" : "My Follower",
  74. backgroundColor: context.appColors.backgroundWhite,
  75. );
  76. }else {
  77. return state.followerPageIsSearchBarStatus!? MyAppBar.searchAppBar(context, backgroundColor: context.appColors.backgroundWhite): MyAppBar.appBar(
  78. context,
  79. state.currentPageViewIdx == 0 ? "My Follow" : "My Follower",
  80. backgroundColor: context.appColors.backgroundWhite,
  81. );
  82. }
  83. }
  84. return Scaffold(
  85. appBar: _buildPageAppBar(context, ref, state),
  86. // appBar: MyAppBar.searchAppBar(context),
  87. backgroundColor: ColorUtils.string2Color("#F2F3F6"),
  88. body: Column(
  89. children:[
  90. Expanded(
  91. child: AutoTabsRouter.pageView(
  92. key: myFollowingPageTabsRouterKey,
  93. routes: const [
  94. MyFollowPageRoute(),
  95. MyFollowerPageRoute(),
  96. ],
  97. builder: (context, child, animation) {
  98. final tabsRouter = AutoTabsRouter.of(context);
  99. return Column(
  100. mainAxisSize: MainAxisSize.max,
  101. children: [
  102. _buildTabsSection(context, ref, tabsRouter, state),
  103. Expanded(
  104. child: child,
  105. )
  106. ],
  107. );
  108. },
  109. ),
  110. ),
  111. ],
  112. ),
  113. );
  114. }
  115. }