home_main_page.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import 'package:flutter/material.dart';
  2. import 'package:common_project/common_project.dart';
  3. import 'package:module_home/model/home_room_list_model.dart';
  4. import 'package:module_home/navigation/routers.dart';
  5. import 'package:module_home/view/home_follow_room_page.dart';
  6. import 'package:module_home/view/home_index_page.dart';
  7. import 'package:module_home/view_model/home_index_cubit.dart';
  8. import 'package:module_home/view/home_room_list_page.dart';
  9. class HomeMainPage extends StatefulWidget {
  10. const HomeMainPage({Key? key}) : super(key: key);
  11. @override
  12. _HomeMainPageState createState() => _HomeMainPageState();
  13. }
  14. class _HomeMainPageState extends State<HomeMainPage> with TickerProviderStateMixin {
  15. TabController? tabController;
  16. TabController? buttonController;
  17. @override
  18. void initState() {
  19. // TODO: implement initState
  20. tabController = TabController(length: 3, vsync: this);
  21. tabController!.addListener(() {
  22. });
  23. super.initState();
  24. }
  25. @override
  26. Widget build(BuildContext context) {
  27. return BlocProvider(
  28. create: (context)=>HomeIndexCubit(this,context),
  29. child: Builder(builder: (context){
  30. return Scaffold(
  31. body: Column(
  32. children: [
  33. Container(
  34. margin: EdgeInsets.only(top: Sizes.topSafeHeight),
  35. width: Sizes.width,
  36. // color: HexColor.fromHex("#D8D8D8"),
  37. padding: EdgeInsets.only(left: 32.w,right: 32.w),
  38. child: Row(
  39. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  40. children: [
  41. Container(
  42. width: 300.w,
  43. child: TabBar(
  44. controller: tabController,
  45. unselectedLabelColor: HexColor.fromHex("#635E70"),
  46. unselectedLabelStyle: TextStyle(fontSize: Sizes.fs_32),
  47. labelStyle: TextStyle(fontSize: Sizes.fs_42),
  48. labelPadding: EdgeInsets.only(left: 10.w),
  49. labelColor: HexColor.fromHex("#3E3752"),
  50. indicatorColor: Colors.transparent,
  51. tabs: [Tab(text: "关注",),Tab(text: "热门",),Tab(text: "游戏",)]
  52. ),
  53. ),
  54. InkWell(
  55. child: Container(
  56. child: ImageUtil.loadImage(ImageUtil.getImgPath("home_search"),package: ModuleName.Module_Home,width: 48.w,height: 48.h),
  57. ),
  58. onTap: (){
  59. Application.navigateTo(context: context, route: HomeRouters().searchIndex);
  60. },
  61. )
  62. ],
  63. ),
  64. ),
  65. Expanded(
  66. child: TabBarView(
  67. controller: tabController,
  68. physics: NeverScrollableScrollPhysics(),
  69. children: [
  70. HomeFollowRoomPage(),
  71. Builder(builder: (context){
  72. HomeIndexCubit homeIndexCubit = BlocProvider.of<HomeIndexCubit>(context);
  73. context.select((HomeIndexCubit bloc) => bloc.state.tabController);
  74. context.select((HomeIndexCubit bloc) => bloc.state.tabList);
  75. context.select((HomeIndexCubit bloc) => bloc.state.bannerList);
  76. return ExtendedNestedScrollView(
  77. onlyOneScrollInBody: false,
  78. headerSliverBuilder: (BuildContext context,bool innerBoxIsScrolled){
  79. return <Widget>[
  80. SliverAppBar(
  81. pinned: true,
  82. floating: true,
  83. expandedHeight:330.w,
  84. backgroundColor: HexColor.fromHex("#F4F2FC"),
  85. flexibleSpace: FlexibleSpaceBar(
  86. collapseMode: CollapseMode.pin,
  87. background: Container(//头部整个背景颜色
  88. height: double.infinity,
  89. child: Column(
  90. children: <Widget>[
  91. Container(
  92. margin: EdgeInsets.only(left: 20.w,right: 20.w),
  93. height: 180.w,
  94. child: Swiper(
  95. itemBuilder: (BuildContext context, int index) {
  96. return InkWell(child: ImageUtil.loadImage(homeIndexCubit.state.bannerList[index].bannerPic,fit: BoxFit.fill,),
  97. onTap: (){
  98. Application.navigateTo(context: context, route: RouterPath().webPage,params: {"url":homeIndexCubit.state.bannerList[index].bannerUrl});
  99. },
  100. );
  101. },
  102. itemCount: homeIndexCubit.state.bannerList.length,
  103. // viewportFraction: 0.8,
  104. pagination: new SwiperPagination(),
  105. controller: homeIndexCubit.state.swiperController,
  106. scale: 0.9,
  107. autoplay: false,
  108. loop: false,
  109. ),
  110. ),
  111. Container(
  112. height: 108.h,
  113. padding: EdgeInsets.only(left: 20.w,right: 20.w),
  114. child: Row(
  115. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  116. children: [
  117. Container(
  118. width: 344.w,
  119. height: 108.h,
  120. child: Stack(
  121. alignment: Alignment.center,
  122. children: [
  123. ImageUtil.loadImage(ImageUtil.getImgPath("home_club"),package: ModuleName.Module_Home,width: 344.w,height: 108.h),
  124. Builder(builder: (context){
  125. HomeIndexCubit bloc = BlocProvider.of<HomeIndexCubit>(context);
  126. context.select((HomeIndexCubit bloc) => bloc.state.diamondItesm);
  127. return Container(child: _rowWidget(bloc).length >0?Container(
  128. padding: EdgeInsets.only(right: 10.w,top: 10.h),
  129. child: Swiper(
  130. itemBuilder: (BuildContext context, int index){
  131. return _rowWidget(bloc)[index];
  132. },
  133. scrollDirection: Axis.vertical,
  134. itemCount: _rowWidget(bloc).length,
  135. autoplay: _rowWidget(bloc).length > 1,
  136. ),
  137. ):Container(),);
  138. })
  139. ],
  140. ),
  141. ),
  142. Container(
  143. width: 344.w,
  144. height: 108.h,
  145. child: Stack(
  146. children: [
  147. ImageUtil.loadImage(ImageUtil.getImgPath("home_send"),package: ModuleName.Module_Home,width: 344.w,height: 108.h),
  148. Builder(builder: (context){
  149. return Container(
  150. );
  151. })
  152. ],
  153. ),
  154. ),
  155. ],
  156. ),
  157. ),
  158. SizedBox(height: 20.w),
  159. ],
  160. ),
  161. ),
  162. ),
  163. bottom: ButtonsTabBar(
  164. height: 75.w,
  165. controller: homeIndexCubit.state.tabController,
  166. backgroundColor: HexColor.fromHex("#6A00FE"),
  167. unselectedBackgroundColor: Colors.white,
  168. labelStyle:
  169. TextStyle(color: Colors.white, fontWeight: FontWeight.w400),
  170. unselectedLabelStyle: TextStyle(
  171. color: Colors.black, fontWeight: FontWeight.w400),
  172. radius: 100.w,
  173. tabs: homeIndexCubit.state.tabList != [] ?
  174. homeIndexCubit.state.tabList.map<Tab>((RtcRoomCategories tab) {
  175. return Tab(
  176. text: tab.categoryName,
  177. );
  178. }).toList() :
  179. <Widget>[
  180. ],
  181. ) ,
  182. )
  183. ];
  184. },
  185. body: TabBarView(
  186. controller: homeIndexCubit.state.tabController,
  187. children:homeIndexCubit.state.tabList.map((RtcRoomCategories tab){
  188. return new HomeRoomListPage(tab.categoryId!,tab.layout);
  189. }).toList()
  190. ),
  191. );
  192. }),
  193. Container(color: Colors.red,height: 400.h,)
  194. ]
  195. )
  196. )
  197. ],
  198. ),
  199. );
  200. }),
  201. );
  202. }
  203. List<Widget> _rowWidget(HomeIndexCubit bloc){
  204. List<Widget> result = [];
  205. if(bloc.state.diamondItesm.length > 0){
  206. result.add(Row(
  207. mainAxisAlignment: MainAxisAlignment.end,
  208. children: bloc.state.diamondItesm.map((e) {
  209. int index = bloc.state.diamondItesm.indexOf(e);
  210. return _rowItem(e.userAvatar!, index + 1);
  211. }).toList(),
  212. )) ;
  213. }
  214. if(bloc.state.dustItems.length > 0){
  215. result.add(Row(
  216. mainAxisAlignment: MainAxisAlignment.end,
  217. children: bloc.state.dustItems.map((e) {
  218. int index = bloc.state.dustItems.indexOf(e);
  219. return _rowItem(e.userAvatar!, index + 1);
  220. }).toList(),
  221. ));
  222. }
  223. return result;
  224. }
  225. Widget _rowItem(String imgUrl, int index){
  226. return Container(
  227. width: 68.w,
  228. height: 68.h,
  229. child: Stack(
  230. alignment: Alignment.center,
  231. children: [
  232. ImageUtil.loadImage(ImageUtil.getImgPath("home_crown_${index}"),package: ModuleName.Module_Home,width: 68.w,height: 68),
  233. ClipOval(
  234. child: ImageUtil.loadImage(imgUrl,width: 50.w,height: 50.w),
  235. )
  236. ],
  237. ),
  238. );
  239. }
  240. }