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.
Related
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
I am currently using a SpriteAnimationWidget from Flame, and I want to have different animations by clicking buttons.
To test out if this works, I am changing the animation parameter of the SpriteAnimationWidget with a button click. After 1 second, the widget has to return to its original animation.
Here is my code:
Future<void> playReaction() async {
setState(() {
isPlaying = true;
state = 'reaction';
});
await Future.delayed(Duration(milliseconds: 1000));
setState(() {
isPlaying = false;
state = 'idle';
});
}
And inside the build, I am returning:
if(state == 'reaction') {
spriteAnimation = reactionSprite!.createAnimation(row: 0, stepTime: 0.1, from: 0, to: 10);
print('reaction');
}
else if(state == 'idle'){
spriteAnimation = sprite!.createAnimation(row: 1, stepTime: 0.2, from: 0, to: 4);
print('idle');
}
return Container(
height: widget.size,
child: Stack(
fit: StackFit.expand,
children: [
Positioned.fill(
child: SpriteAnimationWidget(
animation: spriteAnimation!,
anchor: Anchor.center,
)
),
]
),
);
The variables sprite and reactionSprite are sprite sheets that I preload using SpriteSheet.fromColumnsAndRows().
The problem is that, although my app successfully runs playReaction() and reaches print('reaction'), the SpriteAnimationWidget is still playing the idle animation instead of the reaction animation. I know that it's being rebuilt somehow because I can see that there is a slight unnatural discontinuity in the animation when I hit the button (plus the print messages).
Why is setState() not updating the SpriteAnimationWidget with a new animation parameter?
I am relatively new to Flutter and Flame, so I would love some help or advice.
ps. I tried using the same sprite sheet for the change with a different row (instead of using a completely different sprite sheet as in the code above), but the result was the same.
This was actually a bug, we are fixing it here.
Meanwhile, as a workaround, you can change the key of the widget every time that you change the animation and it should update the widget.
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;
});});
}
As I am quite new to Flutter I can't seem to figure this out on my own. I am wondering if it's possible to display strings from a list instead of the numbers in a Slider? F.ex. If Slider number = 1, display label "Age 1". It seems that I am always coming back to carousels, but they don't act/look like what I want. At the moment I have a dropdownbutton with 18 items, and it's a bit disorganized/ugly displaying it in that manner. It also follows a linear path from Newborn to 12 years.
I don't have any code on this, as all attempts I've made hasn't lead me anywhere. Thus I am asking if anyone knows a way to do this, tips or a solution. All help is welcome!
You need something like this:
double _currentSliderValue = 0;
var result =['one','two','three'];
and then:
Slider(
value: _currentSliderValue,
min: 0,
max: 2,
divisions:2,
label: result[_currentSliderValue.toInt()],
onChanged: (double value) {
setState(() {
_currentSliderValue = value;
});
},
)
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.