flutter好用的輪子推薦八-flutter一個超酷動畫的底部tab欄

前言

Flutter是谷歌的移動UI框架,能夠快速在iOS和Android上構建高質量的原生用戶界面。git

IT界著名的尼古拉斯·高爾包曾說:輪子是IT進步的階梯!熱門的框架千篇一概,好用輪子萬里挑一!Flutter做爲這兩年開始崛起的跨平臺開發框架,其第三方生態相比其餘成熟框架還略有不足,但輪子的數量也已經不少了。本系列文章挑選平常app開發經常使用的輪子分享出來,給你們提升搬磚效率,同時也但願flutter的生態愈來愈完善,輪子愈來愈多。github

本系列文章準備了超過50個輪子推薦,工做緣由,儘可能每1-2天出一篇文章。app

tip:本系列文章合適已有部分flutter基礎的開發者,入門請戳:flutter官網框架

正文

輪子

  • 輪子名稱:curved_navigation_bar
  • 輪子概述:flutter一個超酷動畫的底部tab欄.
  • 輪子做者:rafbednarczuk@gmail.com
  • 推薦指數:★★★★
  • 經常使用指數:★★★★
  • 效果預覽:
    原文效果gif
    效果圖

安裝

dependencies:
 curved_navigation_bar: ^0.3.1
複製代碼
import 'package:curved_navigation_bar/curved_navigation_bar.dart';
複製代碼

使用

  • items:按鈕小部件列表
  • index:NavigationBar的索引,可用於更改當前索引或設置初始索引
  • color:NavigationBar的顏色,默認值爲Colors.white
  • buttonBackgroundColor:浮動按鈕的背景色
  • backgroundColor: NavigationBar動畫鏤空時的背景,默認的Colors.blueAccent
  • onTap:按鈕點擊事件(index)
  • animationCurve:動畫曲線,默認的Curves.easeOutCubic
  • animationDuration:按鈕更改動畫的持續時間,默認的Duration(毫秒:600)
  • height:NavigationBar的高度,最小值0.0,最高75.0

默認示例:ide

Scaffold(
  bottomNavigationBar: CurvedNavigationBar(
    backgroundColor: Colors.blueAccent,
    items: <Widget>[
      Icon(Icons.add, size: 30),
      Icon(Icons.list, size: 30),
      Icon(Icons.compare_arrows, size: 30),
    ],
    onTap: (index) {
      //Handle button tap
    },
  ),
  body: Container(color: Colors.blueAccent),
)
複製代碼

與TabBarView一塊兒聯動使用動畫

class CurvedNavigationBarDemo extends StatefulWidget {
    CurvedNavigationBarDemo({Key key}) : super(key: key);

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

class _CurvedNavigationBarDemoState extends State<CurvedNavigationBarDemo> with SingleTickerProviderStateMixin{

    TabController tabController;

    List colors=[Colors.blue,Colors.pink,Colors.orange];

    int currentIndex=0;

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

    @override
    Widget build(BuildContext context) {
        return Scaffold(
            bottomNavigationBar: CurvedNavigationBar(
                backgroundColor: colors[currentIndex],
                index: currentIndex,
                items: <Widget>[
                    Icon(Icons.home, size: 30),
                    Icon(Icons.fiber_new, size: 30),
                    Icon(Icons.person, size: 30),
                ],
                onTap: (index) {
                    //Handle button tap
                    setState(() {
                        currentIndex=index;
                    });
                    tabController.animateTo(index,duration: Duration(milliseconds: 300), curve: Curves.ease);
                },
            ),
            body: TabBarView(
                controller: tabController,
                children: <Widget>[
                    Container(
                        color: colors[0],
                    ),
                    Container(
                        color: colors[1],
                    ),
                    Container(
                        color: colors[2],
                    )
                ],
            )
        );
    }
}
複製代碼

結尾

相關文章
相關標籤/搜索