From 1d6e533106c0f2469a85e37dd623207fafdd7f20 Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Mon, 24 Jul 2023 20:57:01 +0300 Subject: [PATCH] fix: show indicator when a song is an instrumental --- lib/lyrics.dart | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/lib/lyrics.dart b/lib/lyrics.dart index d3a9c01..dcbfee4 100644 --- a/lib/lyrics.dart +++ b/lib/lyrics.dart @@ -20,6 +20,7 @@ class LyricsPage extends StatefulWidget { class _LyricsPageState extends State { bool fetching = false; String? lyrics; + bool instrumental = false; @override void initState() { @@ -35,13 +36,16 @@ class _LyricsPageState extends State { String path = widget.url.split('genius.com/')[1]; String fullLyrics = ''; if (await webScraper.loadWebPage('/$path?react=1')) { - webScraper.loadFromString(webScraper.getPageContent().replaceAll('
', '\n')); - var element = webScraper.getElement("div[data-lyrics-container]", ['data-lyrics-container']); + webScraper + .loadFromString(webScraper.getPageContent().replaceAll('
', '\n')); + var element = webScraper + .getElement("div[data-lyrics-container]", ['data-lyrics-container']); for (var section in element) { fullLyrics += section['title'] + '\n'; } setState(() { lyrics = fullLyrics; + instrumental = fullLyrics.isEmpty; fetching = false; }); } @@ -82,20 +86,37 @@ class _LyricsPageState extends State { ), ], ) - : SizedBox( - width: MediaQuery.of(context).size.width, - child: SingleChildScrollView( - child: Container( - padding: const EdgeInsets.all(30), - child: SelectableText( - lyrics ?? '', - style: const TextStyle( - fontSize: 16, + : instrumental + ? const Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(Icons.music_note, size: 50), + SizedBox(width: 20, height: 20), + Text( + 'This Song is an Instrumental', + style: TextStyle( + fontSize: 20, + fontStyle: FontStyle.italic, + ), + ), + ], + ), + ) + : SizedBox( + width: MediaQuery.of(context).size.width, + child: SingleChildScrollView( + child: Container( + padding: const EdgeInsets.all(30), + child: SelectableText( + lyrics ?? '', + style: const TextStyle( + fontSize: 16, + ), + ), ), ), ), - ), - ), ), ); }