本篇文章已受權微信公衆號 YYGeeker
獨家發佈轉載請標明出處java
一、簡介微信
AnimatedDefaultTextStyle
控件表示一個具備變化文本樣式的動畫控件AnimatedDefaultTextStyle
經過修改組件的style屬性,系統將會經過動畫的方式自動切換到新的style樣式二、構造函數app
AnimatedDefaultTextStyle({
Key key,
@required this.child,
@required this.style,
this.textAlign,
this.softWrap = true,
this.overflow = TextOverflow.clip,
this.maxLines,
Curve curve = Curves.linear,
@required Duration duration,
Duration reverseDuration,
})
複製代碼
三、例子dom
經過_isSelected
的值控制樣式的切換ide
AnimatedDefaultTextStyle(
softWrap: false,
textAlign: TextAlign.right,
maxLines: 2,
overflow: TextOverflow.ellipsis,
curve: Curves.linear,
duration: Duration(seconds: 1),
child: Text("Flutter message you!!!"),
style: _isSelected
? TextStyle(
fontSize: 10.0,
color: Colors.red,
fontWeight: FontWeight.bold,
)
: TextStyle(
fontSize: 50.0,
color: Colors.black,
fontWeight: FontWeight.w300,
),
),
複製代碼
經過計時器控制樣式的切換函數
Timer.periodic(Duration(seconds: 1), (timer) {
setState(() {
switch (time % 4) {
case 0:
_isSelected = false;
break;
case 2:
_isSelected = true;
break;
}
time++;
});
});
複製代碼
一、簡介字體
AnimatedListState
控件表示一個具備動畫的列表控件AnimatedListState
控件做爲AnimatedList
控件的key進行使用,能夠控制列表動畫和增刪操做二、構造函數動畫
const AnimatedList({ Key key, @required this.itemBuilder, this.initialItemCount = 0, this.scrollDirection = Axis.vertical, this.reverse = false, this.controller, this.primary, this.physics, this.shrinkWrap = false, this.padding, }) 複製代碼
三、例子ui
經過點擊加號隨機生成字符串,對列表進行增長操做,經過點擊條目的刪除圖標,對列表進行刪除操做this
class WeWidgetState extends State<WeWidget> {
var data = <String>[];
var tween = Tween<Offset>(begin: Offset(1, 0), end: Offset(0, 0));
final animatedKey = GlobalKey<AnimatedListState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('day19'),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
var str = Random().nextInt(1000).toString();
data.add(str);
var index = data.lastIndexOf(str);
animatedKey.currentState.insertItem(index);
},
child: Icon(Icons.add),
),
body: AnimatedList(
physics: BouncingScrollPhysics(),
padding: EdgeInsets.all(12.0),
scrollDirection: Axis.vertical,
primary: true,
reverse: false,
shrinkWrap: false,
key: animatedKey,
initialItemCount: data.length,
itemBuilder: (context, int index, Animation<double> animation) {
return animationListItem(data[index], animation);
},
),
);
}
Widget animationListItem(String str, animation) {
return SlideTransition(
position: animation.drive(tween),
child: listItem(str),
);
}
Widget listItem(String str) {
return ListTile(
title: Text('$str', style: TextStyle(fontSize: 30)),
trailing: IconButton(
icon: Icon(Icons.delete_forever),
onPressed: () {
var index = data.indexOf(str);
data.remove(str);
animatedKey.currentState.removeItem(
index, (context, animation) => animationListItem(str, animation));
},
),
);
}
}
複製代碼
一、簡介
AnimatedModalBarrier
控件表示一個具備顏色值變化的動畫控件AnimatedModalBarrier
控件可防止用戶與其自身背後的小部件進行交互,而且可使用顏色動畫進行過渡AnimatedModalBarrier
控件舉例說明,當屏幕上出現對話框時,對話框下方的頁面一般會被ModalBarrier
變暗二、構造函數
const AnimatedModalBarrier({ Key key, Animation<Color> color, this.dismissible = true, this.semanticsLabel, this.barrierSemanticsDismissible, }) 複製代碼
ModalBarrier
將彈出當前路由,配合點擊事件彈出路由使用ModalBarrier
語義三、例子
Widget _buildColumn() {
return Center(
child: Container(
width: 200,
height: 200,
child: AnimatedModalBarrier(
semanticsLabel: "StackBarrier",
barrierSemanticsDismissible: true,
dismissible: true,
color: _animation,
),
),
);
}
複製代碼
一、簡介
AnimatedOpacity
控件表示一個具備透明度變化的動畫控件二、構造函數
const AnimatedOpacity({ Key key, this.child, @required this.opacity, Curve curve = Curves.linear, @required Duration duration, }) 複製代碼
三、例子
經過定時器改變透明度的大小
class WeWidgetState extends State<WeWidget> {
WeWidgetState() {
Timer.periodic(Duration(milliseconds: 1000), (timer) {
setState(() {
switch (time % 2) {
case 0:
_opacity = 0.3;
break;
case 1:
_opacity = 1.0;
break;
}
time++;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("day21"),
),
body: _buildColumn(),
);
}
Widget _buildColumn() {
return Center(
child: AnimatedOpacity(
curve: Curves.fastOutSlowIn,
opacity: _opacity,
duration: Duration(seconds: 1),
child: FlutterLogo(
style: FlutterLogoStyle.horizontal,
size: 200,
),
),
);
}
}
複製代碼
一、簡介
AnimatedPhysicalModel
控件表示一個具備陰影背景動畫的控件二、構造函數
const AnimatedPhysicalModel({ Key key, @required this.child, @required this.shape, this.clipBehavior = Clip.none, this.borderRadius = BorderRadius.zero, @required this.elevation, @required this.color, this.animateColor = true, @required this.shadowColor, this.animateShadowColor = true, Curve curve = Curves.linear, @required Duration duration, }) 複製代碼
三、例子
Widget _buildColumn() {
return Center(
child: AnimatedPhysicalModel(
curve: Curves.fastOutSlowIn,
color: Colors.grey.withOpacity(0.2),
clipBehavior: Clip.antiAliasWithSaveLayer,
borderRadius: BorderRadius.circular(12.0),
animateColor: true,
animateShadowColor: true,
shape: BoxShape.rectangle,
shadowColor: _shadowColor,
elevation: 20.0,
duration: Duration(seconds: 1),
child: FlutterLogo(
style: FlutterLogoStyle.horizontal,
size: 200,
),
),
);
}
複製代碼
一、簡介
AnimatedPositioned
控件表示一個具備位置變化動畫的控件二、構造函數
const AnimatedPositioned({ Key key, @required this.child, this.left, this.top, this.right, this.bottom, this.width, this.height, Curve curve = Curves.linear, @required Duration duration, }) 複製代碼
三、例子
經過改變左上角位置和寬高進行動畫播放
class WeWidgetState extends State<WeWidget> {
WeWidgetState() {
Timer.periodic(Duration(milliseconds: 1000), (timer) {
setState(() {
switch (time % 2) {
case 0:
_width = 100.0;
break;
case 1:
_width = 200.0;
break;
}
time++;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("day23"),
),
body: _buildColumn(),
);
}
Widget _buildColumn() {
return Stack(
children: <Widget>[
AnimatedPositioned(
curve: Curves.fastOutSlowIn,
width: _width,
height: _width,
top: _width,
left: _width,
duration: Duration(seconds: 1),
child: FlutterLogo(
style: FlutterLogoStyle.horizontal,
size: 200,
),
),
],
);
}
}
複製代碼
一、簡介
AnimatedSize
控件表示一個具備尺寸變化動畫的控件二、構造函數
const AnimatedSize({ Key key, Widget child, this.alignment = Alignment.center, this.curve = Curves.linear, @required this.duration, this.reverseDuration, @required this.vsync, }) 複製代碼
三、例子
class WeWidgetState extends State<WeWidget> with SingleTickerProviderStateMixin {
WeWidgetState() {
Timer.periodic(Duration(milliseconds: 1000), (timer) {
setState(() {
switch (time % 2) {
case 0:
_width = 100.0;
break;
case 1:
_width = 200.0;
break;
}
time++;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("day24"),
),
body: _buildColumn(),
);
}
Widget _buildColumn() {
return Center(
child: AnimatedSize(
alignment: Alignment.center,
curve: Curves.fastOutSlowIn,
vsync: this,
duration: Duration(seconds: 1),
reverseDuration: Duration(seconds: 2),
child: FlutterLogo(
style: FlutterLogoStyle.horizontal,
size: _width,
),
),
);
}
}
複製代碼
Hensen_ |