mucke/lib/presentation/pages/songs_page.dart

68 lines
1.9 KiB
Dart
Raw Normal View History

2020-04-06 22:33:26 +02:00
import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
2020-04-04 21:02:42 +02:00
import 'package:mobx/mobx.dart';
import '../../domain/entities/song.dart';
import '../state/music_store.dart';
import '../widgets/album_art_list_tile.dart';
class SongsPage extends StatefulWidget {
SongsPage({Key key, @required this.store}) : super(key: key);
final MusicStore store;
@override
_SongsPageState createState() => _SongsPageState();
}
2020-04-03 15:51:43 +02:00
class _SongsPageState extends State<SongsPage>
with AutomaticKeepAliveClientMixin {
2020-04-04 21:02:42 +02:00
@override
2020-04-03 15:51:43 +02:00
Widget build(BuildContext context) {
print('SongsPage.build');
2020-04-04 21:02:42 +02:00
2020-04-03 15:51:43 +02:00
super.build(context);
return Observer(builder: (_) {
2020-04-04 21:54:43 +02:00
print('SongsPage.build -> Observer.builder');
2020-04-04 21:02:42 +02:00
final bool isFetching = widget.store.isFetchingSongs;
if (isFetching) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
CircularProgressIndicator(),
Text('Loading items...'),
],
);
} else {
final List<Song> songs = widget.store.songs;
return ListView.separated(
itemCount: songs.length,
itemBuilder: (_, int index) {
final Song song = songs[index];
return AlbumArtListTile(
title: song.title,
subtitle: '${song.artist}${song.album}',
albumArtPath: song.albumArtPath,
2020-04-06 22:33:26 +02:00
onTap: () => _playSong(index, songs),
2020-04-04 21:02:42 +02:00
);
},
separatorBuilder: (BuildContext context, int index) => const Divider(
height: 4.0,
),
);
}
});
2020-04-03 15:51:43 +02:00
}
@override
bool get wantKeepAlive => true;
2020-04-06 22:33:26 +02:00
void _playSong(int index, List<Song> songList) {
widget.store.playSong(index, songList);
// AudioService.playFromMediaId(songList[index].path);
}
}