import 'package:flutter/material.dart'; import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_bloc.dart'; import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart'; import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_sk.dart'; class HotRankingContainer extends StatefulWidget { final Map data; const HotRankingContainer({Key key, this.data}) : super(key: key); @override _HotRankingState createState() => _HotRankingState(); } class _HotRankingState extends State with TickerProviderStateMixin { HotRankingBloc _bloc; TabController _tabController; @override void initState() { _bloc = HotRankingBloc(); super.initState(); } _buildTabs() { List listWidget = List(); for (int index = 0; index < 4; index++) { listWidget.add(Tab( text: "hahah", )); } return listWidget; } @override void dispose() { _tabController.dispose(); super.dispose(); } ///构建 void createTabController() { _tabController = TabController(length: 4, vsync: this); } ///构建TabView _buildTabView() { List listWidget = List(); for (var index = 0; index < 4; index++) { listWidget.add(ListView.builder( padding: EdgeInsets.all(0), itemCount: 10, itemBuilder: (context, index) { return Container( child: HotRankingGoods(), ); })); } return listWidget; } @override Widget build(BuildContext context) { return StreamBuilder( stream: _bloc.outData, builder: (context, snapshot) { if (snapshot.data != null) { return HotRankingSkeleton(); } else { createTabController(); return Container( child: Column( children: [ TabBar( controller: _tabController, isScrollable: true, tabs: _buildTabs(), ), Expanded( child: TabBarView( controller: _tabController, children: _buildTabView())) ], ), ); } }); } }