Flutter是谷歌的移動UI框架,能夠快速在iOS和Android上構建高質量的原生用戶界面。git
IT界著名的尼古拉斯·高爾包曾說:輪子是IT進步的階梯!熱門的框架千篇一概,好用輪子萬里挑一!Flutter做爲這兩年開始崛起的跨平臺開發框架,其第三方生態相比其餘成熟框架還略有不足,但輪子的數量也已經不少了。本系列文章挑選平常app開發經常使用的輪子分享出來,給你們提升搬磚效率,同時也但願flutter的生態愈來愈完善,輪子愈來愈多。github
本系列文章準備了超過50個輪子推薦,工做緣由,儘可能每1-2天出一篇文章。app
tip:本系列文章合適已有部分flutter基礎的開發者,入門請戳:flutter官網框架
dependencies:
curved_navigation_bar: ^0.3.1
複製代碼
import 'package:curved_navigation_bar/curved_navigation_bar.dart';
複製代碼
默認示例: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],
)
],
)
);
}
}
複製代碼