Flutter : Slider custom Tooltip - flutter

I want to make the custom tooltip with a background shadow for Slider in my app. Here is my code for the current slider.
SliderTheme(
data: SliderThemeData(
activeTrackColor: AppColor.royalGreen,
inactiveTrackColor: AppColor.black12,
thumbColor: AppColor.royalGreen,
thumbShape: CircleSliderThumbShape(),
showValueIndicator: ShowValueIndicator.always,
valueIndicatorColor: AppColor.white,
valueIndicatorTextStyle: TextStyles.sliderTooltipText,
// overlayShape: SliderComponentShape.noOverlay,
// overlayColor: AppColor.behan24
),
child: Slider(
value: _currentSliderValue,
onChanged: (double value) {
setState(() {
_currentSliderValue = value;
});
},
label: "${_currentSliderValue.toString().split('.')[0] + 'L'}",
min: 5,
max: 50,
),
),
This is what I want to achieve.
What I have achieved so far.
Any help will be appreciable. Thanks

I recommend using the library flutter_xlider
With this, you can customize using the Tooltip and add a shadow to create the effect of elevation.
FlutterSlider(
values: [300],
max: 500,
min: 0,
onDragging: (handlerIndex, lowerValue, upperValue) {
_lowerValue = lowerValue;
_upperValue = upperValue;
setState(() {});
},
tooltip: FlutterSliderTooltip(
textStyle: TextStyle(fontSize: 17, color: Colors.black),
boxStyle: FlutterSliderTooltipBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
)),
),
This is what you will achieve:

Related

Flutter slider overlay color

I have changed the color of the overlay but it still does not take effect as it maintains the color of the thumbShape instead.
SliderTheme(
data: SliderTheme.of(context).copyWith(
thumbColor: Color(0xFFEB1555),
activeTrackColor: Colors.white,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 15.0),
overlayShape: RoundSliderThumbShape(enabledThumbRadius: 25.0),
overlayColor: Color(0x29EB1555),
),
child: Slider(
value: height.toDouble(),
min: 122.0,
max: 220.0,
inactiveColor: Color(0xFF8D8E98),
onChanged: (double newValue) {
setState(() {
height = newValue.round();
});
},
),
),
I removed the overlayShape.
I think it was overriding the color I wanted to use.
You can use the inactive and active track color in your theme to avoid this problem.
SliderTheme(
data: SliderThemeData(
thumbShape: RoundSliderThumbShape(
enabledThumbRadius: 15,
),
overlayColor: Color(0x29eb1555),
activeTrackColor: Colors.white,
inactiveTrackColor: Color(0xff8d8e98),
thumbColor: Color(0xffeb1555),
),
child: Slider(
value: height.toDouble(),
min: 120,
max: 220,
onChanged: (value) {
setState(() {
height = value.round();
});
},
),
),
You used RoundSliderThumbShape for both thumbShape and overlayShape. Instead, use RoundSliderOverlayShape for overlayShape property, and you are good to go.
data: SliderTheme.of(context).copyWith(
thumbColor: Color(0xFFEB1555),
activeTrackColor: Colors.white,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 15.0),
overlayShape: RoundSliderOverlayShape(overlayRadius: 25.0), // Change in here
overlayColor: Color(0x29EB1555),
),

How to change height and width of SfSlider in flutter?

I am using -> SfSlider library to create a slider. To change the size of thumb, i just change the thumbIcon inside it by creating a Container(height:20, width:10,).
But i think its height and width are not reflecting when i change the Container() height and width, these are changing only when i change the thumbRadius.
I am getting below result-
But i want below result -
How to do that? My flutter code is below :
Container(
child: SfSliderTheme(
data: SfSliderThemeData(
activeTrackHeight: 8,
thumbColor: Colors.transparent,
thumbRadius: 15,
thumbStrokeWidth: 0,
activeTrackColor: myColor,
inactiveTrackColor: Colors.black12,
thumbStrokeColor: Colors.black45,
),
child: Center(
child: SfSlider(
showLabels: false,
value: _sliderValue,
min: 5000,
max: 500000,
interval: 1000,
thumbIcon: Container(
height: 30.0,
width: 10,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: myColor,
borderRadius: BorderRadius.all(Radius.circular(8.0))),
),
onChanged: (value) {
setState(() {
_sliderValue = value;
print("slider value" + _sliderValue.toString());
// _amountController.text = value.floor().toString();
_amountController.text =
getChangedAmount(value.floor().toString());
// print("amount controller value" + _amountController.text);
});
},
),
),
),
),

Why parent class is accepting color from child?

I'm working on Slider, I want to change the thumb color, but this is not working. thumbColor accepts color from Child:Slider activeColor.
SliderTheme(
data:SliderTheme.of(context).copyWith(
// thumbShape: RoundSliderThumbShape(enabledThumbRadius: 19.0),
// overlayColor: Colors.grey,
thumbColor: Colors.white,
),
child: Slider(
inactiveColor: Colors.transparent,
min: 0,
activeColor: Color(0xffF3C961),
value: value.toDouble(),
max: MediaQuery.of(context).size.height,
onChanged: (changedValue){
setState(() {
value = changedValue.toInt();
});
},
),
),[![You can check color of thumb shape][1]][1]

How to set slider overlay color?

I'm trying to set slider overlay color but it seems that it only works if I comment out overlayShape: RoundSliderThumbShape(enabledThumbRadius: 30), how to I set both?
P.S. Relevant part code is marked with comments
SliderTheme(
data: SliderTheme.of(context).copyWith(
activeTrackColor: kDefaultColor,
inactiveTrackColor: kDefaultColor,
thumbColor: kButtonColor,
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 15),
overlayShape: RoundSliderThumbShape(enabledThumbRadius: 30), //focus here
overlayColor: Colors.red //focus here
),
child: Slider(
value: sliderValue.toDouble(),
max: 220,
min: 110,
onChanged: (double value) {
setState(() {
sliderValue = value.round();
});
},
),
),
You should use RoundSliderOverlayShape for overlayShape.
overlayShape: RoundSliderOverlayShape(overlayRadius: 30),

Is there a way to create a button with corner radius, gradient, and with dynamic shadows?

I'm creating a button with corner radius and gradient, but I also want its shadows to react on user press and release. I'm trying out a Container with decoration but no luck since I can't seem to find an onRelease callback. So I'm thinking that I'm on the wrong direction. So is there any way to do this?
This button has exactly what I need:
A gradient, rounded corners, dynamic shadows, ripple effectPadding(
padding: const EdgeInsets.only(bottom: 50),
child: Transform.scale(
scale: btnScale,
child: GestureDetector(
onTapCancel: () {
setState(() {});
btnHeight = 5;
btnScale = 1.0;
},
onTapDown: (loc) {
btnHeight = 0;
btnScale = 0.99;
setState(() {});
},
onTapUp: (loc) {
setState(() {});
btnHeight = 5;
btnScale = 1.0;
},
child: Container(
width: 190,
height: 62,
decoration: BoxDecoration(
boxShadow: [
new BoxShadow(
blurRadius: 4,
color: Colors.black12,
offset: new Offset(
-btnHeight, btnHeight),
),
new BoxShadow(
blurRadius: 4,
color: Colors.black12,
offset: new Offset(
btnHeight, btnHeight),
)
],
borderRadius: BorderRadius.all(
Radius.circular(100)),
gradient: BtnTeal),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius:
(BorderRadius.circular(100)),
onTap: () {},
highlightColor:
const Color(0xFF63DCA0),
splashColor: Colors.teal,
child: Center(
child: Text(
"LOG IN",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 21,
),
),
),
),
),
),
),
),
),