123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- 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<HomeFollowRoomPage>{
- @override
- Widget build(BuildContext context) {
- return BlocProvider(
- create: (context)=>HomeFollowCubit(),
- child: BlocListener<AuthenticationCubit, AuthenticationState>(
- listener: (context,state){
- HomeFollowCubit bloc = BlocProvider.of<HomeFollowCubit>(context);
- bloc.myFavRoom();
- },
- child: Builder(builder: (context){
- HomeFollowCubit bloc = BlocProvider.of<HomeFollowCubit>(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<HomeFollowCubit>(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<HomeFollowCubit>(context);
- return EasyRefresh(
- onRefresh: ()async{
- listCubit.myFavRoom();
- },
- child: Builder(builder: (context){
- context.select((HomeFollowCubit bloc) => bloc.state.favRoomItems);
- HomeFollowCubit listCubit = BlocProvider.of<HomeFollowCubit>(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<HomeFollowCubit>(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<Widget>[
- SliverAppBar(
- pinned: true,
- floating: true,
- expandedHeight:600.h,
- backgroundColor: Colors.white,
- flexibleSpace: FlexibleSpaceBar(
- collapseMode: CollapseMode.pin,
- background: Container(//头部整个背景颜色
- height: double.infinity,
- child: Column(
- children: <Widget>[
- 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<HomeFollowCubit>(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<HomeFollowCubit>(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();
- }
- }
|