Flutter 模拟youtube快进icon
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: Duration(seconds: 1),
vsync: this,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
title: Text('Home Page'),
),
body: Center(
child: AnimatedArrowIcon(
controller: controller,
color: Colors.white,
size: Size(600, 600),
iconSize: 30,
onDoubleTap: () {
controller.forward();
},
),
),
);
}
}
class AnimatedArrowIcon extends StatefulWidget {
final AnimationController controller;
final Color color;
final Function onTap;
final Function onDoubleTap;
final Size size;
final double iconSize;
final Animation<double> _oneIconOpacityAnimation;
final Animation<double> _twoIconOpacityAnimation;
final Animation<double> _threeIconOpacityAnimation;
final Animation<Size> _sizeAnimation;
static final double _begin = 0.0;
static final double _end = 2.0;
static final Curve _curve = Curves.easeInOut;
AnimatedArrowIcon({
Key key,
@required this.controller,
this.color = Colors.black,
this.onTap,
this.onDoubleTap,
this.size = const Size(300, 300),
this.iconSize = 24.0,
}) : _oneIconOpacityAnimation =
Tween<double>(begin: _begin, end: _end).animate(
CurvedAnimation(
parent: controller,
curve: Interval(0.0, 0.7, curve: _curve),
),
),
_twoIconOpacityAnimation =
Tween<double>(begin: _begin, end: _end).animate(
CurvedAnimation(
parent: controller,
curve: Interval(0.2, 0.8, curve: _curve),
),
),
_threeIconOpacityAnimation =
Tween<double>(begin: _begin, end: _end).animate(
CurvedAnimation(
parent: controller,
curve: Interval(0.5, 1.0, curve: _curve),
),
),
_sizeAnimation = Tween<Size>(begin: Size(0, 0), end: size).animate(
CurvedAnimation(
parent: controller,
curve: Interval(0.0, 0.8, curve: _curve),
),
),
super(key: key);
@override
_AnimatedArrowIconState createState() => _AnimatedArrowIconState();
}
class _AnimatedArrowIconState extends State<AnimatedArrowIcon> {
double get _oneValue => _edge(_lerp(widget._oneIconOpacityAnimation.value));
double get _twoValue => _edge(_lerp(widget._twoIconOpacityAnimation.value));
double get _threeValue =>
_edge(_lerp(widget._threeIconOpacityAnimation.value));
double _edge(double v) => v > 1.0 ? 1.0 : v < 0 ? 0 : v;
double _lerp(double v) => v >= 1 ? (v - AnimatedArrowIcon._end).abs() : v;
double _opacity = 0;
@override
void initState() {
super.initState();
widget.controller.addStatusListener((status) {
if (status == AnimationStatus.completed) {
setState(() => _opacity = 0);
widget.controller.reset();
}
if (status == AnimationStatus.forward) {
setState(() => _opacity = 1);
}
});
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onTap,
onDoubleTap: widget.onDoubleTap,
child: AnimatedBuilder(
animation: widget.controller,
builder: (context, child) {
return Stack(
alignment: Alignment.center,
children: [
AnimatedOpacity(
opacity: _opacity,
duration: widget.controller.duration,
curve: Curves.easeOutQuint,
child: Container(
width: widget.size.width,
height: widget.size.width,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white.withOpacity(0.1),
),
),
),
Container(
width: widget._sizeAnimation.value.width,
height: widget._sizeAnimation.value.height,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white.withOpacity(0.1),
),
),
SizedBox(
width: widget.iconSize * 3.0,
child: Stack(
alignment: Alignment.center,
children: [
Align(
alignment: Alignment(-0.6, 0),
child: Opacity(
opacity: _oneValue,
child: child,
),
),
Opacity(
opacity: _twoValue,
child: child,
),
Align(
alignment: Alignment(0.6, 0),
child: Opacity(
opacity: _threeValue,
child: child,
),
),
],
),
),
],
);
},
child: Icon(
Icons.play_arrow,
color: widget.color,
size: widget.iconSize,
),
),
);
}
}
Flutter 模拟youtube快进icon的更多相关文章
- MediaElement视频控制:播放、暂停、停止、后退、快进、跳转、音量
/* ================================================= * Author: Micro * Date: 2016=03-25 ...
- jwplayer 禁止视频的快进,但是可以后退(已实现)
一直在研究.net 的视频播放,最近做起了jwplayer,然后项目要求是视频不能快进,但是可以重复观看已经看过的视频资源. 很简单 在标签<script> 中定义两个变量 var max ...
- video字幕无法显示,video视频在google中无法控制快进
video字幕(track)无法显示: 直接用关闭同源策略的浏览器打开你的HTML文件可以请求到字幕文件并显示字幕: 从hbuilder中打开html文件,在从里面打开google浏览器去浏览HTML ...
- 关于jwplayer 处理进度条禁止快进的处理方法。
今天在处理一个关于jwplayer 第一次播放禁止快进,但是可以后退的一个需求.开始在网上去查一些方法,有几个方法是换皮肤,禁止点击,但是和我的初衷不是很一致,还有一种方式是官网查看了API接口的方 ...
- Video/Audio禁止快进(退)
首先接着上个随笔.上个随笔主要介绍了视频音频的相关操作.属性和方法.这里主要记录一个应用:禁止快进(快退同理). 思路:监听快进事件(此处是监听播放时间更新),利用一个缓存的时间和播放到的时间进行对比 ...
- html5 vedio 播放器,禁掉进度条快进快退事件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 修改CKplayer.js 源码解决移动端浏览器全屏不能限制快进的问题
原文地址:https://www.cnblogs.com/jying/p/9642445.html,转载请说明出处. 最近项目需要播放视频且限制未观看部分的快进功能,找了两款js插件ckplayer和 ...
- android开发之GestureDetector手势识别(调节音量、亮度、快进和后退)
写UI布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro ...
- Eclipse之向前快进,向后快退
在已经写好的代码上进行修改,存在代码快需要向前快进,向后快退的情况. 选中代码块,然后右击,有Shift Right, Shift Left
随机推荐
- 省选复习 - LCT 笔记
目录 LCT 笔记 主要功能 和其它数据结构的比较 思想 虚实剖分 如何维护所有的链 实链 虚边 开始构思 具体要维护的功能(从基础到高级) Splay部分 access(u) make(u) fin ...
- Oracle数据库误删除数据恢复(Oracle闪回功能)
一.启用行移动功能 alter table table_name enable row movement ; 二.可查询之前某一个时间点的数据(默认是1440分钟,即24小时内的数据) select ...
- ESRI,空间数据处理,WKT,GeoJson
ESRI,空间数据处理,WKT,GeoJson 一.WKT 二.GeoJson 三.WKT转GeoJson 四.GeoJson 转 WKT 一.WKT WKT(well-known text)是一种文 ...
- SpringMvc获取getbean
import org.apache.commons.lang3.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; i ...
- vulnhub靶机练习-Os-hackNos-1,超详细使用
第一次写自己总结的文章,之后也会有更新,目前还在初学阶段. 首先介绍一下靶机,靶机是 vulnhub Os-hackNos-1 简介: 难度容易到中, flag 两个 一个是普通用户的user.txt ...
- Java程序操作Hive
1.hive的lib+jdbc,还要把mysql的连接驱动加载过来 2.编写程序 开启远程服务:[root@zhiyou ~]# hiveserver2 &[1] 4127[root@zhiy ...
- 2019 ICPC 上海区域赛总结
2019上海区域赛现场赛总结 补题情况(以下通过率为牛客提交): 题号 标题 已通过代码 通过率 我的状态 A Mr. Panda and Dominoes 点击查看 5/29 未通过 B Prefi ...
- 简谈图论重要性&&图论总结
从外地学习回来,我对图论才有认识(以前就没接触过,非常尴尬),说实话,学好图论的重要性,就像学数学时在进行解析几何时,图极有可能是打开答案的最后秘钥,也就是数形结合,而懂的人永远明白,用图解决绝对比用 ...
- poj 3304 Segments(解题报告)
收获:举一反三:刷一道会一道 1:思路转化:(看的kuangbin的思路) 首先是在二维平面中:如果有很多线段能够映射到这个直线上并且至少重合于一点,充要条件: 是过这个点的此条直线的垂线与其他所有直 ...
- c语言实现--不带头结点的单链表操作
1,不带头结点的单链表操作中,除了InitList(),GetElem(),ListInsert(),ListDelete()操作与带头结点的单链表有差别外,其它的操作基本上一样. 2,不带头结点单链 ...