2020-04-03 13:55:15 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
2020-04-07 21:25:01 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2020-04-03 13:55:15 +02:00
|
|
|
|
|
|
|
import '../../domain/entities/song.dart';
|
2020-04-07 22:06:43 +02:00
|
|
|
import '../state/audio_store.dart';
|
2020-04-07 21:25:01 +02:00
|
|
|
import '../state/music_data_store.dart';
|
2020-04-03 13:55:15 +02:00
|
|
|
import '../widgets/album_art_list_tile.dart';
|
|
|
|
|
|
|
|
class SongsPage extends StatefulWidget {
|
2020-04-07 22:06:43 +02:00
|
|
|
const SongsPage({Key key}) : super(key: key);
|
2020-04-03 13:55:15 +02:00
|
|
|
|
|
|
|
@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
|
|
|
|
2020-04-03 13:55:15 +02:00
|
|
|
@override
|
2020-04-03 15:51:43 +02:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
print('SongsPage.build');
|
2020-04-07 22:06:43 +02:00
|
|
|
final MusicDataStore musicDataStore = Provider.of<MusicDataStore>(context);
|
|
|
|
final AudioStore audioStore = Provider.of<AudioStore>(context);
|
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-07 22:06:43 +02:00
|
|
|
final bool isFetching = musicDataStore.isFetchingSongs;
|
2020-04-04 21:02:42 +02:00
|
|
|
|
|
|
|
if (isFetching) {
|
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: const <Widget>[
|
|
|
|
CircularProgressIndicator(),
|
|
|
|
Text('Loading items...'),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
2020-04-07 22:06:43 +02:00
|
|
|
final List<Song> songs = musicDataStore.songs;
|
2020-04-04 21:02:42 +02:00
|
|
|
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-07 22:06:43 +02:00
|
|
|
onTap: () => audioStore.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-03 13:55:15 +02:00
|
|
|
}
|