import 'package:flutter/material.dart'; import 'package:common_project/common_project.dart'; import 'package:module_home/model/home_hot_room_list_model.dart'; import 'package:module_home/navigation/routers.dart'; import 'package:module_home/view_model/home_follow_cubit.dart'; class HomeFollowRoomPage extends StatefulWidget { const HomeFollowRoomPage({Key? key}) : super(key: key); @override _HomeFollowRoomPageState createState() => _HomeFollowRoomPageState(); } class _HomeFollowRoomPageState extends State{ @override Widget build(BuildContext context) { return BlocProvider( create: (context)=>HomeFollowCubit(), child: BlocListener( listener: (context,state){ HomeFollowCubit bloc = BlocProvider.of(context); bloc.myFavRoom(); }, child: Builder(builder: (context){ HomeFollowCubit bloc = BlocProvider.of(context); return Scaffold( body: _followWidget(bloc), ); }), ), ); } Widget _followWidget(HomeFollowCubit listCubit){ return EasyRefresh( onRefresh: ()async{ listCubit.myFavRoom(); }, child: Builder(builder: (context){ context.select((HomeFollowCubit bloc) => bloc.state.favRoomItems); HomeFollowCubit listCubit = BlocProvider.of(context); return listCubit.state.favRoomItems != [] && listCubit.state.favRoomItems!.length > 0 ? GridView.builder( padding: EdgeInsets.zero, shrinkWrap: true,//收缩包装 scrollDirection: Axis.vertical, physics: NeverScrollableScrollPhysics(), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( //横轴元素个数 crossAxisCount: 2, //纵轴间距 mainAxisSpacing: 10.w, //横轴间距 crossAxisSpacing: 10.w, //子组件宽高长度比例 childAspectRatio: 1.0 ), itemCount: listCubit.state.favRoomItems!.length, itemBuilder: (BuildContext context, int index) => _gridItem(listCubit.state.favRoomItems![index]) ):emptWidget(); }), ); return Builder(builder: (context){ context.select((HomeFollowCubit bloc) => bloc.state.favRoomItems); HomeFollowCubit listCubit = BlocProvider.of(context); return EasyRefresh( onRefresh: ()async{ listCubit.myFavRoom(); }, child: Builder(builder: (context){ context.select((HomeFollowCubit bloc) => bloc.state.favRoomItems); HomeFollowCubit listCubit = BlocProvider.of(context); return listCubit.state.favRoomItems != [] && listCubit.state.favRoomItems!.length > 0 ? GridView.builder( padding: EdgeInsets.zero, shrinkWrap: true,//收缩包装 scrollDirection: Axis.vertical, physics: NeverScrollableScrollPhysics(), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( //横轴元素个数 crossAxisCount: 2, //纵轴间距 mainAxisSpacing: 10.w, //横轴间距 crossAxisSpacing: 10.w, //子组件宽高长度比例 childAspectRatio: 1.0 ), itemCount: listCubit.state.favRoomItems!.length, itemBuilder: (BuildContext context, int index) => _gridItem(listCubit.state.favRoomItems![index]) ):emptWidget(); }), ); }); } Widget emptWidget(){ return SingleChildScrollView( child: Column( children: [ Container( child: EmptyStateLayout(hintText: '暂无关注房间', type: StateType.emptyData,), height: 600.h, ), Container( width: Sizes.width, margin: EdgeInsets.only(left: 32.w,bottom: 16.h), child: Text("房间推荐",style: TextStyle(fontSize: Sizes.fs_28,fontWeight: FontWeight.w500),), ), Builder(builder: (context){ context.select((HomeFollowCubit bloc) => bloc.state.hotRoomItems); HomeFollowCubit bloc = BlocProvider.of(context); return bloc.state.hotRoomItems != [] && bloc.state.hotRoomItems!.length > 0? GridView.builder( shrinkWrap: true,//收缩包装 scrollDirection: Axis.vertical, padding: EdgeInsets.only(top: 10.h), physics: NeverScrollableScrollPhysics(), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( //横轴元素个数 crossAxisCount: 2, //纵轴间距 mainAxisSpacing: 10.w, //横轴间距 crossAxisSpacing: 10.w, //子组件宽高长度比例 childAspectRatio: 1.0 ), itemCount: 4, itemBuilder: (BuildContext context, int index) => _hotRoomtem(bloc.state.hotRoomItems![index]) ):Container(); }) ], ), ); return Container( child: ExtendedNestedScrollView( headerSliverBuilder: (BuildContext context,bool innerBoxIsScrolled){ return[ SliverAppBar( pinned: true, floating: true, expandedHeight:600.h, backgroundColor: Colors.white, flexibleSpace: FlexibleSpaceBar( collapseMode: CollapseMode.pin, background: Container(//头部整个背景颜色 height: double.infinity, child: Column( children: [ Container( child: EmptyStateLayout(hintText: '暂无关注房间', type: StateType.emptyData,), height: 600.h, ), ], ), ), ), bottom: PreferredSize( child: Container( width: Sizes.width, margin: EdgeInsets.only(left: 32.w,bottom: 16.h), child: Text("房间推荐",style: TextStyle(fontSize: Sizes.fs_28,fontWeight: FontWeight.w500),), ), preferredSize: Size.fromHeight(60.h), ), ) ]; }, body: Builder(builder: (context){ context.select((HomeFollowCubit bloc) => bloc.state.hotRoomItems); HomeFollowCubit bloc = BlocProvider.of(context); return bloc.state.hotRoomItems != [] && bloc.state.hotRoomItems!.length > 0? GridView.builder( shrinkWrap: true,//收缩包装 scrollDirection: Axis.vertical, padding: EdgeInsets.only(top: 10.h), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( //横轴元素个数 crossAxisCount: 2, //纵轴间距 mainAxisSpacing: 10.w, //横轴间距 crossAxisSpacing: 10.w, //子组件宽高长度比例 childAspectRatio: 1.0 ), itemCount: 4, itemBuilder: (BuildContext context, int index) => _hotRoomtem(bloc.state.hotRoomItems![index]) ):Container(); }), ), height: Sizes.height, ); return Container( height: Sizes.height, child: Column( children: [ Container( child: EmptyStateLayout(hintText: '暂无数据', type: StateType.emptyData,), height: 600.h, ), Container( margin: EdgeInsets.only(left: 32.w,bottom: 16.h), child: Row( children: [ Text("房间推荐",style: TextStyle(fontSize: Sizes.fs_28,fontWeight: FontWeight.w500),) ], ), ), Expanded(child: Builder(builder: (context){ context.select((HomeFollowCubit bloc) => bloc.state.hotRoomItems); HomeFollowCubit bloc = BlocProvider.of(context); return bloc.state.hotRoomItems != [] && bloc.state.hotRoomItems!.length > 0? Container( child: GridView.builder( shrinkWrap: true,//收缩包装 scrollDirection: Axis.vertical, // physics: NeverScrollableScrollPhysics(), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( //横轴元素个数 crossAxisCount: 2, //纵轴间距 mainAxisSpacing: 10.w, //横轴间距 crossAxisSpacing: 10.w, //子组件宽高长度比例 childAspectRatio: 1.0 ), itemCount: 4, itemBuilder: (BuildContext context, int index) => _hotRoomtem(bloc.state.hotRoomItems![index]) ), ):Container(); })) ], ), ); } Widget _gridItem(FavRoomItem data){ return InkWellDelay( shakeTime: 1, onTap: (){ XLog.d("进入页面的次数"); if(data.roomType == RoomType.RoomTypeCommon){ ChatRoomManager.instance.enterRoom(context, "${data.roomId}", null,coverUrl: "${data.roomCover}"); } else { ToastUtil.showToast('${S.of(context).appRoomTips}'); } // Application.navigateTo(context: context, route: RouterPath().chatHome,params: {"roomId":data.roomId}); }, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(16.w)), color: Colors.blue ), child: Stack( children: [ Container( alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(16.w)), image: DecorationImage(image: ImageUtil.getImageProvider('${data.roomCover}'),fit: BoxFit.cover) ), ), Positioned( right: 0, top: 0, child: Container( alignment: Alignment.center, height: 32.h, padding: EdgeInsets.only(left: 10.w,right: 10.w), decoration: BoxDecoration( color: HexColor.fromHex("#1A191F").withOpacity(0.3), borderRadius: BorderRadius.only(topRight: Radius.circular(16.w),bottomLeft: Radius.circular(32.h)) ), child: Text("${data.roomHeat}",style: TextStyle(fontSize: Sizes.fs_24,color: Colors.white),), ) ), Positioned( left: 16.w, bottom: 16.h, child:Row( children: [ Container( alignment: Alignment.center, height: 32.h, padding: EdgeInsets.only(left: 12.w,right: 12.w), decoration: BoxDecoration( color: HexColor.fromHex("#6A00FE"), borderRadius: BorderRadius.only(topLeft: Radius.circular(10.w),bottomLeft: Radius.circular(10.w)) ), child: Text("${data.categoryName}",style: TextStyle(fontSize: Sizes.fs_20,color: Colors.white),), ), Container( height: 32.h, alignment: Alignment.center, padding: EdgeInsets.only(left: 8.w,right: 8.w), decoration: BoxDecoration( color: HexColor.fromHex("#1A191F").withOpacity(0.3), borderRadius: BorderRadius.only(topRight: Radius.circular(10.w),bottomRight: Radius.circular(10.w)) ), child: Text("ID:${data.roomNo}",style: TextStyle(color: Colors.white,fontSize: Sizes.fs_20),), ) ], ) ) ], ), ),); } Widget _hotRoomtem(HotRoomData data){ return InkWellDelay( shakeTime: 1, onTap: (){ XLog.d("进入页面的次数"); if(data.roomType == RoomType.RoomTypeCommon){ ChatRoomManager.instance.enterRoom(context, "${data.roomId}", null,coverUrl: "${data.roomCover}"); } else { ToastUtil.showToast('${S.current.appRoomTips}'); } // Application.navigateTo(context: context, route: RouterPath().chatHome,params: {"roomId":data.roomId}); }, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(16.w)), color: Colors.blue ), child: Stack( children: [ Container( alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(16.w)), image: DecorationImage(image: ImageUtil.getImageProvider('${data.roomCover}'),fit: BoxFit.cover) ), ), Positioned( right: 0, top: 0, child: Container( alignment: Alignment.center, height: 32.h, padding: EdgeInsets.only(left: 10.w,right: 10.w), decoration: BoxDecoration( color: HexColor.fromHex("#1A191F").withOpacity(0.3), borderRadius: BorderRadius.only(topRight: Radius.circular(16.w),bottomLeft: Radius.circular(32.h)) ), child: Text("${data.roomHeat}",style: TextStyle(fontSize: Sizes.fs_24,color: Colors.white),), ) ), Positioned( left: 16.w, bottom: 16.h, child:Row( children: [ Container( alignment: Alignment.center, height: 32.h, padding: EdgeInsets.only(left: 12.w,right: 12.w), decoration: BoxDecoration( color: HexColor.fromHex("#6A00FE"), borderRadius: BorderRadius.only(topLeft: Radius.circular(10.w),bottomLeft: Radius.circular(10.w)) ), child: Text("${data.categoryName}",style: TextStyle(fontSize: Sizes.fs_20,color: Colors.white),), ), Container( height: 32.h, alignment: Alignment.center, padding: EdgeInsets.only(left: 8.w,right: 8.w), decoration: BoxDecoration( color: HexColor.fromHex("#1A191F").withOpacity(0.3), borderRadius: BorderRadius.only(topRight: Radius.circular(10.w),bottomRight: Radius.circular(10.w)) ), child: Text("ID:${data.roomNo}",style: TextStyle(color: Colors.white,fontSize: Sizes.fs_20),), ) ], ) ) ], ), ),); } @override void dispose() { // TODO: implement dispose XLog.d("页面销毁了"); super.dispose(); } }