-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from GioPan04/main
Line thumb shape
- Loading branch information
Showing
4 changed files
with
99 additions
and
1 deletion.
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
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
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,55 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
/// A variant of the default circle thumb shape | ||
/// Similar to the one found in Android 13 Media control | ||
class LineThumbShape extends SliderComponentShape { | ||
/// The size of the thumb | ||
final Size thumbSize; | ||
|
||
const LineThumbShape({ | ||
this.thumbSize = const Size(8, 32), | ||
}); | ||
|
||
@override | ||
Size getPreferredSize(bool isEnabled, bool isDiscrete) { | ||
return thumbSize; | ||
} | ||
|
||
@override | ||
void paint( | ||
PaintingContext context, | ||
Offset center, { | ||
required Animation<double> activationAnimation, | ||
required Animation<double> enableAnimation, | ||
required bool isDiscrete, | ||
required TextPainter labelPainter, | ||
required RenderBox parentBox, | ||
required SliderThemeData sliderTheme, | ||
required TextDirection textDirection, | ||
required double value, | ||
required double textScaleFactor, | ||
required Size sizeWithOverflow, | ||
}) { | ||
assert(sliderTheme.disabledThumbColor != null); | ||
assert(sliderTheme.thumbColor != null); | ||
|
||
final colorTween = ColorTween( | ||
begin: sliderTheme.disabledThumbColor, | ||
end: sliderTheme.thumbColor, | ||
); | ||
|
||
final paint = Paint()..color = colorTween.evaluate(enableAnimation)!; | ||
|
||
context.canvas.drawRRect( | ||
RRect.fromRectAndRadius( | ||
Rect.fromCenter( | ||
center: center, | ||
width: thumbSize.width, | ||
height: thumbSize.height, | ||
), | ||
Radius.circular(thumbSize.width), | ||
), | ||
paint, | ||
); | ||
} | ||
} |
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