2024-05-23 19:14:08 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:ocarina/api/audio/audioplayer_service.dart';
|
|
|
|
import 'package:ocarina/api/subsonic/album.dart';
|
|
|
|
import 'package:ocarina/api/subsonic/song.dart';
|
|
|
|
import 'package:ocarina/api/subsonic/subsonic.dart';
|
|
|
|
import 'package:ocarina/main.dart';
|
|
|
|
import 'package:ocarina/widgets/hero_banner.dart';
|
|
|
|
import 'package:ocarina/widgets/song_row.dart';
|
|
|
|
import 'package:responsive_sizer/responsive_sizer.dart';
|
|
|
|
|
|
|
|
class AlbumView extends StatefulWidget {
|
|
|
|
const AlbumView({required this.album, super.key});
|
|
|
|
final Album album;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<AlbumView> createState() => _AlbumViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AlbumViewState extends State<AlbumView> {
|
|
|
|
final _songs = <Song>[];
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
loadSongs();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> loadSongs() async {
|
|
|
|
_songs
|
|
|
|
..clear()
|
|
|
|
..addAll(await SubsonicApiService().getSongList(widget.album.id) ?? []);
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(),
|
2024-06-21 13:08:40 +02:00
|
|
|
body: Align(
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: SizedBox(
|
|
|
|
width: 100.w,
|
|
|
|
height: 90.h,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
HeroBanner(
|
|
|
|
cacheKey: widget.album.coverArtId,
|
|
|
|
imageUrl: widget.album.coverArtUrl,
|
|
|
|
title: widget.album.name,
|
|
|
|
description: widget.album.artistName,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 46.h,
|
|
|
|
width: 95.w,
|
|
|
|
child: ListView.builder(
|
|
|
|
itemBuilder: (c, i) => InkWell(
|
|
|
|
onTap: () async {
|
|
|
|
playerKey.currentState?.update();
|
|
|
|
await AudioPlayerService().playNow(
|
|
|
|
queueNext: _songs.getRange(i, _songs.length).toList(),
|
|
|
|
queuePast:
|
|
|
|
(i == 0) ? [] : _songs.getRange(0, i).toList(),
|
|
|
|
);
|
2024-05-23 19:14:08 +02:00
|
|
|
|
2024-06-21 13:08:40 +02:00
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: SongRow(
|
|
|
|
imageUrl: _songs[i].coverArtUrl,
|
|
|
|
songTitle: _songs[i].title,
|
|
|
|
),
|
2024-05-23 19:14:08 +02:00
|
|
|
),
|
2024-06-21 13:08:40 +02:00
|
|
|
itemCount: _songs.length,
|
2024-05-23 19:14:08 +02:00
|
|
|
),
|
|
|
|
),
|
2024-06-21 13:08:40 +02:00
|
|
|
],
|
|
|
|
),
|
2024-05-23 19:14:08 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|