基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

224 lines
7.3 KiB

  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:tab_indicator_styler/tab_indicator_styler.dart';
  4. import 'package:zhiying_base_widget/pages/team_page/bloc/team_bloc.dart';
  5. import 'package:zhiying_base_widget/pages/team_page/bloc/team_repository.dart';
  6. import 'package:zhiying_base_widget/pages/team_page/model/team_data_model.dart';
  7. import 'package:zhiying_base_widget/pages/team_page/model/team_style_model.dart';
  8. import 'package:zhiying_base_widget/pages/team_page/notifier/team_page_notifier.dart';
  9. import 'package:zhiying_base_widget/widgets/team/appbar/team_app_bar_widget.dart';
  10. import 'package:zhiying_base_widget/widgets/team/data/team_data_widet.dart';
  11. import 'package:zhiying_base_widget/widgets/team/fans_list/team_fans_widget.dart';
  12. import 'package:zhiying_base_widget/widgets/team/filter/team_filter_widget.dart';
  13. import 'package:zhiying_base_widget/widgets/team/input/team_input_widget.dart';
  14. import 'package:zhiying_base_widget/widgets/team/recommend/team_recommend_widget.dart';
  15. import 'package:zhiying_comm/util/custom_sliver_persistent_header_delegate.dart';
  16. import 'package:zhiying_comm/zhiying_comm.dart';
  17. import 'dart:ui';
  18. import 'package:provider/provider.dart';
  19. import 'package:flutter_bloc/flutter_bloc.dart';
  20. import 'team_page_sk.dart';
  21. ///
  22. /// 我的团队
  23. ///
  24. class TeamPage extends StatelessWidget {
  25. final Map<String, dynamic> data;
  26. const TeamPage(this.data);
  27. @override
  28. Widget build(BuildContext context) {
  29. return MultiProvider(
  30. providers: [
  31. ChangeNotifierProvider.value(value: TeamPageNotifier()),
  32. ],
  33. child: BlocProvider<TeamBloc>(
  34. create: (_) => TeamBloc(repository: TeamRepository())..add(TeamInitEvent(data)),
  35. child: _TeamPageContainer(),
  36. ),
  37. );
  38. }
  39. }
  40. class _TeamPageContainer extends StatefulWidget {
  41. @override
  42. _TeamPageContainerState createState() => _TeamPageContainerState();
  43. }
  44. class _TeamPageContainerState extends State<_TeamPageContainer> {
  45. TabController _controller;
  46. // TabController 监听
  47. void _tabChangeListener(){
  48. if (!_controller.indexIsChanging) {
  49. Logger.log('this TabController is ${_controller?.index}');
  50. Provider.of<TeamPageNotifier>(context, listen: false).updateTabIndex(_controller?.index ?? 0);
  51. }
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. return BlocConsumer<TeamBloc, TeamState>(
  56. listener: (context, state) {},
  57. buildWhen: (prov, current) {
  58. if (current is TeamErrorState) {
  59. return false;
  60. }
  61. return true;
  62. },
  63. builder: (context, state) {
  64. print('TeamPage state === $state, ');
  65. if (state is TeamLoadedState) {
  66. _initTabController(state?.styleModel);
  67. return _getMainWidget(state?.styleModel, state?.dataModel);
  68. }
  69. /// 骨架屏幕
  70. return TeamPageSkeleton();
  71. },
  72. );
  73. }
  74. @override
  75. void initState() {
  76. // _controller = TabController(length: tabTitle.length, vsync: ScrollableState());
  77. super.initState();
  78. }
  79. void _initTabController(TeamStyleModel styleModel) {
  80. if (null == _controller) {
  81. _controller = TabController(length: styleModel?.userLvTabs?.length ?? 0, vsync: ScrollableState());
  82. _controller.addListener(_tabChangeListener);
  83. }
  84. }
  85. @override
  86. void dispose() {
  87. _controller?.removeListener(_tabChangeListener);
  88. _controller?.dispose();
  89. super.dispose();
  90. }
  91. /// 主体视图
  92. Widget _getMainWidget(TeamStyleModel styleModel, TeamDataModel dataModel) {
  93. return Scaffold(
  94. resizeToAvoidBottomPadding: false,
  95. resizeToAvoidBottomInset: false,
  96. backgroundColor: HexColor.fromHex(styleModel?.bgColor ?? '#F9F9F9'),
  97. body: NestedScrollView(
  98. headerSliverBuilder: (context, bool) {
  99. return [
  100. /// 头部Bar
  101. TeamAppBarWidget(styleModel),
  102. /// 我的推荐人
  103. SliverToBoxAdapter(child: TeamRecommendWidget(styleModel, dataModel)),
  104. /// 数据
  105. SliverToBoxAdapter(child: TeamDataWidget(styleModel, dataModel)),
  106. /// 间距
  107. SliverToBoxAdapter(child: SizedBox(height: 8)),
  108. /// 输入框
  109. SliverPersistentHeader(delegate: CustomSliverPersistentHeaderDelegate(min: 34, max: 34, child: TeamInputWidget(styleModel)), pinned: true),
  110. /// 悬停TabBar
  111. SliverPersistentHeader(
  112. delegate: new _SliverTabBarDelegate(
  113. tabBar: TabBar(
  114. isScrollable: false,
  115. labelStyle: TextStyle(fontWeight: FontWeight.bold, fontSize: 13),
  116. unselectedLabelStyle: TextStyle(fontSize: 13),
  117. indicator: MaterialIndicator(
  118. height: 2,
  119. topLeftRadius: 8,
  120. topRightRadius: 8,
  121. bottomLeftRadius: 8,
  122. bottomRightRadius: 8,
  123. color: HexColor.fromHex(styleModel?.userLvTabsLineColor ?? '#F94B47'),
  124. horizontalPadding: 30,
  125. ),
  126. controller: _controller,
  127. // tabs: tabTitle.map((f) => Tab(text: f)).toList(),
  128. tabs: styleModel.userLvTabs
  129. .map((item) => Tab(
  130. text: item.name,
  131. ))
  132. .toList(),
  133. indicatorColor: Colors.red,
  134. unselectedLabelColor: HexColor.fromHex(styleModel?.userLvTabsNameColor ?? '#999999'),
  135. labelColor: HexColor.fromHex(styleModel?.userLvTabsNameSelectedColor ?? '#000000'),
  136. ),
  137. ),
  138. pinned: true,
  139. ),
  140. /// 筛选条件
  141. SliverPersistentHeader(delegate: CustomSliverPersistentHeaderDelegate(max: 32.5, min: 32.5, child: TeamFilterWidget(styleModel)), pinned: true),
  142. ];
  143. },
  144. body: MediaQuery.removePadding(
  145. removeTop: true,
  146. context: context,
  147. // child: TabBarView(controller: _controller, children: tabTitle.map((s) => TeamFansWidget(styleModel)).toList()),
  148. child: TabBarView(
  149. controller: _controller,
  150. children: _buildTabBarView(styleModel),
  151. // children: styleModel.userLvTabs.map((item) => TeamFansWidget(styleModel, item.type, )).toList(),
  152. ),
  153. ),
  154. ),
  155. );
  156. }
  157. /// 创建TabBarView
  158. List<Widget> _buildTabBarView(TeamStyleModel styleModel){
  159. List<Widget> lists = [];
  160. int length = styleModel?.userLvTabs?.length ?? 0;
  161. if(length > 0) {
  162. for (int i = 0; i < styleModel.userLvTabs.length; i ++) {
  163. UserLvTabs item = styleModel.userLvTabs[i];
  164. lists.add(TeamFansWidget(styleModel, item.type, i));
  165. }
  166. }else{
  167. lists.add(Container());
  168. }
  169. return lists;
  170. }
  171. }
  172. class _SliverTabBarDelegate extends SliverPersistentHeaderDelegate {
  173. final TabBar tabBar;
  174. const _SliverTabBarDelegate({this.tabBar}) : assert(tabBar != null);
  175. @override
  176. Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
  177. return Container(
  178. color: Colors.white,
  179. child: tabBar,
  180. );
  181. }
  182. @override
  183. bool shouldRebuild(_SliverTabBarDelegate oldDelegate) {
  184. return false;
  185. }
  186. @override
  187. double get maxExtent => tabBar.preferredSize.height;
  188. @override
  189. double get minExtent => tabBar.preferredSize.height;
  190. }