You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
import 'package:flutter/Material.dart';
|
|
|
|
import '../main.dart';
|
|
import '../model/Music.dart';
|
|
|
|
class ButtonPlayComponent extends StatefulWidget {
|
|
final Music music;
|
|
const ButtonPlayComponent({super.key, required this.music});
|
|
|
|
@override
|
|
State<ButtonPlayComponent> createState() => _ButtonPlayComponentState();
|
|
}
|
|
|
|
class _ButtonPlayComponentState extends State<ButtonPlayComponent> {
|
|
bool isPlaying = false;
|
|
|
|
@override
|
|
void initState() {
|
|
MyApp.audioPlayer.onPlayerComplete.listen((event) {
|
|
setState(() {
|
|
isPlaying = false;
|
|
});
|
|
});
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
if (isPlaying) {
|
|
widget.music.stopSong();
|
|
setState(() {
|
|
isPlaying = !isPlaying;
|
|
});
|
|
} else {
|
|
widget.music.playSong();
|
|
setState(() {
|
|
isPlaying = !isPlaying;
|
|
});
|
|
}
|
|
},
|
|
child: Icon(
|
|
isPlaying ? Icons.pause_circle : Icons.play_circle,
|
|
color: Colors.white,
|
|
size: 53,
|
|
),
|
|
));
|
|
}
|
|
}
|