基础组件库
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

hot_ranking_container.dart 2.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import 'package:flutter/material.dart';
  2. import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_bloc.dart';
  3. import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_goods/hot_ranking_goods.dart';
  4. import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_sk.dart';
  5. class HotRankingContainer extends StatefulWidget {
  6. final Map<String, dynamic> data;
  7. const HotRankingContainer({Key key, this.data}) : super(key: key);
  8. @override
  9. _HotRankingState createState() => _HotRankingState();
  10. }
  11. class _HotRankingState extends State<HotRankingContainer>
  12. with TickerProviderStateMixin {
  13. HotRankingBloc _bloc;
  14. TabController _tabController;
  15. @override
  16. void initState() {
  17. _bloc = HotRankingBloc();
  18. super.initState();
  19. }
  20. _buildTabs() {
  21. List<Widget> listWidget = List();
  22. for (int index = 0; index < 4; index++) {
  23. listWidget.add(Tab(
  24. text: "hahah",
  25. ));
  26. }
  27. return listWidget;
  28. }
  29. @override
  30. void dispose() {
  31. _tabController.dispose();
  32. super.dispose();
  33. }
  34. ///构建
  35. void createTabController() {
  36. _tabController = TabController(length: 4, vsync: this);
  37. }
  38. ///构建TabView
  39. _buildTabView() {
  40. List<Widget> listWidget = List();
  41. for (var index = 0; index < 4; index++) {
  42. listWidget.add(ListView.builder(
  43. padding: EdgeInsets.all(0),
  44. itemCount: 10,
  45. itemBuilder: (context, index) {
  46. return Container(
  47. child: HotRankingGoods(),
  48. );
  49. }));
  50. }
  51. return listWidget;
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. return StreamBuilder(
  56. stream: _bloc.outData,
  57. builder: (context, snapshot) {
  58. if (snapshot.data != null) {
  59. return HotRankingSkeleton();
  60. } else {
  61. createTabController();
  62. return Container(
  63. child: Column(
  64. children: <Widget>[
  65. TabBar(
  66. controller: _tabController,
  67. isScrollable: true,
  68. tabs: _buildTabs(),
  69. ),
  70. Expanded(
  71. child: TabBarView(
  72. controller: _tabController,
  73. children: _buildTabView()))
  74. ],
  75. ),
  76. );
  77. }
  78. });
  79. }
  80. }