颤动选项卡栏导航动画的自定义动画

时间:2020-03-17 09:35:55

标签: flutter

如何在Flutter标签栏和标签栏视图中添加自定义动画,我想在将标签栏控制器附加到下面的代码中添加自定义导航动画,但我只获得了动画值,但我不想这样做我想完全改变动画,例如,当我拖动或单击它从该方向滑入的标签栏时,如果我想在过渡或任何其他动画中淡出,该怎么办。

class TabsPage extends StatefulWidget {
  @override
  _TabsPageState createState() => _TabsPageState();
}

class _TabsPageState extends State<TabsPage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;

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

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        backgroundColor: Colors.white.withOpacity(0.9),
        appBar: AppBar(
          bottom: TabBar(
            onTap: (index) {
              setState(() {
                _tabController.index = index;
              });
            },
            controller: _tabController,
            labelColor: Colors.black,
            tabs: <Widget>[
              Tab(
                icon: Icon(Icons.person),
                text: 'Hello',
              ),
              Tab(
                icon: Icon(Icons.person),
                text: 'World',
              ),
            ],
          ),
        ),
        body: TabBarView(
          controller: _tabController,
          children: [
            HomePage(),
            Favorites(),
          ],
        ),
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: () {
            _tabController.animateTo(1,
                duration: Duration(seconds: 5), curve: Curves.easeIn);
          },
        ),
      ),
    );
  }
}

0 个答案:

没有答案