From be816f16e71d85dbeeb3401f1043dd6d42efc680 Mon Sep 17 00:00:00 2001 From: apoleon33 Date: Sun, 14 Jan 2024 17:35:38 +0100 Subject: [PATCH] get more informations on an album --- lib/albumCard/display_as_card.dart | 41 +++++---- lib/albumCard/display_as_list.dart | 30 ++++-- lib/moreInfoMenu.dart | 22 +++-- lib/route/more_info.dart | 142 +++++++++++++++++++++++++++++ 4 files changed, 202 insertions(+), 33 deletions(-) create mode 100644 lib/route/more_info.dart diff --git a/lib/albumCard/display_as_card.dart b/lib/albumCard/display_as_card.dart index 64d94fd..8b6dedd 100644 --- a/lib/albumCard/display_as_card.dart +++ b/lib/albumCard/display_as_card.dart @@ -48,15 +48,18 @@ class DisplayAlbumAsCard extends DisplayAlbum { ), child: SizedBox( width: MediaQuery.of(context).size.width, - child: album.cover == 'assets/default.png' - ? Image.asset( - album.cover, - fit: BoxFit.fitWidth, - ) - : Image.network( - album.cover, - fit: BoxFit.fitWidth, - ), + child: Hero( + tag: album.name, + child: album.cover == 'assets/default.png' + ? Image.asset( + album.cover, + fit: BoxFit.fitWidth, + ) + : Image.network( + album.cover, + fit: BoxFit.fitWidth, + ), + ), )), ), Expanded( @@ -71,13 +74,14 @@ class DisplayAlbumAsCard extends DisplayAlbum { padding: const EdgeInsets.only(left: 8, top: 8), child: Text( - album.name.length > 18 - ? '${album.name.substring(0, 15)}...' - : album.name, - maxLines: 1, - style: Theme.of(context) - .textTheme - .headlineSmall), + album.name.length > 18 + ? '${album.name.substring(0, 15)}...' + : album.name, + maxLines: 1, + style: Theme.of(context) + .textTheme + .headlineSmall, + ), ), Padding( padding: const EdgeInsets.only( @@ -154,13 +158,16 @@ class DisplayAlbumAsCard extends DisplayAlbum { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - const MoreInfoMenu(), + MoreInfoMenu( + album: album, + ), // new Spacer(), Consumer(builder: (context, serviceNotifier, child) { return FilledButton.icon( + icon: SvgPicture.asset( serviceNotifier .currentService.iconPath, diff --git a/lib/albumCard/display_as_list.dart b/lib/albumCard/display_as_list.dart index 1466f36..dea598a 100644 --- a/lib/albumCard/display_as_list.dart +++ b/lib/albumCard/display_as_list.dart @@ -1,4 +1,5 @@ import 'package:cradle/albumCard/display_album.dart'; +import 'package:cradle/route/more_info.dart'; import 'package:flutter/material.dart'; import '../album.dart'; @@ -13,15 +14,18 @@ class DisplayAsList extends DisplayAlbum { return Column( children: [ ListTile( - leading: album.cover == 'assets/default.png' - ? Image.asset( - album.cover, - fit: BoxFit.fitWidth, - ) - : Image.network( - album.cover, - fit: BoxFit.fitWidth, - ), + leading: Hero( + tag: album.name, + child: album.cover == 'assets/default.png' + ? Image.asset( + album.cover, + fit: BoxFit.fitWidth, + ) + : Image.network( + album.cover, + fit: BoxFit.fitWidth, + ), + ), title: Text(album.name), subtitle: Text(album.artist), trailing: Text( @@ -35,8 +39,14 @@ class DisplayAsList extends DisplayAlbum { ), style: ListTileStyle.list, isThreeLine: false, + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => MoreInfo(album: album))); + }, ), - const Divider(indent: 16.0, endIndent: 16.0) + const Divider(indent: 16.0, endIndent: 16.0), ], ); } diff --git a/lib/moreInfoMenu.dart b/lib/moreInfoMenu.dart index e084239..87965fd 100644 --- a/lib/moreInfoMenu.dart +++ b/lib/moreInfoMenu.dart @@ -1,19 +1,29 @@ +import 'package:cradle/album.dart'; +import 'package:cradle/route/more_info.dart'; import 'package:flutter/material.dart'; class MoreInfoMenu extends StatelessWidget { - const MoreInfoMenu({ - super.key, - }); + Album album; + + MoreInfoMenu({super.key, required this.album}); @override Widget build(BuildContext context) { return MenuAnchor(menuChildren: [ MenuItemButton( - child: const Text("yup"), - onPressed: () {}, + leadingIcon: const Icon(Icons.info_rounded), + child: const Text("More info"), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => MoreInfo(album: album), + )); + }, ), MenuItemButton( - child: const Text("we are here"), + leadingIcon: const Icon(Icons.share), + child: const Text("Share"), onPressed: () {}, ) ], builder: builder); diff --git a/lib/route/more_info.dart b/lib/route/more_info.dart new file mode 100644 index 0000000..a75e9a8 --- /dev/null +++ b/lib/route/more_info.dart @@ -0,0 +1,142 @@ +import 'package:cradle/album.dart'; +import 'package:cradle/api/lastfm_api.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; +import 'package:html2md/html2md.dart' as html2md; +import 'package:url_launcher/url_launcher.dart'; +import 'dart:io'; + +class MoreInfo extends StatefulWidget { + Album album; + + MoreInfo({super.key, required this.album}); + + @override + State createState() => _MoreInfo(); +} + +class _MoreInfo extends State { + late Album album; + late String albumDescription; + late ColorScheme actualColorScheme; + + @override + void initState() { + super.initState(); + album = widget.album; + albumDescription = ""; + actualColorScheme = const ColorScheme.dark(); + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + _setCustomTheme(); + _getAlbumDescription(); + }); + } + + void _setCustomTheme() async { + final ColorScheme newColorScheme = await ColorScheme.fromImageProvider( + provider: NetworkImage(album.cover)); + setState(() { + actualColorScheme = newColorScheme; + }); + } + + void _getAlbumDescription() async { + LastFmApi api = LastFmApi(); + Map result = await api.getAlbum(album); + String description = result['album']["wiki"]["content"]; + description = description.replaceAll('\n', '465416'); + String convertedDescription = html2md.convert(description); + convertedDescription = convertedDescription.replaceAll('465416', '\\\n'); + + setState(() { + albumDescription = convertedDescription; + }); + } + + @override + Widget build(BuildContext context) { + return Theme( + data: Theme.of(context), + child: Scaffold( + appBar: AppBar( + backgroundColor: Theme.of(context).colorScheme.surface, + leading: IconButton( + onPressed: () { + Navigator.pop(context); + }, + icon: Icon( + Icons.arrow_back, + color: Theme.of(context).colorScheme.onSurface, + ), + ), + title: Text( + album.name, + overflow: TextOverflow.ellipsis, + style: Theme.of(context).textTheme.titleLarge, + ), + ), + body: SingleChildScrollView( + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ClipRRect( + borderRadius: const BorderRadius.all(Radius.circular(24)), + child: Hero( + tag: album.name, + child: Image.network(album.cover), + ), + ) + ], + ), + Padding( + padding: const EdgeInsets.only( + right: 32.0, + left: 32.0, + top: 16.0, + ), + child: Text( + album.name, + style: Theme.of(context).textTheme.headlineSmall, + overflow: TextOverflow.ellipsis, + maxLines: 1, + textAlign: TextAlign.center, + ), + ), + Padding( + padding: const EdgeInsets.only( + top: 8.0, + ), + child: Text( + album.artist, + style: Theme.of(context).textTheme.titleMedium, + ), + ), + Padding( + padding: const EdgeInsets.only( + top: 8.0, + right: 16.0, + left: 16.0, + ), + child: MarkdownBody( + data: albumDescription, + selectable: true, + onTapLink: (text, url, title) { + launchUrl( + Uri.parse(url!)); /*For url_launcher 6.1.0 and higher*/ + // launch(url); /*For url_launcher 6.0.20 and lower*/ + }, + ), + ) + ], + ), + ), + floatingActionButton: FloatingActionButton.extended( + onPressed: () {}, + label: const Text("listen to it"), + ), + ), + ); + } +}