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);
});
},
),
),
),
),
Related
I want to add text inside cupertino switch like attached image.. Is there a way to do it?
As of today there is no way to customize the CupertinoSwitch in Flutter out of the box, but hey! there are a number of Plugins in pub.dev that could satisfy your needs, like flutter_switch.
With the following code you can achieve something like what you want:
FlutterSwitch(
showOnOff: true,
value: v,
activeIcon: Text("SELL"),
activeText: "BUY",
inactiveIcon: Text("BUY"),
inactiveText: "SELL",
inactiveColor: Colors.blue,
activeTextFontWeight: FontWeight.normal,
inactiveTextFontWeight: FontWeight.normal,
onToggle: (val) {
setState(() {
v = val;
});
},
)
which looks like this:
That is of course just a sample, you can further customize to get a more beautiful result.
I create custom widget but without cupertinoswitch animation in it. I hope this match your needs =))
GestureDetector(
onTap: () {
setState(() {
val = !val;
});
},
child: Container(
width: size.width * 0.35,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: kSecondaryColor),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Container(
width: 60,
height: 30,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(30),
color: val
? Colors.white
: kSecondaryColor),
child: Center(
child: Text(
'BUY',
style: TextStyle(
fontWeight: FontWeight.bold,
color: val
? Colors.black
: Colors.white),
)),
),
Container(
width: 60,
height: 30,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(30),
color: val
? kSecondaryColor
: Colors.white),
child: Center(
child: Text(
'SELL',
style: TextStyle(
fontWeight: FontWeight.bold,
color: val
? Colors.white
: Colors.black),
)),
),
],
),
),
),
),
add text inside cupertinoswitch flutter
customSwitcher: CupertinoSwitch(
value: model.enableBiometric == 'enable' ? true: false,
activeColor: Color.transparent,
trackColor: Color.transparent,
onChanged: (bool val) {
model.enableBiometric =
(model.enableBiometric == "disable"
? 'enable'
: 'disable');
},),
Container(
width: 70,
height: 36,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular((100)),
border: Border.all(
width: 1.0,
color: model?.enableBiometric == 'enable'
? Color.red
: Color.red,
),
color: Color.red),
child: Row(children: [
if (model?.enableBiometric == "enable")...[
Padding(
padding: EdgeInsets.only(left:model?.enableBiometric == "enable" ? 12 : 0),
child: AppText(
txt:model?.enableBiometric == "enable" ? "Yes" : "",
fontSize: 11,
fontWeight:800,
),
),
] else ...[
SizedBox(
width: 4.0.w,
),
],
Expanded(
child: Container(
// width: ch(12),
//color: AppColor.red,
child: Transform.scale(
transformHitTests: false,
scale: 1.0,
child: customSwitcher!,
),
)),
if (model?.enableBiometric == "disable") ...[
Padding(
padding: EdgeInsets.only(
right:
model?.enableBiometric == "disable" ? 12 : 0),
child: AppText(
txt:
model?.enableBiometric == "disable" ? "No" : "",
fontSize: 11,
fontWeight: 800,
),
),
] else ...[
SizedBox(
width: 4.0.w,
),
]
]),
),
I want to make a combo/dropdown with the circular border which looks like this. How to design this in Flutter?
In Flutter, you can create a combo with a circular border using the Container widget and setting the decoration property to a BoxDecoration with a shape of BoxShape.circle.
Here's an example:
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(width: 2, color: Colors.blue)
),
child: ... // add the combo content here
)
You can customize the border width and color by adjusting the width and color properties of the Border object, respectively.
You can achieve this with this code.
Container(
padding: EdgeInsets.symmetric(horizontal: 20.0),
width: displayWidth(context) * 0.8,
height: 40.0,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black, //Change the border color as your choice
),
borderRadius: BorderRadius.circular(20),
),
child: DropdownButton<String>(
value: dropdownValue,
isExpanded: true,
icon: const Icon(Icons.keyboard_arrow_down),
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
onChanged: (String? value) {
// This is called when the user selects an item.
setState(() {
dropdownValue = value!;
});
},
items: list.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
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:
I am developing a bottom navigation bar which hides upon scrolling up, but I'm unable to achieve the desired result. I have 2 containers with different widgets to handle the separately. In first containers, there are 2 text widgets with a slider and second container has 5 icon buttons. I wat to reduce the space between Texts and slider and align the play_button in vertical centerzz. What I'm trying to make is this:
What have I developed:
this is my code:
bottomNavigationBar: ValueListenableBuilder(
valueListenable: hiding.visible,
builder: (context, bool value, child) => AnimatedContainer(
color: light_mode? Color(0xFFFFFFFF) : Color(0xFF616161),
duration: Duration(milliseconds: 500),
height: value ? 100 : 0.0,
child: Wrap(
runAlignment: WrapAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(5, 1, 5, 1),
padding: EdgeInsets.all(5),
height: 30,
width: MediaQuery.of(context).size.width,
child: Row(
children: <Widget>[
Text("0:00", style: TextStyle(color: Colors.black), textAlign: TextAlign.left),
Container(
margin: EdgeInsets.all(2),
height: 30,
width: MediaQuery.of(context).size.width-80,
child:SliderTheme(
data: SliderThemeData(
thumbColor: light_mode? Color(0xFF6A0080) : Colors.black,
activeTrackColor: light_mode?Color(0xFF6A0080) : Colors.black,
inactiveTrackColor: Colors.grey,
trackHeight: 1.0,
),
child: Slider(
value: 60.0,
max: 100.0,
min: 0.0,
onChanged: (double newValue) {
setState(() {
// sliderValue = newValue.round();
});
},
))),
Text("0:00", style: TextStyle(color: Colors.black), textAlign: TextAlign.right)
],
),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.fromLTRB(20, 1, 20, 16),
padding: EdgeInsets.all(8.0),
height: 50,
width: MediaQuery.of(context).size.width,
child: Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
children: <Widget>[
IconButton(
alignment: Alignment.center,
icon: Icon(
Icons.skip_previous,
color: Colors.grey,
size: 30,
),
onPressed: () {
// do something
},
),
IconButton(
padding: EdgeInsets.all(8.0),
icon: Icon(
Icons.play_circle_fill_rounded,
color: light_mode? Color(0xFFEA80FC) : Color(0xFF6D6D6D) ,
size: 45,
),
onPressed: () {
// do something
},
)
,
IconButton(
icon: Icon(
Icons.skip_next,
color: Colors.grey,
size: 30,
),
onPressed: () {
// do something
},
)
,
IconButton(
icon: Icon(
Icons.bookmark_border_outlined,
color: Colors.grey,
size: 35.0,
),
onPressed: () {
// do something
},
)
,
IconButton(
icon: Icon(
Icons.share_rounded,
color: Colors.grey,
),
onPressed: () {
// do something
},
)
],
),
)
],
),
)),
How can i properly align icons in lesser space?
to reduce the space between text and slider you need to give a custom shape to it. So for that create a shape as show below:-
class CustomTrackShape extends RoundedRectSliderTrackShape {
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);
}
}
and then in your slider theme:-
SliderTheme(
data: SliderThemeData(
thumbColor: light_mode? Color(0xFF6A0080) : Colors.black,
activeTrackColor: light_mode?Color(0xFF6A0080) : Colors.black,
inactiveTrackColor: Colors.grey,
trackHeight: 1.0,
trackShape: CustomTrackShape(),//call your custom shape over here
),
child: Slider(
value: 60.0,
max: 100.0,
min: 0.0,
onChanged: (double newValue) {
setState(() {
// sliderValue = newValue.round();
});
},
)),
and for proper alignment of container remove the padding from top and bottom of your container containing thos icons i.e. change padding from padding:EdgeInsets.all(8.0) to padding:EdgeInsets.symmetric(horizontal:8.0), becuase the size of the container is 50 and of icon is 45 and you are providing padding of 10 pixels(5 from top and 5 from bottom) this means container height should be 55. So either increase the height upto 60 or change padding code.
The Code below only changes the slider from 1-10, how do you change the text while changing the slider as well in Flutter?
The Text is fetched from an API.
double _value = 0.0;
[enter image description here][1] bool _slider = false;
child: _slider == true
? new Container(
margin: EdgeInsets.only(right: 10),
decoration: new BoxDecoration(
color: NNDColors.main,
borderRadius: new BorderRadius.all(
new Radius.circular(5.0)),
boxShadow: [
new BoxShadow(
color: Colors.black38,
offset: new Offset(0.0, 2.0),
blurRadius: 10)
]),
child: new Slider(
value: _value,
activeColor: Colors.white,
inactiveColor: Colors.white,
onChanged: (double s) => _changed(s),
divisions: 10,
min: 0.0,
max: 10.0,
),
void _changed(s) {
setState((){
_value = s;
});
}
Output:
Here is how you can do it.
double _value = 5;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Testing")),
body: Center(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(right: 10),
decoration: new BoxDecoration(
color: Colors.blue,
borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
boxShadow: [new BoxShadow(color: Colors.black38, offset: new Offset(0.0, 2.0), blurRadius: 10)]),
child: new Slider(
value: _value,
activeColor: Colors.white,
inactiveColor: Colors.white,
onChanged: (double s) {
setState(() {
_value = s;
});
},
divisions: 10,
min: 0.0,
max: 10.0,
),
),
Text("Hello World", style: TextStyle(fontSize: 10 * _value)),
],
),
),
);
}