home_index_page.dart 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:common_project/common_project.dart';
  4. import 'package:module_home/navigation/routers.dart';
  5. import 'package:module_home/view/home_room_list_page.dart';
  6. import 'package:module_home/view_model/home_index_cubit.dart';
  7. import 'package:common_project/public_model/init_config_model.dart';
  8. class HomeIndexPage extends StatefulWidget {
  9. @override
  10. _HomeIndexPageState createState() => _HomeIndexPageState();
  11. }
  12. class _HomeIndexPageState extends State<HomeIndexPage> with TickerProviderStateMixin{
  13. @override
  14. Widget build(BuildContext context) {
  15. return BlocProvider(
  16. create: (context) => HomeIndexCubit(this,context),
  17. child: BlocListener<ConfigCubit,ConfigState>(
  18. listener: (context,state){
  19. if(state.timeTemp != 0 && state.configselect){
  20. HomeIndexCubit homeIndexCubit = BlocProvider.of<HomeIndexCubit>(context);
  21. homeIndexCubit.setTabString(state.configModelData.channelConfig!.rtcRoomCategories!);
  22. }
  23. },
  24. child: Builder(builder: (context){
  25. HomeIndexCubit homeIndexCubit = BlocProvider.of<HomeIndexCubit>(context);
  26. context.select((HomeIndexCubit bloc) => bloc.state.tabController);
  27. context.select((HomeIndexCubit bloc) => bloc.state.tabList);
  28. context.select((HomeIndexCubit bloc) => bloc.state.bannerList);
  29. return Scaffold(
  30. body: homeIndexCubit.state.tabList != [] ?
  31. ExtendedNestedScrollView(
  32. onlyOneScrollInBody: false,
  33. headerSliverBuilder: (BuildContext context,bool innerBoxIsScrolled){
  34. return <Widget>[
  35. SliverAppBar(
  36. pinned: true,
  37. floating: true,
  38. expandedHeight:400.w + 200.h,
  39. backgroundColor: Colors.white,
  40. flexibleSpace: FlexibleSpaceBar(
  41. collapseMode: CollapseMode.pin,
  42. background: Container(//头部整个背景颜色
  43. height: double.infinity,
  44. child: Column(
  45. children: <Widget>[
  46. SizedBox(height: Sizes.statusBarHeight+10.w,),
  47. InkWell(
  48. onTap: (){
  49. XLog.d('点击了搜索');
  50. Application.navigateTo(context: context, route: HomeRouters().searchIndex);
  51. },
  52. child: Row(
  53. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  54. children: [
  55. Expanded(
  56. child: Container(
  57. margin: EdgeInsets.only(left: 24.w,right: 24.w),
  58. height: 75.w,
  59. padding: EdgeInsets.only(left: 24.w),
  60. alignment: Alignment.centerLeft,
  61. decoration: BoxDecoration(
  62. borderRadius: BorderRadius.all(Radius.circular(40.w)),
  63. color: HexColor.fromHex("#F7F7FA")
  64. ),
  65. child: Row(
  66. children: [
  67. ImageUtil.loadImage(ImageUtil.getImgPath('icon_search'),package: ModuleName.Module_project,width: 32.w,height: 32.w),
  68. SizedBox(width: 10.w,),
  69. Text('搜索昵称、ID'),
  70. ],
  71. ),
  72. ),)
  73. ],
  74. ),
  75. ),
  76. SizedBox(height: 20.w),
  77. Container(
  78. margin: EdgeInsets.only(left: 20.w,right: 20.w),
  79. height: 180.w,
  80. child: Swiper(
  81. itemBuilder: (BuildContext context, int index) {
  82. return InkWell(child: ImageUtil.loadImage(homeIndexCubit.state.bannerList[index].bannerPic,fit: BoxFit.fill,),
  83. onTap: (){
  84. Application.navigateTo(context: context, route: RouterPath().webPage,params: {"url":homeIndexCubit.state.bannerList[index].bannerUrl});
  85. },
  86. );
  87. },
  88. itemCount: homeIndexCubit.state.bannerList.length,
  89. // viewportFraction: 0.8,
  90. pagination: new SwiperPagination(),
  91. controller: homeIndexCubit.state.swiperController,
  92. scale: 0.9,
  93. autoplay: false,
  94. loop: false,
  95. ),
  96. ),
  97. Container(
  98. height: 200.h,
  99. padding: EdgeInsets.only(left: 20.w,right: 20.w),
  100. child: Row(
  101. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  102. children: [
  103. Container(
  104. width: 344.w,
  105. height: 108.h,
  106. child: Stack(
  107. children: [
  108. ImageUtil.loadImage(ImageUtil.getImgPath("home_club"),package: ModuleName.Module_Home,width: 344.w,height: 108.h)
  109. ],
  110. ),
  111. ),
  112. Container(
  113. width: 344.w,
  114. height: 108.h,
  115. child: Stack(
  116. children: [
  117. ImageUtil.loadImage(ImageUtil.getImgPath("home_send"),package: ModuleName.Module_Home,width: 344.w,height: 108.h)
  118. ],
  119. ),
  120. ),
  121. ],
  122. ),
  123. color: Colors.orange,
  124. ),
  125. SizedBox(height: 20.w),
  126. ],
  127. ),
  128. ),
  129. ),
  130. bottom: ButtonsTabBar(
  131. height: 75.w,
  132. controller: homeIndexCubit.state.tabController,
  133. backgroundColor: Color(0xffec2e2e),
  134. unselectedBackgroundColor: Color(0xd000000),
  135. labelStyle:
  136. TextStyle(color: Colors.white, fontWeight: FontWeight.w400),
  137. unselectedLabelStyle: TextStyle(
  138. color: Color(0xff827979), fontWeight: FontWeight.w400),
  139. radius: 100.w,
  140. tabs: homeIndexCubit.state.tabList != [] ?
  141. homeIndexCubit.state.tabList.map<Tab>((RtcRoomCategories tab) {
  142. return Tab(
  143. text: tab.categoryName,
  144. );
  145. }).toList() :
  146. <Widget>[
  147. ],
  148. ) ,
  149. )
  150. ];
  151. },
  152. body: Container(
  153. margin: EdgeInsets.only(top: 20.w,right: 20.w,left: 20.w),
  154. child: TabBarView(
  155. controller: homeIndexCubit.state.tabController,
  156. children: homeIndexCubit.state.tabList.map((RtcRoomCategories tab){
  157. return new HomeRoomListPage(tab.categoryId!,tab.layout);
  158. }).toList(),
  159. ),
  160. ),
  161. ) : Container(),
  162. );
  163. }),),
  164. );
  165. }
  166. @override
  167. void dispose() {
  168. // TODO: implement dispose
  169. HomeIndexCubit homeIndexCubit = BlocProvider.of<HomeIndexCubit>(context);
  170. homeIndexCubit.state.swiperController.stopAutoplay();
  171. homeIndexCubit.state.swiperController.dispose();
  172. super.dispose();
  173. }
  174. }