import 'package:flutter/material.dart';

class HomeGoodsTab extends StatefulWidget {
  @override
  _HomeGoodsTabState createState() => _HomeGoodsTabState();
}

class _HomeGoodsTabState extends State<HomeGoodsTab>
    with TickerProviderStateMixin {
  TabController _tabController;

  @override
  void initState() {
    _tabController = TabController(length: 3, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> _silverBuilder(BuildContext context, bool innerBoxIsScrolled) {
      return <Widget>[
        SliverAppBar(),
        SliverPersistentHeader(
          pinned: true,
          delegate: _SilverAppBarDelegate(
            Container(
              color: Colors.amber,
              child: TabBar(
                labelColor: Colors.blue,
                unselectedLabelColor: Colors.black,
                controller: _tabController,
                tabs: <Widget>[
                  new Tab(
                    text: "tab1",
                  ),
                  new Tab(
                    text: "tab2",
                  ),
                  new Tab(
                    text: "tab3",
                  ),
                ],
              ),
            ),
          ),
        ),
      ];
    }

    return SliverPersistentHeader(
      pinned: true,
      delegate: _SilverAppBarDelegate(
        Container(
          color: Colors.amber,
          child: TabBar(
            labelColor: Colors.blue,
            unselectedLabelColor: Colors.black,
            controller: _tabController,
            tabs: <Widget>[
              new Tab(
                text: "tab1",
              ),
              new Tab(
                text: "tab2",
              ),
              new Tab(
                text: "tab3",
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class _SilverAppBarDelegate extends SliverPersistentHeaderDelegate {
  _SilverAppBarDelegate(this.child);

  final Widget child;

  @override
  double get minExtent => 44;

  @override
  double get maxExtent => 44;

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return new Container(
      child: child,
    );
  }

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
    return false;
  }
}
