Skip to content

Instantly share code, notes, and snippets.

@miguelpruivo
Created December 28, 2018 13:12
Show Gist options
  • Save miguelpruivo/466e6857eda25146326cdd1c3ffdd86d to your computer and use it in GitHub Desktop.
Save miguelpruivo/466e6857eda25146326cdd1c3ffdd86d to your computer and use it in GitHub Desktop.
A progress line that goes from a starting date to an end date
class MyProgressLine extends CustomPainter {
MyProgressLine({this.shipped, this.estDelivery});
final DateTime shipped;
final DateTime estDelivery;
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = Colors.green
..strokeWidth = 3.0
..style = PaintingStyle.stroke;
double endPointsRadius = 5.0;
double width = size.width;
int totalDays = ((estDelivery.millisecondsSinceEpoch - shipped.millisecondsSinceEpoch) / 86400000).floor();
int currentDay = ((DateTime.now().millisecondsSinceEpoch - shipped.millisecondsSinceEpoch) / 86400000).floor();
double stepPerDay = width / totalDays;
// Draws starting point
canvas.drawCircle(Offset.zero, 5.0, paint);
canvas.drawLine(Offset(endPointsRadius, 0.0), Offset(endPointsRadius + stepPerDay * currentDay, 0.0), paint);
// Draws current progress line
paint.style = PaintingStyle.fill;
canvas.drawCircle(Offset(endPointsRadius + stepPerDay * currentDay, 0.0), 3.0, paint);
// Draws endpoint
paint.style = PaintingStyle.stroke;
paint.color = Colors.grey.withOpacity(0.5);
canvas.drawLine(Offset(endPointsRadius + stepPerDay * currentDay, 0.0), Offset(stepPerDay * totalDays, 0.0), paint);
canvas.drawCircle(Offset((stepPerDay * totalDays) + endPointsRadius, 0.0), endPointsRadius, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
class MySnackBar extends StatefulWidget {
_MySnackBarState createState() => _MySnackBarState();
}
class _MySnackBarState extends State<MySnackBar> {
@override
Widget build(BuildContext context) {
return Center(
child: RaisedButton(
child: Text('Show snackbar'),
onPressed: () {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("sagar"),
action: SnackBarAction(
label: 'UNDO',
onPressed: Scaffold.of(context).hideCurrentSnackBar,
)));
}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment