Created
December 28, 2018 13:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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