当前位置:网站首页>Use flutter to adjust a color filter for the picture of my little sister
Use flutter to adjust a color filter for the picture of my little sister
2022-07-26 05:13:00 【InfoQ】
StatelessWidgetTweenAnimationBuilderTweenAnimationBuilder
TweenAnimationBuilder
Introduce
TweenAnimationBuilderconst TweenAnimationBuilder({
Key? key,
required this.tween,
required Duration duration,
Curve curve = Curves.linear,
required this.builder,
VoidCallback? onEnd,
this.child,
})
durationcurveonEndtween:Twee<T>type , During the animation process, theTweenThe intermediate interpolation of is passed tobuilderTo build subcomponents , Thus, the transition animation effect can be realized .
builder: Component building method , The type isValueWidgetBuilder<T>, The specific definitions are as follows , amongvalueThe parameter istweenIntermediate interpolation during animation . That is, during the animation , Will keep callingbuilderRedraw sub components .
typedef ValueWidgetBuilder<T> = Widget Function(BuildContext context, T value, Widget? child);
class _TweenAnimationBuilderState<T extends Object?> extends AnimatedWidgetBaseState<TweenAnimationBuilder<T>> {
Tween<T>? _currentTween;
@override
void initState() {
_currentTween = widget.tween;
_currentTween!.begin ??= _currentTween!.end;
super.initState();
if (_currentTween!.begin != _currentTween!.end) {
controller.forward();
}
}
@override
void forEachTween(TweenVisitor<dynamic> visitor) {
assert(
widget.tween.end != null,
'Tween provided to TweenAnimationBuilder must have non-null Tween.end value.',
);
_currentTween = visitor(_currentTween, widget.tween.end, (dynamic value) {
assert(false);
throw StateError('Constructor will never be called because null is never provided as current tween.');
}) as Tween<T>?;
}
@override
Widget build(BuildContext context) {
return widget.builder(context, _currentTween!.evaluate(animation), widget.child);
}
}
TweenAnimationBuilderapplication
ColorFilteredColorFilteredColorFilterBlendModeColorFiltered(
colorFilter:
ColorFilter.mode(Colors.orange, BlendMode.modulate),
child: ClipOval(
child: ClipOval(
child: Image.asset(
'images/beauty.jpeg',
width: 300,
),
),
),
);
TweenAnimationBuilderColorTweenbuilderColorFilterbuilderColorSliderclass TweenAnimationDemo extends StatefulWidget {
TweenAnimationDemo({Key? key}) : super(key: key);
@override
_TweenAnimationDemoState createState() => _TweenAnimationDemoState();
}
class _TweenAnimationDemoState extends State<TweenAnimationDemo> {
var _sliderValue = 0.0;
Color _newColor = Colors.orange;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TweenAnimationBuilder'),
brightness: Brightness.dark,
backgroundColor: Colors.black,
),
backgroundColor: Colors.black,
body: Center(
child: Column(
children: [
TweenAnimationBuilder(
tween: ColorTween(
begin: Colors.white,
end: _newColor,
),
duration: Duration(seconds: 1),
builder: (_, color, child) {
return ColorFiltered(
colorFilter:
ColorFilter.mode(color as Color, BlendMode.modulate),
child: ClipOval(
child: ClipOval(
child: Image.asset(
'images/beauty.jpeg',
width: 300,
),
),
),
);
},
),
Slider.adaptive(
value: _sliderValue,
onChanged: (value) {
setState(() {
_sliderValue = value;
});
},
onChangeEnd: (value) {
setState(() {
_newColor = _newColor.withRed((value * 255).toInt());
});
},
)
],
),
),
);
}
}
summary
TweenAnimationBuilderColorFilteredTweenAnimationBuilder

边栏推荐
- Migrate the server and reconfigure the database (the database has no monitoring, and the monitoring starts with tns-12545, tns-12560, tns-00515 errors)
- Mysql主从同步及主从同步延迟解决方案
- 测试必备工具之Fiddler,你真的了解吗?
- [weekly translation go] how to write your first program with go
- ALV程序收集
- Learn to map with nature medicine -- complex heat map
- Excel VBA:将多个工作表保存为新文件
- Security permission management details
- Alibaba cloud industrial vision intelligent engineer ACP certification - Preparation
- Black eat black? The man cracked the loopholes in the gambling website and "collected wool" for more than 100000 yuan per month
猜你喜欢

MODFLOW Flex、GMS、FEFLOW、HYDRUS实践应用

嵌入式开发小记,实用小知识分享

MySQL八股知识点:从入门到删库

普林斯顿微积分读本02第一章--函数的复合、奇偶函数、函数图像

Nacos 介绍和部署

Molecular skeleton transition tool -delinker introduction

Recommend 12 academic websites for free literature search, and suggest to like and collect!

JVM Lecture 2: class loading mechanism

DOM event flow event bubble event capture event delegate

Excel VBA: realize automatic drop-down filling formula to the last line
随机推荐
推荐必读:测试人员如何快速熟悉新业务?
【Leetcode】493. Reverse Pairs
测试用例评审如何开展
Mysql主从同步及主从同步延迟解决方案
Mysql优化
Excel VBA:将多个工作表保存为新文件
C language force buckle question 42 of rain. Four methods - violence, dynamic planning, stack, double pointer
[acwing] 1268. Simple questions
Week 6 Learning Representation: Word Embedding (symbolic →numeric)
如何优雅的复现YOLOv5官方历程(二)——标注并训练自己的数据集
基于通用优化软件GAMS的数学建模和优化分析
Textfield and password input box that are more flexible and easy to use in compose
C语言力扣第41题之缺失的第一个正数。两种方法,预处理快排与原地哈希
nacos注册中心
JVM Lecture 6: how to solve the frequent FGC in online environment?
Migrate the server and reconfigure the database (the database has no monitoring, and the monitoring starts with tns-12545, tns-12560, tns-00515 errors)
How many holes have you stepped on in BigDecimal?
[weekly translation go] how to write your first program with go
JVM第五讲:纵横数据如何应对洪峰推送
Leetcode linked list problem - 206. reverse linked list (learn linked list by one question and one article)