Flutter是谷歌的移動UI框架,能夠快速在iOS和Android上構建高質量的原生用戶界面。git
IT界著名的尼古拉斯·高爾包曾說:輪子是IT進步的階梯!熱門的框架千篇一概,好用輪子萬里挑一!Flutter做爲這兩年開始崛起的跨平臺開發框架,其第三方生態相比其餘成熟框架還略有不足,但輪子的數量也已經不少了。本系列文章挑選平常app開發經常使用的輪子分享出來,給你們提升搬磚效率,同時也但願flutter的生態愈來愈完善,輪子愈來愈多。github
本系列文章準備了超過50個輪子推薦,工做緣由,儘可能每1-2天出一篇文章。app
tip:本系列文章合適已有部分flutter基礎的開發者,入門請戳:flutter官網框架
flutter_staggered_animations: "^0.1.2"
複製代碼
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
複製代碼
flutter_staggered_animations提供三個類:ide
以及四個默認動畫類型:動畫
動畫外部由AnimationLimiter組件包裹,ListView的子項由AnimationConfiguration.staggeredList來建立:ui
int count=20;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("ListView"),
),
body: AnimationLimiter(
child:ListView.builder(
itemCount: count,
itemBuilder: (context,index){
return AnimationConfiguration.staggeredList(
position: index,
duration: const Duration(milliseconds: 375),
child: SlideAnimation( //滑動動畫
verticalOffset: 50.0,
child: FadeInAnimation( //漸隱漸現動畫
child: Container(
margin: EdgeInsets.all(5),
color: Theme.of(context).primaryColor,
height: 60,
),
),
),
);
},
),
),
);
}
複製代碼
動畫外部由AnimationLimiter組件包裹,GridView的子項由AnimationConfiguration.staggeredGrid來建立:spa
int count=20;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("GridView"),
),
body:
AnimationLimiter(
child:GridView.builder(
itemCount: count,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
//橫軸元素個數
crossAxisCount: 3,
//縱軸間距
mainAxisSpacing: 10.0,
//橫軸間距
crossAxisSpacing: 10.0,
//子組件寬高長度比例
childAspectRatio: 1.0
),
itemBuilder: (context,index){
return AnimationConfiguration.staggeredGrid(
columnCount:count,
position: index,
duration: const Duration(milliseconds: 375),
child: SlideAnimation(
verticalOffset: 50.0,
child: FadeInAnimation(
child: Container(
color: Theme.of(context).primaryColor,
),
),
),
);
},
),
),
);
}
複製代碼
動畫外部由AnimationLimiter組件包裹,Column的子項由AnimationConfiguration.toStaggeredList來建立:code
int count=10;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Column"),
),
body:
AnimationLimiter(
child:Column(
children:AnimationConfiguration.toStaggeredList(
duration: const Duration(milliseconds: 375),
childAnimationBuilder:(widget) => SlideAnimation(
verticalOffset: 50.0,
child: FadeInAnimation(
child: widget,
),
),
children: ChildrenList()
)
),
),
);
}
List<Widget> ChildrenList(){
List<Widget> childs=[];
for (var i = 0; i < count; i++) {
childs.add(Container(
margin: EdgeInsets.all(5),
color: Theme.of(context).primaryColor,
height: 60,
));
}
return childs;
}
複製代碼
動畫外部由AnimationLimiter組件包裹,Row的子項由AnimationConfiguration.toStaggeredList來建立:cdn
int count=5;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Row"),
),
body:
AnimationLimiter(
child:Container(
height: 60,
child: Row(
children:AnimationConfiguration.toStaggeredList(
duration: const Duration(milliseconds: 375),
childAnimationBuilder:(widget) => SlideAnimation(
verticalOffset: 50.0,
child: FadeInAnimation(
child: widget,
),
),
children: ChildrenList()
)
),
),
),
);
}
List<Widget> ChildrenList(){
List<Widget> childs=[];
for (var i = 0; i < count; i++) {
childs.add(Container(
margin: EdgeInsets.only(right:5),
color: Theme.of(context).primaryColor,
width: 60,
));
}
return childs;
}
複製代碼