Skip to content

Instantly share code, notes, and snippets.

@mravn-google
Last active August 7, 2018 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mravn-google/cceb5f61d1a852d0a21dc6d7ce69f42e to your computer and use it in GitHub Desktop.
Save mravn-google/cceb5f61d1a852d0a21dc6d7ce69f42e to your computer and use it in GitHub Desktop.
Bar, BarTween, BarPainter. Height property only.
import 'dart:ui' show lerpDouble;
import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
class Bar {
Bar(this.height);
final double height;
static Bar lerp(Bar begin, Bar end, double t) {
return Bar(lerpDouble(begin.height, end.height, t));
}
}
class BarTween extends Tween<Bar> {
BarTween(Bar begin, Bar end) : super(begin: begin, end: end);
@override
Bar lerp(double t) => Bar.lerp(begin, end, t);
}
class BarChartPainter extends CustomPainter {
static const barWidth = 10.0;
BarChartPainter(Animation<Bar> animation)
: animation = animation,
super(repaint: animation);
final Animation<Bar> animation;
@override
void paint(Canvas canvas, Size size) {
final bar = animation.value;
final paint = Paint()
..color = Colors.blue[400]
..style = PaintingStyle.fill;
canvas.drawRect(
Rect.fromLTWH(
(size.width - barWidth) / 2.0,
size.height - bar.height,
barWidth,
bar.height,
),
paint,
);
}
@override
bool shouldRepaint(BarChartPainter old) => false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment