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
随机推荐
- SpringBoot+Spring常用注解总结
为什么要写这篇文章? 最近看到网上有一篇关于 SpringBoot 常用注解的文章被转载的比较多,我看了文章内容之后属实觉得质量有点低,并且有点会误导没有太多实际使用经验的人(这些人又占据了大多数). ...
- MIT 6.S081 Lab File System
前言 打开自己的blog一看,居然三个月没更新了...回想一下前几个月,开题 + 实验室杂活貌似也没占非常多的时间,还是自己太懈怠了吧,掉线城和文明6真的是时间刹手( 不过好消息是把15445的所有l ...
- hadoop知识点总结(三)YARN设计理念及基本架构
YARN设计理念与基本架构 1,MRv1的局限性:扩展性差,可靠性差,资源利用率低,无法支持多种计算框架 2,YARN基本设计思想 1)基本框架对比 Hadoop1.0中,JobTracker由资源管 ...
- 嵌入式设备上卷积神经网络推理时memory的优化
以前的神经网络几乎都是部署在云端(服务器上),设备端采集到数据通过网络发送给服务器做inference(推理),结果再通过网络返回给设备端.如今越来越多的神经网络部署在嵌入式设备端上,即inferen ...
- Python Line Messaging Api
Line Messaging line 是国外一个很火的实时通信软件,类似与WX,由于公司业务需求,需要基于line开发一个聊天平台,下面主要介绍关于line messaging api 的使用. 官 ...
- 2019 ICPC Asia Nanjing Regional
2019 ICPC Asia Nanjing Regional A - Hard Problem 计蒜客 - 42395 若 n = 10,可以先取:6,7,8,9,10.然后随便从1,2,3,4,5 ...
- Codeforces 1368F - Lamps on a Circle (交互博弈)
这题也太新颖了吧.. 交互博弈 以前一直以为交互只能出二分 题意:长度为n的环形灯 玩家有两种操作 结束游戏 或者选择k个灯点亮 每次这个k是玩家自己选的 玩家操作后让电脑操作 电脑选择一个最优的点x ...
- A. Crazy Town
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation ...
- Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2) B. Repainting Street (枚举)
题意:有\(n\)栋房子,每栋房子都有自己的颜色\(c_i\),你每次可以对连续的长度为\(k\)的区间改变任何房子的颜色,问最少多少次可以使得所有房子颜色相同. 题解:因为只有\(100\)中颜色, ...
- Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths (二分图染色)
题意:有\(n\)个点和\(m\)条无向边,现在让你给你这\(m\)条边赋方向,但是要满足任意一条边的路径都不能大于\(1\),问是否有满足条件的构造方向,如果有,输出一个二进制串,表示所给的边的方向 ...