How to make half circular slider in flutter - 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.

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

Flutter sleek_circular_slider full circle

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);
});

How to make music slider, start time and end time?

I want to make music slider like this:
slider image
I am new to dart so please forgive any mistakes in the question.
I am just confused on how to set the time elapsed playing and total time.
my code:
double sliderValue = 0;
Duration max = const Duration(seconds: 120);
Row(
children: [
Text('${sliderValue.toInt()}'),
Slider(
value: sliderValue,
min: 0,
max: max.inSeconds.toDouble(),
onChanged: (double value){
setState(() {
sliderValue = value;
});
}
),
Text('${max.inMinutes}')
],
),
One way is to manually implement it. You can do this by first getting the audio length from the metadata of the file. Once you get that, you can show the current progress based on the total.
Another way is to check out this package. Also, you might be using the audio player package. It also has a callback to get the current position of the audio. Check it here.

Flutter audio slider with assets_audio_player ,

Flutter audio slider with assets_audio_player
I'm trying to create a slider to watch the audio progress and seek some parts of the audio. In order to play local audio files I'm using the assets_audio_player package. This is my code:
Here's an example, position and duration are both Duration() variables
Widget slider() {
return Slider(
value: _position.inSeconds.toDouble(),
min: 0.0,
max: _duration.inSeconds.toDouble(),
onChanged: (double value) {
setState(() {
seekToSecond(value.toInt());
value = value;
});});
}

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);
});