import 'package:flutter/material.dart';
import 'package:zhiying_comm/util/extension/color.dart';

///品牌详情的
class BrandDetailTabBar extends StatefulWidget {
  final TabController tabController;

  const BrandDetailTabBar({Key key, this.tabController}) : super(key: key);

  @override
  _BrandDetailTabBarState createState() => _BrandDetailTabBarState();
}

class _BrandDetailTabBarState extends State<BrandDetailTabBar>
    with TickerProviderStateMixin {
  int currentSelectIndex = 0;
  TabController tabController;

  @override
  void initState() {
    tabController = TabController(length: 3, vsync: this);
    tabController.addListener(() {
      currentSelectIndex = tabController.index;
      setState(() {});
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: HexColor.fromHex("#FFFFFF")),
      padding: EdgeInsets.only(left: 10, right: 10,top: 4,bottom: 4),
      margin: EdgeInsets.only(top: 0, left: 10, right: 10),
      child: TabBar(
        isScrollable: true,
        controller: tabController,
        tabs: _buildTabs(),
        indicatorWeight: 0.01,
      ),
    );
  }

  _buildTabs() {
    List<Widget> listWidget = List();
    for (var index = 0; index < 3; index++) {
      listWidget.add(Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              "全部",
              style:
                  TextStyle(color: HexColor.fromHex("#FFF84F45"), fontSize: 14),
            ),
            Container(
              width: 40,
              height: 2,
              color:
                  currentSelectIndex == index ? Colors.red : Colors.transparent,
            )
          ],
        ),
      ));
    }
    return listWidget;
  }
}
