Skip to content

Commit

Permalink
get more informations on an album
Browse files Browse the repository at this point in the history
  • Loading branch information
apoleon33 committed Jan 14, 2024
1 parent 7f60c9e commit be816f1
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 33 deletions.
41 changes: 24 additions & 17 deletions lib/albumCard/display_as_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -154,13 +158,16 @@ class DisplayAlbumAsCard extends DisplayAlbum {
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
const MoreInfoMenu(),
MoreInfoMenu(
album: album,
),

// new Spacer(),

Consumer<ServiceNotifier>(builder:
(context, serviceNotifier, child) {
return FilledButton.icon(

icon: SvgPicture.asset(
serviceNotifier
.currentService.iconPath,
Expand Down
30 changes: 20 additions & 10 deletions lib/albumCard/display_as_list.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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(
Expand All @@ -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),
],
);
}
Expand Down
22 changes: 16 additions & 6 deletions lib/moreInfoMenu.dart
Original file line number Diff line number Diff line change
@@ -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: <Widget>[
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);
Expand Down
142 changes: 142 additions & 0 deletions lib/route/more_info.dart
Original file line number Diff line number Diff line change
@@ -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<StatefulWidget> createState() => _MoreInfo();
}

class _MoreInfo extends State<MoreInfo> {
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"),
),
),
);
}
}

0 comments on commit be816f1

Please sign in to comment.