Created
November 13, 2022 06:04
-
-
Save BarryDaBee/e9f5bfd36c0abc8b3b95107193054efc to your computer and use it in GitHub Desktop.
Custom track shape for flutter slider widget without height
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 CustomTrackShape extends RoundedRectSliderTrackShape { | |
@override | |
Rect getPreferredRect( | |
{required RenderBox parentBox, | |
Offset offset = Offset.zero, | |
required SliderThemeData sliderTheme, | |
bool isEnabled = false, | |
bool isDiscrete = false}) { | |
final double? trackHeight = sliderTheme.trackHeight; | |
final double? trackLeft = offset.dx; | |
final double? trackTop = | |
offset.dy + (parentBox.size.height - trackHeight!) / 2; | |
final double? trackWidth = parentBox.size.width; | |
return Rect.fromLTWH(trackLeft!, trackTop!, trackWidth!, trackHeight); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment