diff --git a/lib/md2_tab_indicator.dart b/lib/md2_tab_indicator.dart index ef78afa..e1d5777 100644 --- a/lib/md2_tab_indicator.dart +++ b/lib/md2_tab_indicator.dart @@ -1,7 +1,7 @@ library md2_tab_indicator; import 'package:flutter/widgets.dart'; - +//*THIS Initial but working null safety update enum MD2IndicatorSize { tiny, normal, @@ -13,59 +13,49 @@ class MD2Indicator extends Decoration { final Color indicatorColor; final MD2IndicatorSize indicatorSize; - const MD2Indicator({ - required this.indicatorHeight, - required this.indicatorColor, - required this.indicatorSize, - }); + const MD2Indicator( + {required this.indicatorHeight, + required this.indicatorColor, + required this.indicatorSize}); @override _MD2Painter createBoxPainter([VoidCallback? onChanged]) { - return _MD2Painter(this, onChanged); + return _MD2Painter(this, onChanged!); } } class _MD2Painter extends BoxPainter { - final MD2Indicator decoration; + final MD2Indicator? decoration; - _MD2Painter(this.decoration, VoidCallback? onChanged) : super(onChanged); + _MD2Painter(this.decoration, VoidCallback onChanged) : super(onChanged); @override void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { assert(configuration.size != null); - Rect rect; - if (decoration.indicatorSize == MD2IndicatorSize.full) { - rect = Offset( - offset.dx, - configuration.size!.height - decoration.indicatorHeight, - ) & - Size(configuration.size!.width, decoration.indicatorHeight); - } else if (decoration.indicatorSize == MD2IndicatorSize.tiny) { + Rect rect = Offset(1.0, 2.0) & const Size(3.0, 4.0); + if (decoration!.indicatorSize == MD2IndicatorSize.full) { rect = Offset( - offset.dx + configuration.size!.width / 2 - 8, - configuration.size!.height - decoration.indicatorHeight, - ) & - Size(16, decoration.indicatorHeight); - } else { - rect = Offset( - offset.dx + 6, - configuration.size!.height - decoration.indicatorHeight, - ) & - Size(configuration.size!.width - 12, decoration.indicatorHeight); + offset.dx, + (configuration.size!.height - + decoration!.indicatorHeight.toDouble())) & + Size(configuration.size!.width, decoration!.indicatorHeight); + } else if (decoration!.indicatorSize == MD2IndicatorSize.normal) { + rect = Offset(offset.dx + 6, + (configuration.size!.height - decoration!.indicatorHeight)) & + Size(configuration.size!.width - 12, decoration!.indicatorHeight); + } else if (decoration!.indicatorSize == MD2IndicatorSize.tiny) { + rect = Offset(offset.dx + configuration.size!.width / 2 - 8, + (configuration.size!.height - decoration!.indicatorHeight)) & + Size(16, decoration!.indicatorHeight); } - final Paint paint = Paint() - ..color = decoration.indicatorColor - ..style = PaintingStyle.fill; - + final Paint paint = Paint(); + paint.color = decoration?.indicatorColor ?? Colors.blue; + paint.style = PaintingStyle.fill; canvas.drawRRect( - RRect.fromRectAndCorners( - rect, - topRight: Radius.circular(8), - topLeft: Radius.circular(8), - ), - paint, - ); + RRect.fromRectAndCorners(rect, + topRight: Radius.circular(8), topLeft: Radius.circular(8)), + paint); } }