Created
July 31, 2021 14:14
-
-
Save tayormi/7cc5ed31d4ad753f0b990f8e84c076ec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| enum MD2IndicatorSize { | |
| tiny, | |
| normal, | |
| full, | |
| } | |
| class MD2Indicator extends Decoration { | |
| final double indicatorHeight; | |
| final Color indicatorColor; | |
| final MD2IndicatorSize indicatorSize; | |
| const MD2Indicator( | |
| {@required this.indicatorHeight, | |
| @required this.indicatorColor, | |
| @required this.indicatorSize}); | |
| @override | |
| _MD2Painter createBoxPainter([VoidCallback onChanged]) { | |
| return new _MD2Painter(this, onChanged); | |
| } | |
| } | |
| class _MD2Painter extends BoxPainter { | |
| final MD2Indicator decoration; | |
| _MD2Painter(this.decoration, VoidCallback onChanged) | |
| : assert(decoration != null), | |
| super(onChanged); | |
| @override | |
| void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { | |
| assert(configuration != null); | |
| assert(configuration.size != null); | |
| Rect rect; | |
| if (decoration.indicatorSize == MD2IndicatorSize.full) { | |
| rect = Offset(offset.dx, | |
| (configuration.size.height - decoration.indicatorHeight ?? 3)) & | |
| Size(configuration.size.width, decoration.indicatorHeight ?? 3); | |
| } else if (decoration.indicatorSize == MD2IndicatorSize.normal) { | |
| rect = Offset(offset.dx + 6, | |
| (configuration.size.height - decoration.indicatorHeight ?? 3)) & | |
| Size(configuration.size.width - 12, decoration.indicatorHeight ?? 3); | |
| } else if (decoration.indicatorSize == MD2IndicatorSize.tiny) { | |
| rect = Offset(offset.dx + configuration.size.width / 2 - 8, | |
| (configuration.size.height - decoration.indicatorHeight ?? 3)) & | |
| Size(16, decoration.indicatorHeight ?? 3); | |
| } | |
| final Paint paint = Paint(); | |
| paint.color = decoration.indicatorColor ?? Color(0xff1967d2); | |
| paint.style = PaintingStyle.fill; | |
| canvas.drawRRect( | |
| RRect.fromRectAndCorners(rect, | |
| bottomRight: Radius.circular(8), | |
| bottomLeft: Radius.circular(8), | |
| topRight: Radius.circular(8), | |
| topLeft: Radius.circular(8)), | |
| paint); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment