ocarina2/lib/views/album_view.dart
2024-05-28 18:54:05 +02:00

78 lines
2.2 KiB
Dart

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(),
body: SizedBox(
width: 100.w,
height: 100.h,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
HeroBanner(
cacheKey: widget.album.coverArtId,
imageUrl: widget.album.coverArtUrl,
title: widget.album.name,
description: widget.album.artistName,
),
SizedBox(
height: 65.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(),
);
setState(() {});
},
child: SongRow(
imageUrl: _songs[i].coverArtUrl,
songTitle: _songs[i].title,
),
),
itemCount: _songs.length,
),
),
],
),
),
);
}
}