-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c4cbf7
commit 4be81ec
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class DotIndicator extends Decoration { | ||
const DotIndicator({ | ||
this.color = Colors.white, | ||
this.radius = 4.0, | ||
}); | ||
|
||
final Color color; | ||
final double radius; | ||
|
||
@override | ||
BoxPainter createBoxPainter([VoidCallback? onChanged]) { | ||
return _DotPainter( | ||
color: color, | ||
radius: radius, | ||
onChange: onChanged, | ||
); | ||
} | ||
} | ||
|
||
class _DotPainter extends BoxPainter { | ||
_DotPainter({ | ||
required this.color, | ||
required this.radius, | ||
VoidCallback? onChange, | ||
}) : _paint = Paint() | ||
..color = color | ||
..style = PaintingStyle.fill, | ||
super(onChange); | ||
|
||
final Paint _paint; | ||
final Color color; | ||
final double radius; | ||
|
||
@override | ||
void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { | ||
assert(configuration.size != null); | ||
final Rect rect = offset & configuration.size!; | ||
canvas.drawCircle( | ||
Offset(rect.bottomCenter.dx, rect.bottomCenter.dy - radius), | ||
radius, | ||
_paint); | ||
} | ||
} |