123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import 'package:bloc/bloc.dart';
- import 'package:flutter/material.dart';
- import 'package:meta/meta.dart';
- import 'package:common_project/public_model/init_config_model.dart';
- import 'package:common_project/common_project.dart';
- import 'package:module_home/dso/apis/home_main_api.dart';
- import 'package:module_home/model/home_banner_model.dart';
- import 'package:module_home/model/home_diamond_rank_model.dart';
- import 'package:module_home/model/home_dust_rank_model.dart';
- part 'home_index_state.dart';
- class HomeIndexCubit extends Cubit<HomeIndexState> {
- TickerProvider vsyncV;
- BuildContext?context;
- HomeIndexCubit(this.vsyncV,this.context) : super(HomeIndexState().init(vsyncV)){
- getBannerHttp();
- requestDiamondList();
- requestDustList();
- setTabBar(context!);
- state.tabController.addListener(() {
- XLog.d("滑动到哪里了------${state.tabController.index}");
- XLog.d("之前滑动哪里里------${state.tabController.previousIndex}");
- });
- }
- void setTabBar(BuildContext context){
- ConfigCubit configBloc = BlocProvider.of<ConfigCubit>(context);
- if(configBloc.state.configModelData.channelConfig != null){
- if(configBloc.state.configModelData.channelConfig!.rtcRoomCategories != null){
- XLog.d("-0--00${configBloc.state.configModelData.channelConfig?.rtcRoomCategories}");
- setTabString(configBloc.state.configModelData.channelConfig!.rtcRoomCategories!);
- }
- }
- }
- setTabString(List<RtcRoomCategories> list){
- XLog.d("-0--00${list}");
- emit(state.clone()..tabList = list..tabController = TabController(length: list.length, vsync: vsyncV));
- }
- getBannerHttp() async {
- HomeBannerModel bannerModel = await HomeMainApi.getBanners();
- if(bannerModel.code.toString() == 'OK' && bannerModel.data != null){
- emit(state.clone()..bannerList = bannerModel.data!.list!);
- state.swiperController.startAutoplay();
- }
- }
- void requestDiamondList()async{
- HomeDiamondRankModel model = await HomeMainApi.getDiamondRankDay("0");
- if(model.success == true && model.data != null){
- if(model.data!.list != null){
- List<DiamondList> result = [];
- if(model.data!.list!.length >3){
- result.add(model.data!.list![0]);
- result.add(model.data!.list![1]);
- result.add(model.data!.list![2]);
- } else {
- result.addAll(model.data!.list!);
- }
- if(result.length > 0){
- emit(state.clone()..diamondItesm = result);
- }
- }
- }
- }
- void requestDustList()async{
- HomeDustRankModel model = await HomeMainApi.getDustRankDay("0");
- if(model.success == true && model.data != null){
- if(model.data!.list != null){
- List<DustList> result = [];
- if(model.data!.list!.length > 3){
- result.add(model.data!.list![0]);
- result.add(model.data!.list![1]);
- result.add(model.data!.list![2]);
- } else {
- result.addAll(model.data!.list!);
- }
- if(result.length > 0){
- emit(state.clone()..dustItems = result);
- }
- }
- }
- }
- }
|