mucke/lib/presentation/pages/albums_page.dart

61 lines
1.8 KiB
Dart
Raw Normal View History

2020-03-28 11:08:43 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
2021-05-10 19:19:54 +02:00
import 'package:get_it/get_it.dart';
2020-03-28 11:08:43 +01:00
import '../../domain/entities/album.dart';
import '../state/music_data_store.dart';
2021-06-20 19:10:24 +02:00
import '../state/navigation_store.dart';
2020-03-28 11:08:43 +01:00
import '../widgets/album_art_list_tile.dart';
import 'album_details_page.dart';
2020-08-01 20:14:13 +02:00
class AlbumsPage extends StatefulWidget {
2021-06-20 13:49:21 +02:00
const AlbumsPage({Key? key}) : super(key: key);
2020-03-28 11:08:43 +01:00
@override
2020-08-01 20:14:13 +02:00
_AlbumsPageState createState() => _AlbumsPageState();
}
2020-03-28 11:08:43 +01:00
2020-12-30 18:28:16 +01:00
class _AlbumsPageState extends State<AlbumsPage> with AutomaticKeepAliveClientMixin {
2020-08-01 20:14:13 +02:00
@override
Widget build(BuildContext context) {
print('AlbumsPage.build');
2021-05-10 19:19:54 +02:00
final MusicDataStore store = GetIt.I<MusicDataStore>();
2021-06-20 19:10:24 +02:00
final NavigationStore navStore = GetIt.I<NavigationStore>();
2020-03-28 11:08:43 +01:00
2020-08-01 20:14:13 +02:00
super.build(context);
return Observer(builder: (_) {
print('AlbumsPage.build -> Observer.builder');
2021-06-20 13:49:21 +02:00
final List<Album> albums = store.albumStream.value ?? [];
2021-07-17 22:34:55 +02:00
return Scrollbar(
child: 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: () {
navStore.push(
context,
MaterialPageRoute<Widget>(
builder: (BuildContext context) => AlbumDetailsPage(
album: album,
),
2020-08-01 20:14:13 +02:00
),
2021-07-17 22:34:55 +02:00
);
},
);
},
separatorBuilder: (BuildContext context, int index) => const SizedBox(
height: 4.0,
),
2020-12-30 18:28:16 +01:00
),
);
2020-08-01 20:14:13 +02:00
});
}
@override
bool get wantKeepAlive => true;
2020-03-28 11:08:43 +01:00
}