Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update md2_tab_indicator.dart #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 28 additions & 38 deletions lib/md2_tab_indicator.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library md2_tab_indicator;

import 'package:flutter/widgets.dart';

//*THIS Initial but working null safety update
enum MD2IndicatorSize {
tiny,
normal,
Expand All @@ -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);
}
}