union_tabs 1.0.0+7 copy "union_tabs: ^1.0.0+7" to clipboard
union_tabs: ^1.0.0+7 copied to clipboard

A nested TabBarView overscroll event unites outer TabBarView scroll event.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:union_tabs/union_tabs.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

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

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  List<String> tabsText = ["一", "二", "三"];
  List<String> secondTabsText = ["one", "two", "three"];
  TabController _controller;
  TabController _childController;

  @override
  void initState() {
    _controller = TabController(length: tabsText.length, vsync: this);
    _childController =
        TabController(length: secondTabsText.length, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          bottom: TabBar(
              controller: _controller,
              tabs: tabsText.map((it) => Tab(text: it)).toList()),
        ),

        /// outer tabTarView which receives  OverscrollNotification of inner tabBarView.
        body: UnionOuterTabBarView(
          controller: _controller,
          children: _createTabContent(),
        ));
  }

  List<Widget> _createTabContent() {
    List<Widget> tabContent = List();
    tabContent.add(Center(child: Text(tabsText[0])));
    final child = Column(
      children: <Widget>[
        TabBar(
            labelColor: Colors.black,
            unselectedLabelColor: Colors.black45,
            controller: _childController,
            tabs: secondTabsText.map((it) => Tab(text: it)).toList()),
        Expanded(
          /// convert inner tabBarView OverscrollNotification to UnionOverscrollNotification to notify outer tabBarView.
          child: UnionInnerTabBarView(
              controller: _childController,
              children:
                  secondTabsText.map((it) => Center(child: Text(it))).toList()),
        )
      ],
    );
    tabContent.add(child);
    tabContent.add(Center(child: Text(tabsText[2])));
    return tabContent;
  }

  @override
  void dispose() {
    _controller.dispose();
    _childController.dispose();
    super.dispose();
  }
}
2
likes
30
pub points
21%
popularity

Publisher

verified publisherwilin.me

A nested TabBarView overscroll event unites outer TabBarView scroll event.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

cupertino_icons, flutter

More

Packages that depend on union_tabs