Skip to content

Instantly share code, notes, and snippets.

View felixblaschke's full-sized avatar

Felix Blaschke felixblaschke

  • Frankfurt am Main, Germany
View GitHub Profile
@felixblaschke
felixblaschke / bar_chart_3.dart
Created November 9, 2019 07:19
bar_chart_3.dart
class BarChartApplication extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Bar(0.3, "2013"),
Bar(0.5, "2014"),
@felixblaschke
felixblaschke / bar_chart_2.dart
Created November 9, 2019 07:17
bar_chart_2.dart
class Bar extends StatelessWidget {
// ...
@override
Widget build(BuildContext context) {
return ControlledAnimation(
duration: Duration(milliseconds: (height * _baseDurationMs).round()),
tween: Tween(begin: 0.0, end: height),
builder: (context, animatedHeight) {
return Column(
@felixblaschke
felixblaschke / bar_chart_1.dart
Created November 9, 2019 07:02
bar_chart_1.dart
class Bar extends StatelessWidget {
final double height;
final String label;
final int _baseDurationMs = 1000;
final double _maxElementHeight = 100;
Bar(this.height, this.label);
@override
@felixblaschke
felixblaschke / acx_progress-3.dart
Created May 26, 2019 05:57
acx_progress-3.dart
var _dataIsLoaded = false;
_loadData() {
// Simulate HTTP Request
_dataIsLoaded = false;
Future.delayed(Duration(seconds: 4)).then((_) => _dataIsLoaded = true);
controller.addTasks([
FromToTask(
duration: Duration(milliseconds: 700),
@felixblaschke
felixblaschke / acx_progress-2.dart
Created May 26, 2019 05:47
acx_progress-2.dart
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[_progressIndicator(), _requestButton()],
);
}
var _showCircularProgressIndicator = false;
@felixblaschke
felixblaschke / acx_progress-1.dart
Created May 26, 2019 05:33
acx_progress-1.dart
class ProgressIndicatorAnimation extends StatefulWidget {
@override
_ProgressIndicatorAnimationState createState() =>
_ProgressIndicatorAnimationState();
}
class _ProgressIndicatorAnimationState extends State<ProgressIndicatorAnimation>
with AnimationControllerMixin {
Animation tween;
// Animate forward (1s)
controller
.addTask(FromToTask(duration: Duration(seconds: 1), to: 1.0));
// Animate reverse (0,5s)
controller
.addTask(FromToTask(duration: Duration(milliseconds: 500), to: 0.0));
// Clear queue (stop all running tasks) and loop forever
controller
@felixblaschke
felixblaschke / acx3.dart
Last active May 19, 2019 06:54
acx3.dart
class _WidgetWithAnimationState extends State<WidgetWithAnimation>
with AnimationControllerMixin {
Animation<double> width;
@override
void initState() {
width = Tween(begin: 100.0, end: 200.0).animate(controller);
controller.addTask(FromToTask(duration: Duration(seconds: 1), to: 1.0));
super.initState();
}
class _WidgetWithAnimationState /* ... */ {
AnimationControllerX controller; // change here
// ...
@override
void initState() {
controller = AnimationControllerX(vsync: this); // change here
// ...
}
// ...
}
@felixblaschke
felixblaschke / acx1.dart
Last active May 19, 2019 06:55
acx1.dart
class _WidgetWithAnimationState extends State<WidgetWithAnimation>
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation<double> width;
@override
void initState() {
controller = AnimationController(
vsync: this,
duration: Duration(seconds: 1),