home_index_cubit.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import 'package:bloc/bloc.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:meta/meta.dart';
  4. import 'package:common_project/public_model/init_config_model.dart';
  5. import 'package:common_project/common_project.dart';
  6. import 'package:module_home/dso/apis/home_main_api.dart';
  7. import 'package:module_home/model/home_banner_model.dart';
  8. import 'package:module_home/model/home_diamond_rank_model.dart';
  9. import 'package:module_home/model/home_dust_rank_model.dart';
  10. part 'home_index_state.dart';
  11. class HomeIndexCubit extends Cubit<HomeIndexState> {
  12. TickerProvider vsyncV;
  13. BuildContext?context;
  14. HomeIndexCubit(this.vsyncV,this.context) : super(HomeIndexState().init(vsyncV)){
  15. getBannerHttp();
  16. requestDiamondList();
  17. requestDustList();
  18. setTabBar(context!);
  19. state.tabController.addListener(() {
  20. XLog.d("滑动到哪里了------${state.tabController.index}");
  21. XLog.d("之前滑动哪里里------${state.tabController.previousIndex}");
  22. });
  23. }
  24. void setTabBar(BuildContext context){
  25. ConfigCubit configBloc = BlocProvider.of<ConfigCubit>(context);
  26. if(configBloc.state.configModelData.channelConfig != null){
  27. if(configBloc.state.configModelData.channelConfig!.rtcRoomCategories != null){
  28. XLog.d("-0--00${configBloc.state.configModelData.channelConfig?.rtcRoomCategories}");
  29. setTabString(configBloc.state.configModelData.channelConfig!.rtcRoomCategories!);
  30. }
  31. }
  32. }
  33. setTabString(List<RtcRoomCategories> list){
  34. XLog.d("-0--00${list}");
  35. emit(state.clone()..tabList = list..tabController = TabController(length: list.length, vsync: vsyncV));
  36. }
  37. getBannerHttp() async {
  38. HomeBannerModel bannerModel = await HomeMainApi.getBanners();
  39. if(bannerModel.code.toString() == 'OK' && bannerModel.data != null){
  40. emit(state.clone()..bannerList = bannerModel.data!.list!);
  41. state.swiperController.startAutoplay();
  42. }
  43. }
  44. void requestDiamondList()async{
  45. HomeDiamondRankModel model = await HomeMainApi.getDiamondRankDay("0");
  46. if(model.success == true && model.data != null){
  47. if(model.data!.list != null){
  48. List<DiamondList> result = [];
  49. if(model.data!.list!.length >3){
  50. result.add(model.data!.list![0]);
  51. result.add(model.data!.list![1]);
  52. result.add(model.data!.list![2]);
  53. } else {
  54. result.addAll(model.data!.list!);
  55. }
  56. if(result.length > 0){
  57. emit(state.clone()..diamondItesm = result);
  58. }
  59. }
  60. }
  61. }
  62. void requestDustList()async{
  63. HomeDustRankModel model = await HomeMainApi.getDustRankDay("0");
  64. if(model.success == true && model.data != null){
  65. if(model.data!.list != null){
  66. List<DustList> result = [];
  67. if(model.data!.list!.length > 3){
  68. result.add(model.data!.list![0]);
  69. result.add(model.data!.list![1]);
  70. result.add(model.data!.list![2]);
  71. } else {
  72. result.addAll(model.data!.list!);
  73. }
  74. if(result.length > 0){
  75. emit(state.clone()..dustItems = result);
  76. }
  77. }
  78. }
  79. }
  80. }