123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- import 'package:flutter/material.dart';
- import 'package:common_project/common_project.dart';
- import 'package:module_home/model/home_room_list_model.dart';
- import 'package:module_home/navigation/routers.dart';
- import 'package:module_home/view/home_follow_room_page.dart';
- import 'package:module_home/view/home_index_page.dart';
- import 'package:module_home/view_model/home_index_cubit.dart';
- import 'package:module_home/view/home_room_list_page.dart';
- class HomeMainPage extends StatefulWidget {
- const HomeMainPage({Key? key}) : super(key: key);
- @override
- _HomeMainPageState createState() => _HomeMainPageState();
- }
- class _HomeMainPageState extends State<HomeMainPage> with TickerProviderStateMixin {
- TabController? tabController;
- TabController? buttonController;
- @override
- void initState() {
- // TODO: implement initState
- tabController = TabController(length: 3, vsync: this);
- tabController!.addListener(() {
- });
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return BlocProvider(
- create: (context)=>HomeIndexCubit(this,context),
- child: Builder(builder: (context){
- return Scaffold(
- body: Column(
- children: [
- Container(
- margin: EdgeInsets.only(top: Sizes.topSafeHeight),
- width: Sizes.width,
- // color: HexColor.fromHex("#D8D8D8"),
- padding: EdgeInsets.only(left: 32.w,right: 32.w),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Container(
- width: 300.w,
- child: TabBar(
- controller: tabController,
- unselectedLabelColor: HexColor.fromHex("#635E70"),
- unselectedLabelStyle: TextStyle(fontSize: Sizes.fs_32),
- labelStyle: TextStyle(fontSize: Sizes.fs_42),
- labelPadding: EdgeInsets.only(left: 10.w),
- labelColor: HexColor.fromHex("#3E3752"),
- indicatorColor: Colors.transparent,
- tabs: [Tab(text: "关注",),Tab(text: "热门",),Tab(text: "游戏",)]
- ),
- ),
- InkWell(
- child: Container(
- child: ImageUtil.loadImage(ImageUtil.getImgPath("home_search"),package: ModuleName.Module_Home,width: 48.w,height: 48.h),
- ),
- onTap: (){
- Application.navigateTo(context: context, route: HomeRouters().searchIndex);
- },
- )
- ],
- ),
- ),
- Expanded(
- child: TabBarView(
- controller: tabController,
- physics: NeverScrollableScrollPhysics(),
- children: [
- HomeFollowRoomPage(),
- Builder(builder: (context){
- HomeIndexCubit homeIndexCubit = BlocProvider.of<HomeIndexCubit>(context);
- context.select((HomeIndexCubit bloc) => bloc.state.tabController);
- context.select((HomeIndexCubit bloc) => bloc.state.tabList);
- context.select((HomeIndexCubit bloc) => bloc.state.bannerList);
- return ExtendedNestedScrollView(
- onlyOneScrollInBody: false,
- headerSliverBuilder: (BuildContext context,bool innerBoxIsScrolled){
- return <Widget>[
- SliverAppBar(
- pinned: true,
- floating: true,
- expandedHeight:330.w,
- backgroundColor: HexColor.fromHex("#F4F2FC"),
- flexibleSpace: FlexibleSpaceBar(
- collapseMode: CollapseMode.pin,
- background: Container(//头部整个背景颜色
- height: double.infinity,
- child: Column(
- children: <Widget>[
- Container(
- margin: EdgeInsets.only(left: 20.w,right: 20.w),
- height: 180.w,
- child: Swiper(
- itemBuilder: (BuildContext context, int index) {
- return InkWell(child: ImageUtil.loadImage(homeIndexCubit.state.bannerList[index].bannerPic,fit: BoxFit.fill,),
- onTap: (){
- Application.navigateTo(context: context, route: RouterPath().webPage,params: {"url":homeIndexCubit.state.bannerList[index].bannerUrl});
- },
- );
- },
- itemCount: homeIndexCubit.state.bannerList.length,
- // viewportFraction: 0.8,
- pagination: new SwiperPagination(),
- controller: homeIndexCubit.state.swiperController,
- scale: 0.9,
- autoplay: false,
- loop: false,
- ),
- ),
- Container(
- height: 108.h,
- padding: EdgeInsets.only(left: 20.w,right: 20.w),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Container(
- width: 344.w,
- height: 108.h,
- child: Stack(
- alignment: Alignment.center,
- children: [
- ImageUtil.loadImage(ImageUtil.getImgPath("home_club"),package: ModuleName.Module_Home,width: 344.w,height: 108.h),
- Builder(builder: (context){
- HomeIndexCubit bloc = BlocProvider.of<HomeIndexCubit>(context);
- context.select((HomeIndexCubit bloc) => bloc.state.diamondItesm);
- return Container(child: _rowWidget(bloc).length >0?Container(
- padding: EdgeInsets.only(right: 10.w,top: 10.h),
- child: Swiper(
- itemBuilder: (BuildContext context, int index){
- return _rowWidget(bloc)[index];
- },
- scrollDirection: Axis.vertical,
- itemCount: _rowWidget(bloc).length,
- autoplay: _rowWidget(bloc).length > 1,
- ),
- ):Container(),);
- })
- ],
- ),
- ),
- Container(
- width: 344.w,
- height: 108.h,
- child: Stack(
- children: [
- ImageUtil.loadImage(ImageUtil.getImgPath("home_send"),package: ModuleName.Module_Home,width: 344.w,height: 108.h),
- Builder(builder: (context){
- return Container(
- );
- })
- ],
- ),
- ),
- ],
- ),
- ),
- SizedBox(height: 20.w),
- ],
- ),
- ),
- ),
- bottom: ButtonsTabBar(
- height: 75.w,
- controller: homeIndexCubit.state.tabController,
- backgroundColor: HexColor.fromHex("#6A00FE"),
- unselectedBackgroundColor: Colors.white,
- labelStyle:
- TextStyle(color: Colors.white, fontWeight: FontWeight.w400),
- unselectedLabelStyle: TextStyle(
- color: Colors.black, fontWeight: FontWeight.w400),
- radius: 100.w,
- tabs: homeIndexCubit.state.tabList != [] ?
- homeIndexCubit.state.tabList.map<Tab>((RtcRoomCategories tab) {
- return Tab(
- text: tab.categoryName,
- );
- }).toList() :
- <Widget>[
- ],
- ) ,
- )
- ];
- },
- body: TabBarView(
- controller: homeIndexCubit.state.tabController,
- children:homeIndexCubit.state.tabList.map((RtcRoomCategories tab){
- return new HomeRoomListPage(tab.categoryId!,tab.layout);
- }).toList()
- ),
- );
- }),
- Container(color: Colors.red,height: 400.h,)
- ]
- )
- )
- ],
- ),
- );
- }),
- );
- }
- List<Widget> _rowWidget(HomeIndexCubit bloc){
- List<Widget> result = [];
- if(bloc.state.diamondItesm.length > 0){
- result.add(Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: bloc.state.diamondItesm.map((e) {
- int index = bloc.state.diamondItesm.indexOf(e);
- return _rowItem(e.userAvatar!, index + 1);
- }).toList(),
- )) ;
- }
- if(bloc.state.dustItems.length > 0){
- result.add(Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: bloc.state.dustItems.map((e) {
- int index = bloc.state.dustItems.indexOf(e);
- return _rowItem(e.userAvatar!, index + 1);
- }).toList(),
- ));
- }
- return result;
- }
- Widget _rowItem(String imgUrl, int index){
-
- return Container(
- width: 68.w,
- height: 68.h,
- child: Stack(
- alignment: Alignment.center,
- children: [
- ImageUtil.loadImage(ImageUtil.getImgPath("home_crown_${index}"),package: ModuleName.Module_Home,width: 68.w,height: 68),
- ClipOval(
- child: ImageUtil.loadImage(imgUrl,width: 50.w,height: 50.w),
- )
-
- ],
- ),
- );
- }
- }
|