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
随机推荐
- Elasticsearch--ES-Head--docker版安装
1.0ElasticSearch安装 # 拉取ES镜像docker pull elasticsearch:6.5.0 # 设置vm.max_map_count大小sysctl -w vm.max_ma ...
- React中组件间通信的方式
React中组件间通信的方式 React中组件间通信包括父子组件.兄弟组件.隔代组件.非嵌套组件之间通信. Props props适用于父子组件的通信,props以单向数据流的形式可以很好的完成父子组 ...
- FLOYD判圈
转载一篇博客:http://blog.csdn.net/javasus/article/details/50015687 Floyd判圈算法(Floyd Cycle Detection Algorit ...
- java创建线程的多种方式
java创建线程的四种方式 1.继承 Thread 类 通过继承 Thread 类,并重写它的 run 方法,我们就可以创建一个线程. 首先定义一个类来继承 Thread 类,重写 run 方法. 然 ...
- Java面试,面试题
Java面试,面试题 HashMap,HashTable,ConcurrentHash的共同点和区别 HashMap HashTable ConcurrentHashMap ArrayList和Lin ...
- sql注入-原理&防御
SQL注入是指web应用程序对用户输入数据的合法性没有判断或过滤不严,攻击者可以在web应用程序中事先定义好的查询语句的结尾上添加额外的SQL语句,在管理员不知情的情况下实现非法操作,以此来实现欺骗数 ...
- Centos7安装成功后,网卡配置及更改镜像地址为国内镜像
Centos7安装成功后,网卡配置及更改镜像地址为国内镜像 一.网卡配置 二.修改网络配置 踩坑一:IPADDR 踩坑二:网关,DNS与本地不一致 重启网络服务 三.镜像修改为aliyun 四.相关知 ...
- hadoop使用常见问题总结!
1,执行 hdfs dfs -copyFromLocal 命令报错! 19/01/02 11:01:32 INFO hdfs.DFSClient: Exception in createBlockOu ...
- .Net微服务实战之必须得面对的分布式问题
系列文章 .Net微服务实战之技术选型篇 .Net微服务实战之技术架构分层篇 .Net微服务实战之DevOps篇 .Net微服务实战之负载均衡(上) .Net微服务实战之CI/CD .Net微服务实战 ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...