Skip to content

Instantly share code, notes, and snippets.

@eseidelGoogle
Created February 1, 2020 05:27
Show Gist options
  • Save eseidelGoogle/4a5013998161dbba27f1b2e7582913ab to your computer and use it in GitHub Desktop.
Save eseidelGoogle/4a5013998161dbba27f1b2e7582913ab to your computer and use it in GitHub Desktop.
debouce example
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MyWidget();
}
}
class MyWidget extends StatefulWidget {
State<MyWidget> createState() => MyState();
}
class MyState extends State<MyWidget> with TickerProviderStateMixin {
AnimationController controller;
Animation animation;
void initState() {
super.initState();
controller =
AnimationController(vsync: this, duration: Duration(seconds: 1))
..forward();
animation = Tween(begin: 1.0, end: 0.0)
.chain(CurveTween(curve: const Interval(0.5, 1.0)))
.animate(controller.view);
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: animation,
builder: (_, __) {
print(animation.value);
return Container();
});
}
}
@eseidelGoogle
Copy link
Author

Output:
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0.9992000000000001
0.965838
0.93249
0.899116
0.8657699999999999
0.832414
0.79905
0.7656799999999999
0.7323299999999999
0.698958
0.6656120000000001
0.63225
0.5988800000000001
0.5655300000000001
0.5321720000000001
0.49881
0.465468
0.4320759999999999
0.398722
0.3653599999999999
0.331998
0.298654
0.265312
0.23195199999999994
0.19856800000000008
0.1652260000000001
0.09851199999999993
0.03179200000000004
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment