home_follow_room_page.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. import 'package:flutter/material.dart';
  2. import 'package:common_project/common_project.dart';
  3. import 'package:module_home/model/home_hot_room_list_model.dart';
  4. import 'package:module_home/navigation/routers.dart';
  5. import 'package:module_home/view_model/home_follow_cubit.dart';
  6. class HomeFollowRoomPage extends StatefulWidget {
  7. const HomeFollowRoomPage({Key? key}) : super(key: key);
  8. @override
  9. _HomeFollowRoomPageState createState() => _HomeFollowRoomPageState();
  10. }
  11. class _HomeFollowRoomPageState extends State<HomeFollowRoomPage>{
  12. @override
  13. Widget build(BuildContext context) {
  14. return BlocProvider(
  15. create: (context)=>HomeFollowCubit(),
  16. child: BlocListener<AuthenticationCubit, AuthenticationState>(
  17. listener: (context,state){
  18. HomeFollowCubit bloc = BlocProvider.of<HomeFollowCubit>(context);
  19. bloc.myFavRoom();
  20. },
  21. child: Builder(builder: (context){
  22. HomeFollowCubit bloc = BlocProvider.of<HomeFollowCubit>(context);
  23. return Scaffold(
  24. body: _followWidget(bloc),
  25. );
  26. }),
  27. ),
  28. );
  29. }
  30. Widget _followWidget(HomeFollowCubit listCubit){
  31. return EasyRefresh(
  32. onRefresh: ()async{
  33. listCubit.myFavRoom();
  34. },
  35. child: Builder(builder: (context){
  36. context.select((HomeFollowCubit bloc) => bloc.state.favRoomItems);
  37. HomeFollowCubit listCubit = BlocProvider.of<HomeFollowCubit>(context);
  38. return listCubit.state.favRoomItems != [] && listCubit.state.favRoomItems!.length > 0 ? GridView.builder(
  39. padding: EdgeInsets.zero,
  40. shrinkWrap: true,//收缩包装
  41. scrollDirection: Axis.vertical,
  42. physics: NeverScrollableScrollPhysics(),
  43. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  44. //横轴元素个数
  45. crossAxisCount: 2,
  46. //纵轴间距
  47. mainAxisSpacing: 10.w,
  48. //横轴间距
  49. crossAxisSpacing: 10.w,
  50. //子组件宽高长度比例
  51. childAspectRatio: 1.0
  52. ),
  53. itemCount: listCubit.state.favRoomItems!.length,
  54. itemBuilder: (BuildContext context, int index) =>
  55. _gridItem(listCubit.state.favRoomItems![index])
  56. ):emptWidget();
  57. }),
  58. );
  59. return Builder(builder: (context){
  60. context.select((HomeFollowCubit bloc) => bloc.state.favRoomItems);
  61. HomeFollowCubit listCubit = BlocProvider.of<HomeFollowCubit>(context);
  62. return EasyRefresh(
  63. onRefresh: ()async{
  64. listCubit.myFavRoom();
  65. },
  66. child: Builder(builder: (context){
  67. context.select((HomeFollowCubit bloc) => bloc.state.favRoomItems);
  68. HomeFollowCubit listCubit = BlocProvider.of<HomeFollowCubit>(context);
  69. return listCubit.state.favRoomItems != [] && listCubit.state.favRoomItems!.length > 0 ? GridView.builder(
  70. padding: EdgeInsets.zero,
  71. shrinkWrap: true,//收缩包装
  72. scrollDirection: Axis.vertical,
  73. physics: NeverScrollableScrollPhysics(),
  74. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  75. //横轴元素个数
  76. crossAxisCount: 2,
  77. //纵轴间距
  78. mainAxisSpacing: 10.w,
  79. //横轴间距
  80. crossAxisSpacing: 10.w,
  81. //子组件宽高长度比例
  82. childAspectRatio: 1.0
  83. ),
  84. itemCount: listCubit.state.favRoomItems!.length,
  85. itemBuilder: (BuildContext context, int index) =>
  86. _gridItem(listCubit.state.favRoomItems![index])
  87. ):emptWidget();
  88. }),
  89. );
  90. });
  91. }
  92. Widget emptWidget(){
  93. return SingleChildScrollView(
  94. child: Column(
  95. children: [
  96. Container(
  97. child: EmptyStateLayout(hintText: '暂无关注房间', type: StateType.emptyData,),
  98. height: 600.h,
  99. ),
  100. Container(
  101. width: Sizes.width,
  102. margin: EdgeInsets.only(left: 32.w,bottom: 16.h),
  103. child: Text("房间推荐",style: TextStyle(fontSize: Sizes.fs_28,fontWeight: FontWeight.w500),),
  104. ),
  105. Builder(builder: (context){
  106. context.select((HomeFollowCubit bloc) => bloc.state.hotRoomItems);
  107. HomeFollowCubit bloc = BlocProvider.of<HomeFollowCubit>(context);
  108. return bloc.state.hotRoomItems != [] && bloc.state.hotRoomItems!.length > 0? GridView.builder(
  109. shrinkWrap: true,//收缩包装
  110. scrollDirection: Axis.vertical,
  111. padding: EdgeInsets.only(top: 10.h),
  112. physics: NeverScrollableScrollPhysics(),
  113. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  114. //横轴元素个数
  115. crossAxisCount: 2,
  116. //纵轴间距
  117. mainAxisSpacing: 10.w,
  118. //横轴间距
  119. crossAxisSpacing: 10.w,
  120. //子组件宽高长度比例
  121. childAspectRatio: 1.0
  122. ),
  123. itemCount: 4,
  124. itemBuilder: (BuildContext context, int index) =>
  125. _hotRoomtem(bloc.state.hotRoomItems![index])
  126. ):Container();
  127. })
  128. ],
  129. ),
  130. );
  131. return Container(
  132. child: ExtendedNestedScrollView(
  133. headerSliverBuilder: (BuildContext context,bool innerBoxIsScrolled){
  134. return<Widget>[
  135. SliverAppBar(
  136. pinned: true,
  137. floating: true,
  138. expandedHeight:600.h,
  139. backgroundColor: Colors.white,
  140. flexibleSpace: FlexibleSpaceBar(
  141. collapseMode: CollapseMode.pin,
  142. background: Container(//头部整个背景颜色
  143. height: double.infinity,
  144. child: Column(
  145. children: <Widget>[
  146. Container(
  147. child: EmptyStateLayout(hintText: '暂无关注房间', type: StateType.emptyData,),
  148. height: 600.h,
  149. ),
  150. ],
  151. ),
  152. ),
  153. ),
  154. bottom: PreferredSize(
  155. child: Container(
  156. width: Sizes.width,
  157. margin: EdgeInsets.only(left: 32.w,bottom: 16.h),
  158. child: Text("房间推荐",style: TextStyle(fontSize: Sizes.fs_28,fontWeight: FontWeight.w500),),
  159. ),
  160. preferredSize: Size.fromHeight(60.h),
  161. ),
  162. )
  163. ];
  164. },
  165. body: Builder(builder: (context){
  166. context.select((HomeFollowCubit bloc) => bloc.state.hotRoomItems);
  167. HomeFollowCubit bloc = BlocProvider.of<HomeFollowCubit>(context);
  168. return bloc.state.hotRoomItems != [] && bloc.state.hotRoomItems!.length > 0? GridView.builder(
  169. shrinkWrap: true,//收缩包装
  170. scrollDirection: Axis.vertical,
  171. padding: EdgeInsets.only(top: 10.h),
  172. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  173. //横轴元素个数
  174. crossAxisCount: 2,
  175. //纵轴间距
  176. mainAxisSpacing: 10.w,
  177. //横轴间距
  178. crossAxisSpacing: 10.w,
  179. //子组件宽高长度比例
  180. childAspectRatio: 1.0
  181. ),
  182. itemCount: 4,
  183. itemBuilder: (BuildContext context, int index) =>
  184. _hotRoomtem(bloc.state.hotRoomItems![index])
  185. ):Container();
  186. }),
  187. ),
  188. height: Sizes.height,
  189. );
  190. return Container(
  191. height: Sizes.height,
  192. child: Column(
  193. children: [
  194. Container(
  195. child: EmptyStateLayout(hintText: '暂无数据', type: StateType.emptyData,),
  196. height: 600.h,
  197. ),
  198. Container(
  199. margin: EdgeInsets.only(left: 32.w,bottom: 16.h),
  200. child: Row(
  201. children: [
  202. Text("房间推荐",style: TextStyle(fontSize: Sizes.fs_28,fontWeight: FontWeight.w500),)
  203. ],
  204. ),
  205. ),
  206. Expanded(child: Builder(builder: (context){
  207. context.select((HomeFollowCubit bloc) => bloc.state.hotRoomItems);
  208. HomeFollowCubit bloc = BlocProvider.of<HomeFollowCubit>(context);
  209. return bloc.state.hotRoomItems != [] && bloc.state.hotRoomItems!.length > 0? Container(
  210. child: GridView.builder(
  211. shrinkWrap: true,//收缩包装
  212. scrollDirection: Axis.vertical,
  213. // physics: NeverScrollableScrollPhysics(),
  214. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  215. //横轴元素个数
  216. crossAxisCount: 2,
  217. //纵轴间距
  218. mainAxisSpacing: 10.w,
  219. //横轴间距
  220. crossAxisSpacing: 10.w,
  221. //子组件宽高长度比例
  222. childAspectRatio: 1.0
  223. ),
  224. itemCount: 4,
  225. itemBuilder: (BuildContext context, int index) =>
  226. _hotRoomtem(bloc.state.hotRoomItems![index])
  227. ),
  228. ):Container();
  229. }))
  230. ],
  231. ),
  232. );
  233. }
  234. Widget _gridItem(FavRoomItem data){
  235. return InkWellDelay(
  236. shakeTime: 1,
  237. onTap: (){
  238. XLog.d("进入页面的次数");
  239. if(data.roomType == RoomType.RoomTypeCommon){
  240. ChatRoomManager.instance.enterRoom(context, "${data.roomId}", null,coverUrl: "${data.roomCover}");
  241. } else {
  242. ToastUtil.showToast('${S.of(context).appRoomTips}');
  243. }
  244. // Application.navigateTo(context: context, route: RouterPath().chatHome,params: {"roomId":data.roomId});
  245. },
  246. child: Container(
  247. decoration: BoxDecoration(
  248. borderRadius: BorderRadius.all(Radius.circular(16.w)),
  249. color: Colors.blue
  250. ),
  251. child: Stack(
  252. children: [
  253. Container(
  254. alignment: Alignment.center,
  255. decoration: BoxDecoration(
  256. borderRadius: BorderRadius.all(Radius.circular(16.w)),
  257. image: DecorationImage(image: ImageUtil.getImageProvider('${data.roomCover}'),fit: BoxFit.cover)
  258. ),
  259. ),
  260. Positioned(
  261. right: 0,
  262. top: 0,
  263. child: Container(
  264. alignment: Alignment.center,
  265. height: 32.h,
  266. padding: EdgeInsets.only(left: 10.w,right: 10.w),
  267. decoration: BoxDecoration(
  268. color: HexColor.fromHex("#1A191F").withOpacity(0.3),
  269. borderRadius: BorderRadius.only(topRight: Radius.circular(16.w),bottomLeft: Radius.circular(32.h))
  270. ),
  271. child: Text("${data.roomHeat}",style: TextStyle(fontSize: Sizes.fs_24,color: Colors.white),),
  272. )
  273. ),
  274. Positioned(
  275. left: 16.w,
  276. bottom: 16.h,
  277. child:Row(
  278. children: [
  279. Container(
  280. alignment: Alignment.center,
  281. height: 32.h,
  282. padding: EdgeInsets.only(left: 12.w,right: 12.w),
  283. decoration: BoxDecoration(
  284. color: HexColor.fromHex("#6A00FE"),
  285. borderRadius: BorderRadius.only(topLeft: Radius.circular(10.w),bottomLeft: Radius.circular(10.w))
  286. ),
  287. child: Text("${data.categoryName}",style: TextStyle(fontSize: Sizes.fs_20,color: Colors.white),),
  288. ),
  289. Container(
  290. height: 32.h,
  291. alignment: Alignment.center,
  292. padding: EdgeInsets.only(left: 8.w,right: 8.w),
  293. decoration: BoxDecoration(
  294. color: HexColor.fromHex("#1A191F").withOpacity(0.3),
  295. borderRadius: BorderRadius.only(topRight: Radius.circular(10.w),bottomRight: Radius.circular(10.w))
  296. ),
  297. child: Text("ID:${data.roomNo}",style: TextStyle(color: Colors.white,fontSize: Sizes.fs_20),),
  298. )
  299. ],
  300. )
  301. )
  302. ],
  303. ),
  304. ),);
  305. }
  306. Widget _hotRoomtem(HotRoomData data){
  307. return InkWellDelay(
  308. shakeTime: 1,
  309. onTap: (){
  310. XLog.d("进入页面的次数");
  311. if(data.roomType == RoomType.RoomTypeCommon){
  312. ChatRoomManager.instance.enterRoom(context, "${data.roomId}", null,coverUrl: "${data.roomCover}");
  313. } else {
  314. ToastUtil.showToast('${S.current.appRoomTips}');
  315. }
  316. // Application.navigateTo(context: context, route: RouterPath().chatHome,params: {"roomId":data.roomId});
  317. },
  318. child: Container(
  319. decoration: BoxDecoration(
  320. borderRadius: BorderRadius.all(Radius.circular(16.w)),
  321. color: Colors.blue
  322. ),
  323. child: Stack(
  324. children: [
  325. Container(
  326. alignment: Alignment.center,
  327. decoration: BoxDecoration(
  328. borderRadius: BorderRadius.all(Radius.circular(16.w)),
  329. image: DecorationImage(image: ImageUtil.getImageProvider('${data.roomCover}'),fit: BoxFit.cover)
  330. ),
  331. ),
  332. Positioned(
  333. right: 0,
  334. top: 0,
  335. child: Container(
  336. alignment: Alignment.center,
  337. height: 32.h,
  338. padding: EdgeInsets.only(left: 10.w,right: 10.w),
  339. decoration: BoxDecoration(
  340. color: HexColor.fromHex("#1A191F").withOpacity(0.3),
  341. borderRadius: BorderRadius.only(topRight: Radius.circular(16.w),bottomLeft: Radius.circular(32.h))
  342. ),
  343. child: Text("${data.roomHeat}",style: TextStyle(fontSize: Sizes.fs_24,color: Colors.white),),
  344. )
  345. ),
  346. Positioned(
  347. left: 16.w,
  348. bottom: 16.h,
  349. child:Row(
  350. children: [
  351. Container(
  352. alignment: Alignment.center,
  353. height: 32.h,
  354. padding: EdgeInsets.only(left: 12.w,right: 12.w),
  355. decoration: BoxDecoration(
  356. color: HexColor.fromHex("#6A00FE"),
  357. borderRadius: BorderRadius.only(topLeft: Radius.circular(10.w),bottomLeft: Radius.circular(10.w))
  358. ),
  359. child: Text("${data.categoryName}",style: TextStyle(fontSize: Sizes.fs_20,color: Colors.white),),
  360. ),
  361. Container(
  362. height: 32.h,
  363. alignment: Alignment.center,
  364. padding: EdgeInsets.only(left: 8.w,right: 8.w),
  365. decoration: BoxDecoration(
  366. color: HexColor.fromHex("#1A191F").withOpacity(0.3),
  367. borderRadius: BorderRadius.only(topRight: Radius.circular(10.w),bottomRight: Radius.circular(10.w))
  368. ),
  369. child: Text("ID:${data.roomNo}",style: TextStyle(color: Colors.white,fontSize: Sizes.fs_20),),
  370. )
  371. ],
  372. )
  373. )
  374. ],
  375. ),
  376. ),);
  377. }
  378. @override
  379. void dispose() {
  380. // TODO: implement dispose
  381. XLog.d("页面销毁了");
  382. super.dispose();
  383. }
  384. }