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
随机推荐
- cocos2d-x 调试问题
1.昨天一个新功能,在xcode模拟器上测试没问题.后来打包安卓后,一直有问题 就又添加日志功能 # define CCLOGFUNC(s) ...
- ElasticSearch的查询(二)
一.Query String search 添加测试数据 PUT test_search { "mappings": { "test_type": { &quo ...
- 2019HDU多校 Round6
Solved:2 02 Nonsense Time (LIS) 题意:给定一个全排列 最开始为空的 每秒中一个位置上的数出现 求每秒的LIS 题解:题解说 考虑时光倒流 倒着消掉 因为数据随机 所以期 ...
- Codeforces Round #608 (Div. 2) E. Common Number (二分,构造)
题意:对于一个数\(x\),有函数\(f(x)\),如果它是偶数,则\(x/=2\),否则\(x-=1\),不断重复这个过程,直到\(x-1\),我们记\(x\)到\(1\)的这个过程为\(path( ...
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a lin ...
- Codeforces Round #650 (Div. 3) D. Task On The Board (构造,贪心)
题意:有一个字符串和一组数,可以对字符串删去任意字符后为数组的长度,且可以随意排序,要求修改后的字符串的每个位置上的字符满足:其余大于它的字符的位置减去当前位置绝对值之和等于对应序列位置上的数. 题解 ...
- B-number HDU - 3652
题意: 找出区间[li,ri]有多少个符合要求的数: 1.这个数里面有13 2.这个数可以被13整除 题解: 这个题目和之前的有点不一样就是这个题目要我们求包含13的(之前做过的都是不包含).但是都差 ...
- [已完成+附代码]CS:APP:Lab6-ShellLab
由于我的第五个实验的partB部分一直出问题.而且修了好久没解决先不管了 这个实验建议一定要认真读完csapp全书的第八章.不然可能会毫无思路.千万不要上来直接做. 0. 环境配置和实验下载 利用do ...
- Jpress小程序
首页轮播.首页公告.首页宫格.个人中心页面均支持在PC后台设置内容 首页列表.分类列表页.搜索列表的文章展示页均支持后台设置,拥有三种风格 所有分类展示支持两种风格 用户中心授权登陆,查看个人数据 J ...
- 【Azure 微服务】基于已经存在的虚拟网络(VNET)及子网创建新的Service Fabric并且为所有节点配置自定义DNS服务
问题描述 创建新的Service Fabric集群,可以通过门户,Powershell命令,或者是ARM模板.但是通过门户和PowerShell命令时,创建的SF集群都会自动新建一个虚拟网络而无法使用 ...