mucke/lib/presentation/pages/album_details_page.dart

133 lines
4.2 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';
import 'package:provider/provider.dart';
2020-03-28 11:08:43 +01:00
import '../../domain/entities/album.dart';
import '../../domain/entities/song.dart';
import '../state/audio_store.dart';
import '../state/music_data_store.dart';
2020-03-28 11:08:43 +01:00
import '../utils.dart' as utils;
import '../widgets/song_list_tile.dart';
2020-03-28 11:08:43 +01:00
class AlbumDetailsPage extends StatelessWidget {
const AlbumDetailsPage({Key key, @required this.album}) : super(key: key);
final Album album;
@override
Widget build(BuildContext context) {
final MusicDataStore musicDataStore = Provider.of<MusicDataStore>(context);
final AudioStore audioStore = Provider.of<AudioStore>(context);
return Observer(
builder: (BuildContext context) => CustomScrollView(
slivers: <Widget>[
SliverAppBar(
brightness: Brightness.dark,
pinned: true,
expandedHeight: 250.0,
2020-05-09 19:46:06 +02:00
backgroundColor: Theme.of(context).primaryColor,
2020-08-12 20:59:00 +02:00
iconTheme: const IconThemeData(
color: Colors.white,
),
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
titlePadding: const EdgeInsets.only(
bottom: 16.0,
left: 16.0,
right: 16.0,
),
title: Text(
album.title,
2020-08-12 20:59:00 +02:00
style: const TextStyle(
fontWeight: FontWeight.w300,
fontSize: 16.0,
color: Colors.white,
),
textAlign: TextAlign.center,
),
background: Stack(
children: [
Positioned(
left: 0,
right: 0,
child: Image(
image: utils.getAlbumImage(album.albumArtPath),
),
),
Container(
color: Colors.black45,
),
],
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(_, int index) {
if (index.isEven) {
final songIndex = (index / 2).round();
2020-11-15 16:36:50 +01:00
final Song song =
musicDataStore.albumSongStream.value[songIndex];
return SongListTile(
song: song,
inAlbum: true,
2020-11-15 16:36:50 +01:00
onTap: () => audioStore.playSong(
songIndex, musicDataStore.albumSongStream.value),
onTapMore: () => _openBottomSheet(song, context),
);
}
return const Divider(
height: 4.0,
);
},
semanticIndexCallback: (Widget widget, int localIndex) {
if (localIndex.isEven) {
return localIndex ~/ 2;
}
return null;
},
2020-11-15 16:36:50 +01:00
childCount: musicDataStore.albumSongStream.value.length * 2,
),
2020-04-04 21:02:42 +02:00
),
2020-03-28 11:08:43 +01:00
],
),
);
}
2020-11-15 16:36:50 +01:00
void _openBottomSheet(Song song, BuildContext context) {
final AudioStore audioStore =
Provider.of<AudioStore>(context, listen: false);
final MusicDataStore musicDataStore =
Provider.of<MusicDataStore>(context, listen: false);
showModalBottomSheet(
context: context,
builder: (context) {
return Container(
child: Column(
children: [
ListTile(
title: const Text('Add to queue'),
onTap: () {
audioStore.addToQueue(song);
Navigator.pop(context);
},
),
ListTile(
title: song.blocked
? const Text('Unblock song')
: const Text('Block song'),
onTap: () {
musicDataStore.setSongBlocked(song, !song.blocked);
Navigator.pop(context);
},
),
],
),
);
});
}
2020-03-28 11:08:43 +01:00
}