Merge branch 'RESPONSABILITY_PLAYER_LDE'

PHOTO_PICKER_LDE
Lucas Delanier 2 years ago
commit 593f38062e

@ -8,12 +8,12 @@ class MusicListComponent extends StatelessWidget {
final Music music;
final bool playing;
final int index;
final Function(int) selectMusic;
final Function(int) callback;
const MusicListComponent({
Key? key,
required this.music,
required this.playing,
required this.selectMusic,
required this.callback,
required this.index,
}) : super(key: key);
@ -99,7 +99,7 @@ class MusicListComponent extends StatelessWidget {
music.previewUrl != null
? PlayButtonComponent(
music: music,
callback: selectMusic,
callback: callback,
playing: playing,
index: index,
)

@ -3,6 +3,7 @@ import 'package:flutter/Material.dart';
import 'package:flutter_animated_play_button/flutter_animated_play_button.dart';
import 'package:ionicons/ionicons.dart';
import '../main.dart';
import '../model/Music.dart';
class PlayButtonComponent extends StatefulWidget {
@ -24,29 +25,21 @@ class PlayButtonComponent extends StatefulWidget {
class _PlayButtonComponentState extends State<PlayButtonComponent> {
final player = AudioPlayer();
void switchStatePlaying() {
setState(() {
widget.playing = !widget.playing;
});
widget.music.stopSong();
}
@override
void initState() {
player.onPlayerComplete.listen((event) {
switchStatePlaying();
MyApp.audioPlayer.onPlayerComplete.listen((event) {
widget.callback(widget.index);
});
super.initState();
}
@override
Widget build(BuildContext context) {
if (widget.playing) {
widget.music.playSong();
} else {}
return !widget.playing
? GestureDetector(
onTap: () {
widget.music.playSong();
widget.callback(widget.index);
},
child: Container(
@ -59,7 +52,11 @@ class _PlayButtonComponentState extends State<PlayButtonComponent> {
)),
)
: GestureDetector(
onTap: switchStatePlaying,
onTap: () {
widget.music.stopSong();
widget.callback(widget.index);
},
child: Container(
width: 30,
height: 30,

@ -20,6 +20,7 @@ class SearchSongScreen extends StatefulWidget {
class _SearchSongScreenState extends State<SearchSongScreen> {
final ScrollController _scrollController = ScrollController();
final TextEditingController _textEditingController = TextEditingController();
int? playingIndex;
Future<void> resetFullScreen() async {
await SystemChannels.platform.invokeMethod<void>(
@ -62,6 +63,18 @@ class _SearchSongScreenState extends State<SearchSongScreen> {
List<Music> filteredData = [];
void playMusic(int index) {
if (playingIndex == index) {
setState(() {
playingIndex = null;
});
} else {
setState(() {
playingIndex = index;
});
}
}
@override
Widget build(BuildContext context) {
double screenHeight = MediaQuery.of(context).size.height;
@ -104,7 +117,7 @@ class _SearchSongScreenState extends State<SearchSongScreen> {
controller: _textEditingController,
keyboardAppearance: Brightness.dark,
onEditingComplete: resetFullScreen,
onChanged: (value) async {
onSubmitted: (value) async {
if (_textEditingController.text.isEmpty) {
} else if (value == " ") {
print("popular");
@ -155,9 +168,25 @@ class _SearchSongScreenState extends State<SearchSongScreen> {
controller: _scrollController,
itemCount: filteredData.length,
itemBuilder: (context, index) {
if (playingIndex == index) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: MusicListComponent(
music: filteredData[index],
playing: true,
callback: playMusic,
index: index,
),
);
}
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: MusicListComponent(music: filteredData[index]),
child: MusicListComponent(
music: filteredData[index],
playing: false,
callback: playMusic,
index: index,
),
);
}),
))

Loading…
Cancel
Save