Created
June 23, 2020 07:13
-
-
Save abdulazizahwan/9b9719469d91378c010cefb87b17c474 to your computer and use it in GitHub Desktop.
Dart code for custom tab indicator
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
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