2020-03-28 11:08:43 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
2020-04-07 21:25:01 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2020-03-28 11:08:43 +01:00
|
|
|
|
|
|
|
import '../../domain/entities/album.dart';
|
2020-04-07 21:25:01 +02:00
|
|
|
import '../state/music_data_store.dart';
|
2020-03-28 11:08:43 +01:00
|
|
|
import '../widgets/album_art_list_tile.dart';
|
|
|
|
import 'album_details_page.dart';
|
|
|
|
|
|
|
|
class AlbumsPage extends StatelessWidget {
|
2020-04-07 21:25:01 +02:00
|
|
|
const AlbumsPage({Key key}) : super(key: key);
|
2020-03-28 11:08:43 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) => Observer(builder: (_) {
|
2020-04-03 13:55:15 +02:00
|
|
|
print('AlbumsPage.build');
|
2020-04-07 21:25:01 +02:00
|
|
|
final MusicDataStore store = Provider.of<MusicDataStore>(context);
|
2020-03-28 11:08:43 +01:00
|
|
|
final ObservableFuture<List<Album>> future = store.albumsFuture;
|
|
|
|
|
|
|
|
switch (future.status) {
|
|
|
|
case FutureStatus.pending:
|
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: const <Widget>[
|
|
|
|
CircularProgressIndicator(),
|
|
|
|
Text('Loading items...'),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
case FutureStatus.rejected:
|
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: const <Widget>[
|
|
|
|
Text(
|
|
|
|
'Failed to load items.',
|
|
|
|
style: TextStyle(color: Colors.red),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
case FutureStatus.fulfilled:
|
|
|
|
final List<Album> albums = future.result as List<Album>;
|
|
|
|
return ListView.separated(
|
|
|
|
itemCount: albums.length,
|
|
|
|
itemBuilder: (_, int index) {
|
|
|
|
final Album album = albums[index];
|
|
|
|
return AlbumArtListTile(
|
|
|
|
title: album.title,
|
|
|
|
subtitle: album.artist,
|
|
|
|
albumArtPath: album.albumArtPath,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute<Widget>(
|
|
|
|
builder: (BuildContext context) => AlbumDetailsPage(
|
|
|
|
album: album,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
separatorBuilder: (BuildContext context, int index) =>
|
2020-04-04 21:02:42 +02:00
|
|
|
const Divider(
|
|
|
|
height: 4.0,
|
|
|
|
),
|
2020-03-28 11:08:43 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return const Center(
|
|
|
|
child: Text('Library Page'),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|