fix: show indicator when a song is an instrumental

This commit is contained in:
2023-07-24 20:57:01 +03:00
parent 1417eef23c
commit a770033563
+23 -2
View File
@@ -20,6 +20,7 @@ class LyricsPage extends StatefulWidget {
class _LyricsPageState extends State<LyricsPage> { class _LyricsPageState extends State<LyricsPage> {
bool fetching = false; bool fetching = false;
String? lyrics; String? lyrics;
bool instrumental = false;
@override @override
void initState() { void initState() {
@@ -35,13 +36,16 @@ class _LyricsPageState extends State<LyricsPage> {
String path = widget.url.split('genius.com/')[1]; String path = widget.url.split('genius.com/')[1];
String fullLyrics = ''; String fullLyrics = '';
if (await webScraper.loadWebPage('/$path?react=1')) { if (await webScraper.loadWebPage('/$path?react=1')) {
webScraper.loadFromString(webScraper.getPageContent().replaceAll('<br>', '\n')); webScraper
var element = webScraper.getElement("div[data-lyrics-container]", ['data-lyrics-container']); .loadFromString(webScraper.getPageContent().replaceAll('<br>', '\n'));
var element = webScraper
.getElement("div[data-lyrics-container]", ['data-lyrics-container']);
for (var section in element) { for (var section in element) {
fullLyrics += section['title'] + '\n'; fullLyrics += section['title'] + '\n';
} }
setState(() { setState(() {
lyrics = fullLyrics; lyrics = fullLyrics;
instrumental = fullLyrics.isEmpty;
fetching = false; fetching = false;
}); });
} }
@@ -82,6 +86,23 @@ class _LyricsPageState extends State<LyricsPage> {
), ),
], ],
) )
: 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( : SizedBox(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
child: SingleChildScrollView( child: SingleChildScrollView(