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
随机推荐
- 浅析 record 使用场景
浅析 record 使用场景 Intro 之前我们有介绍过 record 基本知识,record 会实现基于值的类型比较,最近遇到的几个问题觉得用 record 来解决会非常方便,分享一下 基于值的类 ...
- AutoMapper 10.0使用教程
这里有个目录 什么是AutoMapper 配置 使用MapperConfiguration配置 使用Profile Instances配置 Naming Conventions(命名约定) Repla ...
- 像羽毛一样轻的MVVMLight(一)(MVVM 和 MVVMLight简介)
致敬 在此致敬翁智华大佬,感谢大佬为后辈们写下如此详细的文档,本文将在原文基础上添加些自己的理解,希望这样优秀的文档广为流传. 原文请参考 https://www.cnblogs.com/wzh201 ...
- Kubernetes之持久化存储
转载自 https://blog.csdn.net/dkfajsldfsdfsd/article/details/81319735 ConfigMap.Secret.emptyDir.hostPath ...
- 7. Linux命令行的通配符、转义字符
1.命令行的通配符 举例:1)列出所有在/dev 目录中以sda 开头的文件 [root@Centos test]# ll /dev/sda* brw-rw----. 1 root disk 8, 0 ...
- 学会lambda表达式,能让你少敲1000行代码!
01.什么是 lambda 表达式 1. 函数式接口 在聊起 lambda 表达式之前,我们不得不提起函数式接口:一个接口只包含唯一的方法,那么它就是函数式接口.例如: public class La ...
- dedecms织梦搜索页错乱的解决方法
在使用DEDE程序所架设的网站时,使用搜索结果页展示的问题上,由于font样式飘红问题,导致页面错乱,今天来解决这个问题. 织梦程序的搜索结果原理很简单,利用font加入颜色样式赋予搜索结果,所以显示 ...
- TypeScript中 typeof ArrayInstance[number] 剖析
假设这样一个场景,目前业务上仅对接了三方支付 'Alipay', 'Wxpay', 'PayPal', 实际业务 getPaymentMode 会根据不同支付方式进行不同的付款/结算流程. const ...
- Java基础(第二期)
数据类型扩展以及面试题讲解 整数拓展:进制 int i=10; int i2=010; //八进制0 int i3=0x10; //十六进制0x 0~9 A~F 16 相关进制转换自行学习,用的不多 ...
- WSL2 VS Code远程开发.Net Core
修改 我们打开一个页面,随便修改一下,保存,结果会出现错误:Unable to write file (NoPermissions (FileSystemError): Error: EACCES: ...