Flutter sleek_circular_slider full circle - flutter

I'm using sleek_circular_slider package, but i don't know how to be
the widget as circle, by default it is not
final slider = SleekCircularSlider(
appearance: CircularSliderAppearance(
customWidths: CustomSliderWidths(progressBarWidth: 10)),
min: 10,
max: 28,
initialValue: 14,
);

The package documentation states that the slider object takes an appearance parameter of type CircularSliderAppearance. You can then set angleRange as a parameter on the appearance to get whatever range you require. By default docs state it is 240 degrees.
To get a complete circle, the code would look something like:
final slider = SleekCircularSlider(
appearance: CircularSliderAppearance(angleRange: 360),
onChange: (double value) {
print(value);
});

Related

Change playback speed in flutter video_player package

I want to change the playback speed of the video with the flutter video_player package and save it to the gallery. I changed the playback speed with the property controller.setPlaybackSpeed ​​but I couldn't find how to get the change information of the modified video.
Slider(
value: blur, min: 1, max: 5, onChanged: (value) {
setState(() {
blur = value;
_controller.setPlaybackSpeed(blur);
});
},) ,
I tried to find it with controller.dataSource and controller.value properties but I couldn't find it

Difference between SliderThemeData().copyWith(...) and SliderTheme.of(context).copyWith(...)

I am new to flutter and was trying to change the slider style other than the default one. I found that it can be done using either SliderThemeData().copyWith(...) or SliderTheme.of(context).copyWith(...) and they are working exactly the same way. What is the difference between these two?
SliderTheme(
// data: SliderThemeData().copyWith(),
child: Slider(
activeColor: Color(0xFFEB1555),
inactiveColor: Color(0xFF8D8E98),
onChanged: (double value) {
},
value: 10
min: 10,
max: 100,
),
),
The difference is that if you customized the theme, you need to obtain it with SliderThemeData.of(context), the .of method looks up and returns the closest SliderTheme in the widget tree. You can read more about this here.
The SliderThemeData() generates a brand new SliderThemeData with the default values because you called the constructor with no additional parameters.
The .copyWith() method creates copy of this object but with the given fields replaced with the new values.

How to make half circular slider in flutter

I am new to flutter. I am developing a music app. I want to half(180°) or more then half(180°-240°) circular slider which increase or decrease the volume.
Note:
You can use the sleek_circular_slider from pub.dev
Add the dependency to pubspec.yaml
dependencies:
sleek_circular_slider : ^1.1.0
Run flutter packages get to fetch the dependencies.
Import it to your project file
import 'package:sleek_circular_slider/sleek_circular_slider.dart';
Then you can create the slider like so -
final SleekCircularSlider(
min: 0,
max: 100,
initialValue: 0,
onChange: (double value) {
// callback providing a value while its being changed (with a pan gesture)
},
onChangeStart: (double startValue) {
// callback providing a starting value (when a pan gesture starts)
},
onChangeEnd: (double endValue) {
// callback providing an ending value (when a pan gesture ends)
},
innerWidget: (double value) {
//This the widget that will show current value
return Center(child: Text("${value.toInt().toString()} %", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.w200),));
},
),
This will create something like this -
You can read about more customization options here.

How do I Convert Flutter slider double value to int

I'm writing code for BMI calculator, and I'm using the slider for height and it returns a double type a long one. I tried _startHeight.toInt() but in vain. And Is there any way to show label without using division.
Here is my slider code.
Slider(
value: _startHeight,
min: 1,
max: 100,
onChanged: (newHeight) {
setState(() {
_startHeight = newHeight;
_startHeight.toInt();
print(_startHeight);
});
},
),
Thank you.
if you want _startHeight to be an int then I assumed you defined it to be an int in the first place.
you are trying to assign a double to an int, and then to change this double to int. you need to do it the other way around:
onChanged: (double newHeight) {
setState(() {
_startHeight = newHeight.toInt();
print(_startHeight);
});
}
If your ultimate goal is to display the value in a String without decimal, then you can use toStringAsFixed:
_startHeight.toStringAsFixed(0);

How to show the menu of PopupMenuButton from the code

PopupMenuButton opens a menu when user clicks on it. But how do I do open the same menu at the same place as the PopupMenuButton from the code(e.g. due to another user event)?
I am trying to create a nested menu in the AppBar. Like when user clicks on "Sort by" then menu changes to something else. Is there another way to achieve this? I could not find it on the internet.
If you take a look at the sources of PopupMenuButton you can see that it uses showMenu method which is accessible even out of the button's context (potentially comes along with imported material Dart class).
Define a GlobalKey variable and apply it to your PopupMenuButton to have a reference to the context of your button - that's how we get the position of the button on the screen.
Create an array of items for the menu, later to reuse it in both the programmatic call and the physical button itself.
Calculate the position for the menu to appear at, and make the showMenu call.
showMenu returns a Future - listen to its completion to get the chosen item.
// Define these variables somewhere accessible by both the button on `build` & by the programmatic call.
final popupButtonKey = GlobalKey<State>(); // We use `State` because Flutter libs do not export `PopupMenuButton` state specifically.
final List<PopupMenuEntry> menuEntries = [
PopupMenuItem(
value: 1,
child: Text('One'),
),
PopupMenuItem(
value: 2,
child: Text('Two'),
),
];
In your build:
PopupMenuButton(
key: popupButtonKey,
initialValue: null,
itemBuilder: (_) => menuEntries,
// ...
);
To show the menu programmatically:
// Here we get the render object of our physical button, later to get its size & position
final RenderBox popupButtonObject = popupButtonKey.currentContext.findRenderObject();
// Get the render object of the overlay used in `Navigator` / `MaterialApp`, i.e. screen size reference
final RenderBox overlay = Overlay.of(context).context.findRenderObject();
// Calculate the show-up area for the dropdown using button's size & position based on the `overlay` used as the coordinate space.
final RelativeRect position = RelativeRect.fromRect(
Rect.fromPoints(
popupButtonObject.localToGlobal(Offset.zero, ancestor: overlay),
popupButtonObject.localToGlobal(popupButtonObject.size.bottomRight(Offset.zero), ancestor: overlay),
),
Offset.zero & overlay.size, // same as: new Rect.fromLTWH(0.0, 0.0, overlay.size.width, overlay.size.height)
);
// Finally, show the menu.
showMenu(
context: context,
elevation: 8.0, // default value
items: menuEntries,
initialValue: null,
position: position,
).then((res) {
print(res);
});