Skip to content

Instantly share code, notes, and snippets.

@abdulazizahwan
Created June 23, 2020 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdulazizahwan/9b9719469d91378c010cefb87b17c474 to your computer and use it in GitHub Desktop.
Save abdulazizahwan/9b9719469d91378c010cefb87b17c474 to your computer and use it in GitHub Desktop.
Dart code for custom tab indicator
import 'package:flutter/material.dart';
class RoundedRectangleTabIndicator extends Decoration {
final BoxPainter _painter;
RoundedRectangleTabIndicator(
{@required Color color, @required double weight, @required double width})
: _painter = _RRectanglePainterColor(color, weight, width);
@override
BoxPainter createBoxPainter([onChanged]) => _painter;
}
class _RRectanglePainterColor extends BoxPainter {
final Paint _paint;
final double weight;
final double width;
_RRectanglePainterColor(Color color, this.weight, this.width)
: _paint = Paint()
..color = color
..isAntiAlias = true;
@override
void paint(Canvas canvas, Offset offset, ImageConfiguration cfg) {
final Offset customOffset = offset + Offset(0, cfg.size.height - weight);
//Custom Rectangle
Rect myRect = customOffset & Size(width, weight);
// Custom Rounded Rectangle
RRect myRRect = RRect.fromRectXY(myRect, weight, weight);
canvas.drawRRect(myRRect, _paint);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment