From 9d716fc3b6946db76e041046110ce1654df140d0 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 20:34:45 -0400 Subject: [PATCH 01/20] add comment type --- lib/src/chord_parser.dart | 50 ++++++++------------------ lib/src/lyrics_renderer.dart | 53 ++++++++++++++++++---------- lib/src/model/chord_lyrics_line.dart | 18 +++++++--- 3 files changed, 63 insertions(+), 58 deletions(-) diff --git a/lib/src/chord_parser.dart b/lib/src/chord_parser.dart index c52d064..169980b 100644 --- a/lib/src/chord_parser.dart +++ b/lib/src/chord_parser.dart @@ -46,26 +46,18 @@ class ChordProcessor { //check if we have a long line if (textWidth(currentLine, lyricsStyle) >= media) { _handleLongLine( - currentLine: currentLine, - newLines: newLines, - lyricsStyle: lyricsStyle, - widgetPadding: widgetPadding); + currentLine: currentLine, newLines: newLines, lyricsStyle: lyricsStyle, widgetPadding: widgetPadding); } else { //otherwise just add the regular line newLines.add(currentLine.trim()); } } - List _chordLyricsLines = newLines - .map( - (line) => _processLine(line, lyricsStyle, chordStyle)) - .toList(); + List _chordLyricsLines = + newLines.map((line) => _processLine(line, lyricsStyle, chordStyle)).toList(); return ChordLyricsDocument(_chordLyricsLines, - capo: metadata.capo, - artist: metadata.artist, - title: metadata.title, - key: metadata.key); + capo: metadata.capo, artist: metadata.artist, title: metadata.title, key: metadata.key); } void _handleLongLine( @@ -99,18 +91,15 @@ class ChordProcessor { //widgetPadding has been added as a parameter to be passed from the build function //It is intended to allow for padding in the widget when comparing it to screen width //An additional buffer of around 10 might be needed to definitely stop overflow (ie. padding + 10). - if (textWidth(_currentCharacters, lyricsStyle) + widgetPadding >= - media) { - newLines - .add(currentLine.substring(_characterIndex, _lastSpace).trim()); + if (textWidth(_currentCharacters, lyricsStyle) + widgetPadding >= media) { + newLines.add(currentLine.substring(_characterIndex, _lastSpace).trim()); _currentCharacters = ''; _characterIndex = _lastSpace; } } } //add the rest of the long line - newLines - .add(currentLine.substring(_characterIndex, currentLine.length).trim()); + newLines.add(currentLine.substring(_characterIndex, currentLine.length).trim()); } /// Return the textwidth of the text in the given style @@ -125,8 +114,7 @@ class ChordProcessor { .width; } - ChordLyricsLine _processLine( - String line, TextStyle lyricsStyle, TextStyle chordStyle) { + ChordLyricsLine _processLine(String line, TextStyle lyricsStyle, TextStyle chordStyle) { ChordLyricsLine _chordLyricsLine = ChordLyricsLine(); String _lyricsSoFar = ''; String _chordsSoFar = ''; @@ -135,9 +123,7 @@ class ChordProcessor { if (character == ']') { final sizeOfLeadingLyrics = textWidth(_lyricsSoFar, lyricsStyle); - final lastChordText = _chordLyricsLine.chords.isNotEmpty - ? _chordLyricsLine.chords.last.chordText - : ''; + final lastChordText = _chordLyricsLine.chords.isNotEmpty ? _chordLyricsLine.chords.last.chordText : ''; final lastChordWidth = textWidth(lastChordText, chordStyle); // final sizeOfThisChord = textWidth(_chordsSoFar, chordStyle); @@ -183,17 +169,13 @@ class MetadataHandler { /// Try to find and parse metadata in the string. /// Return true if there was a match bool parseLine(String line) { - return _setCapoIfMatch(line) || - _setArtistIfMatch(line) || - _setKeyIfMatch(line) || - _setTitleIfMatch(line); + return _setCapoIfMatch(line) || _setArtistIfMatch(line) || _setKeyIfMatch(line) || _setTitleIfMatch(line); } /// Get key in line if it's present /// Return true if match was found bool _setKeyIfMatch(String line) { - String? tmpKey = - regKey.hasMatch(line) ? _getMetadataFromLine(line, 'key:') : null; + String? tmpKey = regKey.hasMatch(line) ? _getMetadataFromLine(line, 'key:') : null; key ??= tmpKey; return tmpKey != null; } @@ -201,9 +183,7 @@ class MetadataHandler { /// Get capo in line if it's present /// Return true if match was found bool _setCapoIfMatch(String line) { - int? tmpCapo = regCapo.hasMatch(line) - ? int.parse(_getMetadataFromLine(line, 'capo:')) - : null; + int? tmpCapo = regCapo.hasMatch(line) ? int.parse(_getMetadataFromLine(line, 'capo:')) : null; capo ??= tmpCapo; return tmpCapo != null; } @@ -211,8 +191,7 @@ class MetadataHandler { /// Get artist in line if it's present /// Return true if match was found bool _setArtistIfMatch(String line) { - String? tmpArtist = - regArtist.hasMatch(line) ? _getMetadataFromLine(line, 'artist:') : null; + String? tmpArtist = regArtist.hasMatch(line) ? _getMetadataFromLine(line, 'artist:') : null; artist ??= tmpArtist; return tmpArtist != null; } @@ -220,8 +199,7 @@ class MetadataHandler { /// Get title in line if it's present /// Return true if match was found bool _setTitleIfMatch(String line) { - String? tmpTitle = - regTitle.hasMatch(line) ? _getMetadataFromLine(line, 'title:') : null; + String? tmpTitle = regTitle.hasMatch(line) ? _getMetadataFromLine(line, 'title:') : null; title ??= tmpTitle; return tmpTitle != null; } diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index e037f60..7411968 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -48,6 +48,9 @@ class LyricsRenderer extends StatefulWidget { /// If not defined it will be the italic version of [textStyle] final TextStyle? capoStyle; + /// If not defined it will be the italic version of [textStyle] + final TextStyle? commentStyle; + const LyricsRenderer( {Key? key, required this.lyrics, @@ -55,6 +58,7 @@ class LyricsRenderer extends StatefulWidget { required this.chordStyle, required this.onTapChord, this.chorusStyle, + this.commentStyle, this.capoStyle, this.scaleFactor = 1.0, this.showChord = true, @@ -77,15 +81,20 @@ class _LyricsRendererState extends State { late final ScrollController _controller; late TextStyle chorusStyle; late TextStyle capoStyle; + late TextStyle commentStyle; bool _isChorus = false; + bool _isComment = false; @override void initState() { super.initState(); - chorusStyle = widget.chorusStyle ?? - widget.textStyle.copyWith(fontWeight: FontWeight.bold); - capoStyle = widget.capoStyle ?? - widget.textStyle.copyWith(fontStyle: FontStyle.italic); + chorusStyle = widget.chorusStyle ?? widget.textStyle.copyWith(fontWeight: FontWeight.bold); + capoStyle = widget.capoStyle ?? widget.textStyle.copyWith(fontStyle: FontStyle.italic); + commentStyle = widget.commentStyle ?? + widget.textStyle.copyWith( + fontStyle: FontStyle.italic, + fontSize: widget.textStyle.fontSize! / 2, + ); _controller = ScrollController(); WidgetsBinding.instance.addPostFrameCallback((_) { // executes after build @@ -99,10 +108,19 @@ class _LyricsRendererState extends State { super.dispose(); } + TextStyle getLineTextStyle() { + if (_isChorus) { + return chorusStyle; + } else if (_isComment) { + return commentStyle; + } else { + return widget.textStyle; + } + } + @override Widget build(BuildContext context) { - ChordProcessor _chordProcessor = - ChordProcessor(context, widget.chordNotation); + ChordProcessor _chordProcessor = ChordProcessor(context, widget.chordNotation); final chordLyricsDocument = _chordProcessor.processText( text: widget.lyrics, lyricsStyle: widget.textStyle, @@ -119,8 +137,7 @@ class _LyricsRendererState extends State { crossAxisAlignment: widget.horizontalAlignment, children: [ if (widget.leadingWidget != null) widget.leadingWidget!, - if (chordLyricsDocument.capo != null) - Text('Capo: ${chordLyricsDocument.capo!}', style: capoStyle), + if (chordLyricsDocument.capo != null) Text('Capo: ${chordLyricsDocument.capo!}', style: capoStyle), ListView.separated( shrinkWrap: true, scrollDirection: Axis.vertical, @@ -129,14 +146,19 @@ class _LyricsRendererState extends State { height: widget.lineHeight, ), itemBuilder: (context, index) { - final ChordLyricsLine line = - chordLyricsDocument.chordLyricsLines[index]; + final ChordLyricsLine line = chordLyricsDocument.chordLyricsLines[index]; if (line.isStartOfChorus()) { _isChorus = true; } if (line.isEndOfChorus()) { _isChorus = false; } + if (line.isCommment(line.lyrics)) { + _isComment = true; + } + if (!line.isCommment(line.lyrics)) { + _isComment = false; + } return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -149,8 +171,7 @@ class _LyricsRendererState extends State { width: chord.leadingSpace, ), GestureDetector( - onTap: () => - widget.onTapChord(chord.chordText), + onTap: () => widget.onTapChord(chord.chordText), child: RichText( textScaleFactor: widget.scaleFactor, text: TextSpan( @@ -165,10 +186,7 @@ class _LyricsRendererState extends State { ), RichText( textScaleFactor: widget.scaleFactor, - text: TextSpan( - text: line.lyrics, - style: _isChorus ? chorusStyle : widget.textStyle, - ), + text: TextSpan(text: line.lyrics, style: getLineTextStyle()), ) ], ); @@ -198,8 +216,7 @@ class _LyricsRendererState extends State { if (_controller.offset >= _controller.position.maxScrollExtent) return; - final seconds = - (_controller.position.maxScrollExtent / (widget.scrollSpeed)).floor(); + final seconds = (_controller.position.maxScrollExtent / (widget.scrollSpeed)).floor(); _controller.animateTo( _controller.position.maxScrollExtent, diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index 08b15a5..d61f24d 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -12,8 +12,7 @@ class ChordLyricsLine { bool isStartOfChorus() { const String startOfChorusAbbreviation = '{soc}'; const String startOfChorus = '{start_of_chorus}'; - bool out = lyrics.contains(startOfChorus) || - lyrics.contains(startOfChorusAbbreviation); + bool out = lyrics.contains(startOfChorus) || lyrics.contains(startOfChorusAbbreviation); if (out) { lyrics = lyrics.replaceAll(startOfChorus, ''); lyrics = lyrics.replaceAll(startOfChorusAbbreviation, ''); @@ -25,8 +24,7 @@ class ChordLyricsLine { bool isEndOfChorus() { const String endOfChorusAbbreviation = '{eoc}'; const String endOfChorus = '{end_of_chorus}'; - bool out = lyrics.contains(endOfChorus) || - lyrics.contains(endOfChorusAbbreviation); + bool out = lyrics.contains(endOfChorus) || lyrics.contains(endOfChorusAbbreviation); if (out) { lyrics = lyrics.replaceAll(endOfChorus, ''); lyrics = lyrics.replaceAll(endOfChorusAbbreviation, ''); @@ -34,6 +32,18 @@ class ChordLyricsLine { return out; } + String _getMetadataFromLine(String line, String key) { + return line.split(key).last.split('}').first.trim(); + } + + /// Get comment in line if it's present + /// Return true if match was found + bool isCommment(String line) { + final RegExp regComment = RegExp(r'^\{comment:.*\}'); + String? tmpComment = regComment.hasMatch(line) ? _getMetadataFromLine(line, 'comment:') : null; + return tmpComment != null; + } + @override String toString() { return 'ChordLyricsLine($chords, lyrics: $lyrics)'; From e080bcba18ec15b02e3defb08ced87c219672dc0 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 20:40:23 -0400 Subject: [PATCH 02/20] add comment type --- lib/src/lyrics_renderer.dart | 4 ++-- lib/src/model/chord_lyrics_line.dart | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index 7411968..3f55816 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -153,10 +153,10 @@ class _LyricsRendererState extends State { if (line.isEndOfChorus()) { _isChorus = false; } - if (line.isCommment(line.lyrics)) { + if (line.isComment()) { _isComment = true; } - if (!line.isCommment(line.lyrics)) { + if (!line.isComment()) { _isComment = false; } return Column( diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index d61f24d..35be8d8 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -32,16 +32,12 @@ class ChordLyricsLine { return out; } - String _getMetadataFromLine(String line, String key) { - return line.split(key).last.split('}').first.trim(); - } - - /// Get comment in line if it's present - /// Return true if match was found - bool isCommment(String line) { - final RegExp regComment = RegExp(r'^\{comment:.*\}'); - String? tmpComment = regComment.hasMatch(line) ? _getMetadataFromLine(line, 'comment:') : null; - return tmpComment != null; + /// Remove also the keyword + bool isComment() { + const String endOfChorusAbbreviation = '{comment}'; + const String endOfChorus = '{comment: }'; + bool out = lyrics.contains(endOfChorus) || lyrics.contains(endOfChorusAbbreviation); + return out; } @override From bbbdf8ef7e42280098c3f11e5931c04d61517f08 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 20:44:00 -0400 Subject: [PATCH 03/20] add comment type --- lib/src/model/chord_lyrics_line.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index 35be8d8..31cbeda 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -34,9 +34,8 @@ class ChordLyricsLine { /// Remove also the keyword bool isComment() { - const String endOfChorusAbbreviation = '{comment}'; - const String endOfChorus = '{comment: }'; - bool out = lyrics.contains(endOfChorus) || lyrics.contains(endOfChorusAbbreviation); + const String endOfChorusAbbreviation = 'comment'; + bool out = lyrics.contains(endOfChorusAbbreviation); return out; } From 36d2d36273a4523faf883c49f6c2457dce3a8b98 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 20:52:43 -0400 Subject: [PATCH 04/20] add comment type --- lib/src/model/chord_lyrics_line.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index 31cbeda..25e0bdd 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -34,7 +34,7 @@ class ChordLyricsLine { /// Remove also the keyword bool isComment() { - const String endOfChorusAbbreviation = 'comment'; + const String endOfChorusAbbreviation = '{comment:'; bool out = lyrics.contains(endOfChorusAbbreviation); return out; } From 5db61e0bb9992d2b5e913ff689c0bb80686e5365 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 20:57:22 -0400 Subject: [PATCH 05/20] add comment type --- lib/src/lyrics_renderer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index 3f55816..3ac81fe 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -93,7 +93,7 @@ class _LyricsRendererState extends State { commentStyle = widget.commentStyle ?? widget.textStyle.copyWith( fontStyle: FontStyle.italic, - fontSize: widget.textStyle.fontSize! / 2, + fontSize: widget.textStyle.fontSize! - 5, ); _controller = ScrollController(); WidgetsBinding.instance.addPostFrameCallback((_) { From 137e33c46a5ef620aa7c4649f0951a2248c69262 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 21:00:18 -0400 Subject: [PATCH 06/20] add comment type --- lib/src/lyrics_renderer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index 3ac81fe..a66ac01 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -93,7 +93,7 @@ class _LyricsRendererState extends State { commentStyle = widget.commentStyle ?? widget.textStyle.copyWith( fontStyle: FontStyle.italic, - fontSize: widget.textStyle.fontSize! - 5, + fontSize: widget.textStyle.fontSize! - 2, ); _controller = ScrollController(); WidgetsBinding.instance.addPostFrameCallback((_) { From d7a76e0dafe6d6215896e5fb6aeab90f2cfc5ec3 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 21:08:01 -0400 Subject: [PATCH 07/20] add comment type --- lib/src/model/chord_lyrics_line.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index 25e0bdd..c09d93f 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -34,8 +34,12 @@ class ChordLyricsLine { /// Remove also the keyword bool isComment() { - const String endOfChorusAbbreviation = '{comment:'; - bool out = lyrics.contains(endOfChorusAbbreviation); + const String comment = '{comment:'; + bool out = lyrics.contains(comment); + if (out) { + lyrics.replaceAll(new RegExp(r'[^\w\s]+'), ''); + lyrics.replaceAll(comment, ''); + } return out; } From 6d130cc86cf26a8f0c0eb65bf9546e3f430839d8 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 21:12:03 -0400 Subject: [PATCH 08/20] add comment type --- lib/src/model/chord_lyrics_line.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index c09d93f..25b3a64 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -34,7 +34,7 @@ class ChordLyricsLine { /// Remove also the keyword bool isComment() { - const String comment = '{comment:'; + const String comment = 'comment'; bool out = lyrics.contains(comment); if (out) { lyrics.replaceAll(new RegExp(r'[^\w\s]+'), ''); From 2fc9396d00fe0a18e64409754fc8902f20889637 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 21:18:45 -0400 Subject: [PATCH 09/20] change regex works in dartpad --- lib/src/model/chord_lyrics_line.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index 25b3a64..d66446a 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -37,7 +37,7 @@ class ChordLyricsLine { const String comment = 'comment'; bool out = lyrics.contains(comment); if (out) { - lyrics.replaceAll(new RegExp(r'[^\w\s]+'), ''); + lyrics.replaceAll(new RegExp(r"[^\s\w]"), ''); lyrics.replaceAll(comment, ''); } return out; From e4d2eb5be6c2f8fda6a68e6b14b70ebe19de0adb Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 21:29:03 -0400 Subject: [PATCH 10/20] change regex works in dartpad --- lib/src/model/chord_lyrics_line.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index d66446a..de3f0b0 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -34,11 +34,11 @@ class ChordLyricsLine { /// Remove also the keyword bool isComment() { - const String comment = 'comment'; + const String comment = '{comment:'; bool out = lyrics.contains(comment); if (out) { - lyrics.replaceAll(new RegExp(r"[^\s\w]"), ''); lyrics.replaceAll(comment, ''); + lyrics.replaceAll('}', ''); } return out; } From 3f63bf28832a6f56225c7adbb7fb49b88ee0d66c Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 21:32:53 -0400 Subject: [PATCH 11/20] change regex works in dartpad --- lib/src/lyrics_renderer.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index a66ac01..6841f14 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -155,6 +155,8 @@ class _LyricsRendererState extends State { } if (line.isComment()) { _isComment = true; + line.lyrics.replaceAll('{comment:', ''); + line.lyrics.replaceAll('}', ''); } if (!line.isComment()) { _isComment = false; From 73288e5ec4d3f0846490b423948af58050a8bd42 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 21:37:56 -0400 Subject: [PATCH 12/20] change regex works in dartpad --- lib/src/lyrics_renderer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index 6841f14..fdac008 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -146,7 +146,7 @@ class _LyricsRendererState extends State { height: widget.lineHeight, ), itemBuilder: (context, index) { - final ChordLyricsLine line = chordLyricsDocument.chordLyricsLines[index]; + var line = chordLyricsDocument.chordLyricsLines[index]; if (line.isStartOfChorus()) { _isChorus = true; } From a8275cf9d10440ca5261683ce096c344b391990b Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 21:52:35 -0400 Subject: [PATCH 13/20] didnt set lyrics = --- lib/src/lyrics_renderer.dart | 4 +--- lib/src/model/chord_lyrics_line.dart | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index fdac008..a66ac01 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -146,7 +146,7 @@ class _LyricsRendererState extends State { height: widget.lineHeight, ), itemBuilder: (context, index) { - var line = chordLyricsDocument.chordLyricsLines[index]; + final ChordLyricsLine line = chordLyricsDocument.chordLyricsLines[index]; if (line.isStartOfChorus()) { _isChorus = true; } @@ -155,8 +155,6 @@ class _LyricsRendererState extends State { } if (line.isComment()) { _isComment = true; - line.lyrics.replaceAll('{comment:', ''); - line.lyrics.replaceAll('}', ''); } if (!line.isComment()) { _isComment = false; diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index de3f0b0..82e88b1 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -37,8 +37,8 @@ class ChordLyricsLine { const String comment = '{comment:'; bool out = lyrics.contains(comment); if (out) { - lyrics.replaceAll(comment, ''); - lyrics.replaceAll('}', ''); + lyrics = lyrics.replaceAll(comment, ''); + lyrics = lyrics.replaceAll('}', ''); } return out; } From f053c4b0244c53f8094a17412a8af563ee473284 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 21:56:43 -0400 Subject: [PATCH 14/20] trim --- lib/src/model/chord_lyrics_line.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index 82e88b1..b160fa1 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -38,7 +38,7 @@ class ChordLyricsLine { bool out = lyrics.contains(comment); if (out) { lyrics = lyrics.replaceAll(comment, ''); - lyrics = lyrics.replaceAll('}', ''); + lyrics = lyrics.replaceAll('}', '').trim(); } return out; } From 3de9d793497f5f6ef5169ba4af6c6637d90b1bed Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 22:03:02 -0400 Subject: [PATCH 15/20] format --- lib/src/chord_parser.dart | 50 ++++++++++++++++++++-------- lib/src/lyrics_renderer.dart | 24 ++++++++----- lib/src/model/chord_lyrics_line.dart | 6 ++-- 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/lib/src/chord_parser.dart b/lib/src/chord_parser.dart index 169980b..c52d064 100644 --- a/lib/src/chord_parser.dart +++ b/lib/src/chord_parser.dart @@ -46,18 +46,26 @@ class ChordProcessor { //check if we have a long line if (textWidth(currentLine, lyricsStyle) >= media) { _handleLongLine( - currentLine: currentLine, newLines: newLines, lyricsStyle: lyricsStyle, widgetPadding: widgetPadding); + currentLine: currentLine, + newLines: newLines, + lyricsStyle: lyricsStyle, + widgetPadding: widgetPadding); } else { //otherwise just add the regular line newLines.add(currentLine.trim()); } } - List _chordLyricsLines = - newLines.map((line) => _processLine(line, lyricsStyle, chordStyle)).toList(); + List _chordLyricsLines = newLines + .map( + (line) => _processLine(line, lyricsStyle, chordStyle)) + .toList(); return ChordLyricsDocument(_chordLyricsLines, - capo: metadata.capo, artist: metadata.artist, title: metadata.title, key: metadata.key); + capo: metadata.capo, + artist: metadata.artist, + title: metadata.title, + key: metadata.key); } void _handleLongLine( @@ -91,15 +99,18 @@ class ChordProcessor { //widgetPadding has been added as a parameter to be passed from the build function //It is intended to allow for padding in the widget when comparing it to screen width //An additional buffer of around 10 might be needed to definitely stop overflow (ie. padding + 10). - if (textWidth(_currentCharacters, lyricsStyle) + widgetPadding >= media) { - newLines.add(currentLine.substring(_characterIndex, _lastSpace).trim()); + if (textWidth(_currentCharacters, lyricsStyle) + widgetPadding >= + media) { + newLines + .add(currentLine.substring(_characterIndex, _lastSpace).trim()); _currentCharacters = ''; _characterIndex = _lastSpace; } } } //add the rest of the long line - newLines.add(currentLine.substring(_characterIndex, currentLine.length).trim()); + newLines + .add(currentLine.substring(_characterIndex, currentLine.length).trim()); } /// Return the textwidth of the text in the given style @@ -114,7 +125,8 @@ class ChordProcessor { .width; } - ChordLyricsLine _processLine(String line, TextStyle lyricsStyle, TextStyle chordStyle) { + ChordLyricsLine _processLine( + String line, TextStyle lyricsStyle, TextStyle chordStyle) { ChordLyricsLine _chordLyricsLine = ChordLyricsLine(); String _lyricsSoFar = ''; String _chordsSoFar = ''; @@ -123,7 +135,9 @@ class ChordProcessor { if (character == ']') { final sizeOfLeadingLyrics = textWidth(_lyricsSoFar, lyricsStyle); - final lastChordText = _chordLyricsLine.chords.isNotEmpty ? _chordLyricsLine.chords.last.chordText : ''; + final lastChordText = _chordLyricsLine.chords.isNotEmpty + ? _chordLyricsLine.chords.last.chordText + : ''; final lastChordWidth = textWidth(lastChordText, chordStyle); // final sizeOfThisChord = textWidth(_chordsSoFar, chordStyle); @@ -169,13 +183,17 @@ class MetadataHandler { /// Try to find and parse metadata in the string. /// Return true if there was a match bool parseLine(String line) { - return _setCapoIfMatch(line) || _setArtistIfMatch(line) || _setKeyIfMatch(line) || _setTitleIfMatch(line); + return _setCapoIfMatch(line) || + _setArtistIfMatch(line) || + _setKeyIfMatch(line) || + _setTitleIfMatch(line); } /// Get key in line if it's present /// Return true if match was found bool _setKeyIfMatch(String line) { - String? tmpKey = regKey.hasMatch(line) ? _getMetadataFromLine(line, 'key:') : null; + String? tmpKey = + regKey.hasMatch(line) ? _getMetadataFromLine(line, 'key:') : null; key ??= tmpKey; return tmpKey != null; } @@ -183,7 +201,9 @@ class MetadataHandler { /// Get capo in line if it's present /// Return true if match was found bool _setCapoIfMatch(String line) { - int? tmpCapo = regCapo.hasMatch(line) ? int.parse(_getMetadataFromLine(line, 'capo:')) : null; + int? tmpCapo = regCapo.hasMatch(line) + ? int.parse(_getMetadataFromLine(line, 'capo:')) + : null; capo ??= tmpCapo; return tmpCapo != null; } @@ -191,7 +211,8 @@ class MetadataHandler { /// Get artist in line if it's present /// Return true if match was found bool _setArtistIfMatch(String line) { - String? tmpArtist = regArtist.hasMatch(line) ? _getMetadataFromLine(line, 'artist:') : null; + String? tmpArtist = + regArtist.hasMatch(line) ? _getMetadataFromLine(line, 'artist:') : null; artist ??= tmpArtist; return tmpArtist != null; } @@ -199,7 +220,8 @@ class MetadataHandler { /// Get title in line if it's present /// Return true if match was found bool _setTitleIfMatch(String line) { - String? tmpTitle = regTitle.hasMatch(line) ? _getMetadataFromLine(line, 'title:') : null; + String? tmpTitle = + regTitle.hasMatch(line) ? _getMetadataFromLine(line, 'title:') : null; title ??= tmpTitle; return tmpTitle != null; } diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index a66ac01..8ce6976 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -88,8 +88,10 @@ class _LyricsRendererState extends State { @override void initState() { super.initState(); - chorusStyle = widget.chorusStyle ?? widget.textStyle.copyWith(fontWeight: FontWeight.bold); - capoStyle = widget.capoStyle ?? widget.textStyle.copyWith(fontStyle: FontStyle.italic); + chorusStyle = widget.chorusStyle ?? + widget.textStyle.copyWith(fontWeight: FontWeight.bold); + capoStyle = widget.capoStyle ?? + widget.textStyle.copyWith(fontStyle: FontStyle.italic); commentStyle = widget.commentStyle ?? widget.textStyle.copyWith( fontStyle: FontStyle.italic, @@ -120,7 +122,8 @@ class _LyricsRendererState extends State { @override Widget build(BuildContext context) { - ChordProcessor _chordProcessor = ChordProcessor(context, widget.chordNotation); + ChordProcessor _chordProcessor = + ChordProcessor(context, widget.chordNotation); final chordLyricsDocument = _chordProcessor.processText( text: widget.lyrics, lyricsStyle: widget.textStyle, @@ -137,7 +140,8 @@ class _LyricsRendererState extends State { crossAxisAlignment: widget.horizontalAlignment, children: [ if (widget.leadingWidget != null) widget.leadingWidget!, - if (chordLyricsDocument.capo != null) Text('Capo: ${chordLyricsDocument.capo!}', style: capoStyle), + if (chordLyricsDocument.capo != null) + Text('Capo: ${chordLyricsDocument.capo!}', style: capoStyle), ListView.separated( shrinkWrap: true, scrollDirection: Axis.vertical, @@ -146,7 +150,8 @@ class _LyricsRendererState extends State { height: widget.lineHeight, ), itemBuilder: (context, index) { - final ChordLyricsLine line = chordLyricsDocument.chordLyricsLines[index]; + final ChordLyricsLine line = + chordLyricsDocument.chordLyricsLines[index]; if (line.isStartOfChorus()) { _isChorus = true; } @@ -171,7 +176,8 @@ class _LyricsRendererState extends State { width: chord.leadingSpace, ), GestureDetector( - onTap: () => widget.onTapChord(chord.chordText), + onTap: () => + widget.onTapChord(chord.chordText), child: RichText( textScaleFactor: widget.scaleFactor, text: TextSpan( @@ -186,7 +192,8 @@ class _LyricsRendererState extends State { ), RichText( textScaleFactor: widget.scaleFactor, - text: TextSpan(text: line.lyrics, style: getLineTextStyle()), + text: + TextSpan(text: line.lyrics, style: getLineTextStyle()), ) ], ); @@ -216,7 +223,8 @@ class _LyricsRendererState extends State { if (_controller.offset >= _controller.position.maxScrollExtent) return; - final seconds = (_controller.position.maxScrollExtent / (widget.scrollSpeed)).floor(); + final seconds = + (_controller.position.maxScrollExtent / (widget.scrollSpeed)).floor(); _controller.animateTo( _controller.position.maxScrollExtent, diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index b160fa1..cbd8543 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -12,7 +12,8 @@ class ChordLyricsLine { bool isStartOfChorus() { const String startOfChorusAbbreviation = '{soc}'; const String startOfChorus = '{start_of_chorus}'; - bool out = lyrics.contains(startOfChorus) || lyrics.contains(startOfChorusAbbreviation); + bool out = lyrics.contains(startOfChorus) || + lyrics.contains(startOfChorusAbbreviation); if (out) { lyrics = lyrics.replaceAll(startOfChorus, ''); lyrics = lyrics.replaceAll(startOfChorusAbbreviation, ''); @@ -24,7 +25,8 @@ class ChordLyricsLine { bool isEndOfChorus() { const String endOfChorusAbbreviation = '{eoc}'; const String endOfChorus = '{end_of_chorus}'; - bool out = lyrics.contains(endOfChorus) || lyrics.contains(endOfChorusAbbreviation); + bool out = lyrics.contains(endOfChorus) || + lyrics.contains(endOfChorusAbbreviation); if (out) { lyrics = lyrics.replaceAll(endOfChorus, ''); lyrics = lyrics.replaceAll(endOfChorusAbbreviation, ''); From 4d94bb39c61ca08d52f64e79be9bb77d02957eb9 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 22:08:09 -0400 Subject: [PATCH 16/20] format --- lib/src/lyrics_renderer.dart | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index 8ce6976..bc42a18 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -88,10 +88,8 @@ class _LyricsRendererState extends State { @override void initState() { super.initState(); - chorusStyle = widget.chorusStyle ?? - widget.textStyle.copyWith(fontWeight: FontWeight.bold); - capoStyle = widget.capoStyle ?? - widget.textStyle.copyWith(fontStyle: FontStyle.italic); + chorusStyle = widget.chorusStyle ?? widget.textStyle.copyWith(fontWeight: FontWeight.bold); + capoStyle = widget.capoStyle ?? widget.textStyle.copyWith(fontStyle: FontStyle.italic); commentStyle = widget.commentStyle ?? widget.textStyle.copyWith( fontStyle: FontStyle.italic, @@ -122,8 +120,7 @@ class _LyricsRendererState extends State { @override Widget build(BuildContext context) { - ChordProcessor _chordProcessor = - ChordProcessor(context, widget.chordNotation); + ChordProcessor _chordProcessor = ChordProcessor(context, widget.chordNotation); final chordLyricsDocument = _chordProcessor.processText( text: widget.lyrics, lyricsStyle: widget.textStyle, @@ -140,8 +137,7 @@ class _LyricsRendererState extends State { crossAxisAlignment: widget.horizontalAlignment, children: [ if (widget.leadingWidget != null) widget.leadingWidget!, - if (chordLyricsDocument.capo != null) - Text('Capo: ${chordLyricsDocument.capo!}', style: capoStyle), + if (chordLyricsDocument.capo != null) Text('Capo: ${chordLyricsDocument.capo!}', style: capoStyle), ListView.separated( shrinkWrap: true, scrollDirection: Axis.vertical, @@ -150,20 +146,19 @@ class _LyricsRendererState extends State { height: widget.lineHeight, ), itemBuilder: (context, index) { - final ChordLyricsLine line = - chordLyricsDocument.chordLyricsLines[index]; + final ChordLyricsLine line = chordLyricsDocument.chordLyricsLines[index]; if (line.isStartOfChorus()) { _isChorus = true; } if (line.isEndOfChorus()) { _isChorus = false; } - if (line.isComment()) { - _isComment = true; - } if (!line.isComment()) { _isComment = false; } + if (line.isComment()) { + _isComment = true; + } return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -176,8 +171,7 @@ class _LyricsRendererState extends State { width: chord.leadingSpace, ), GestureDetector( - onTap: () => - widget.onTapChord(chord.chordText), + onTap: () => widget.onTapChord(chord.chordText), child: RichText( textScaleFactor: widget.scaleFactor, text: TextSpan( @@ -192,8 +186,7 @@ class _LyricsRendererState extends State { ), RichText( textScaleFactor: widget.scaleFactor, - text: - TextSpan(text: line.lyrics, style: getLineTextStyle()), + text: TextSpan(text: line.lyrics, style: getLineTextStyle()), ) ], ); @@ -223,8 +216,7 @@ class _LyricsRendererState extends State { if (_controller.offset >= _controller.position.maxScrollExtent) return; - final seconds = - (_controller.position.maxScrollExtent / (widget.scrollSpeed)).floor(); + final seconds = (_controller.position.maxScrollExtent / (widget.scrollSpeed)).floor(); _controller.animateTo( _controller.position.maxScrollExtent, From 56a059b3bd18b5bf8a4895196743cdae14756897 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 22:13:54 -0400 Subject: [PATCH 17/20] format --- lib/src/lyrics_renderer.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index bc42a18..39fd4b2 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -153,11 +153,10 @@ class _LyricsRendererState extends State { if (line.isEndOfChorus()) { _isChorus = false; } - if (!line.isComment()) { - _isComment = false; - } if (line.isComment()) { _isComment = true; + } else { + _isComment = false; } return Column( crossAxisAlignment: CrossAxisAlignment.start, From 91e239ceb8eec00b6a5f038a603cd8055326e393 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 22:21:25 -0400 Subject: [PATCH 18/20] format --- lib/src/lyrics_renderer.dart | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index 39fd4b2..86b74d1 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -88,8 +88,10 @@ class _LyricsRendererState extends State { @override void initState() { super.initState(); - chorusStyle = widget.chorusStyle ?? widget.textStyle.copyWith(fontWeight: FontWeight.bold); - capoStyle = widget.capoStyle ?? widget.textStyle.copyWith(fontStyle: FontStyle.italic); + chorusStyle = widget.chorusStyle ?? + widget.textStyle.copyWith(fontWeight: FontWeight.bold); + capoStyle = widget.capoStyle ?? + widget.textStyle.copyWith(fontStyle: FontStyle.italic); commentStyle = widget.commentStyle ?? widget.textStyle.copyWith( fontStyle: FontStyle.italic, @@ -120,7 +122,8 @@ class _LyricsRendererState extends State { @override Widget build(BuildContext context) { - ChordProcessor _chordProcessor = ChordProcessor(context, widget.chordNotation); + ChordProcessor _chordProcessor = + ChordProcessor(context, widget.chordNotation); final chordLyricsDocument = _chordProcessor.processText( text: widget.lyrics, lyricsStyle: widget.textStyle, @@ -137,7 +140,8 @@ class _LyricsRendererState extends State { crossAxisAlignment: widget.horizontalAlignment, children: [ if (widget.leadingWidget != null) widget.leadingWidget!, - if (chordLyricsDocument.capo != null) Text('Capo: ${chordLyricsDocument.capo!}', style: capoStyle), + if (chordLyricsDocument.capo != null) + Text('Capo: ${chordLyricsDocument.capo!}', style: capoStyle), ListView.separated( shrinkWrap: true, scrollDirection: Axis.vertical, @@ -146,7 +150,8 @@ class _LyricsRendererState extends State { height: widget.lineHeight, ), itemBuilder: (context, index) { - final ChordLyricsLine line = chordLyricsDocument.chordLyricsLines[index]; + final ChordLyricsLine line = + chordLyricsDocument.chordLyricsLines[index]; if (line.isStartOfChorus()) { _isChorus = true; } @@ -170,7 +175,8 @@ class _LyricsRendererState extends State { width: chord.leadingSpace, ), GestureDetector( - onTap: () => widget.onTapChord(chord.chordText), + onTap: () => + widget.onTapChord(chord.chordText), child: RichText( textScaleFactor: widget.scaleFactor, text: TextSpan( @@ -185,7 +191,8 @@ class _LyricsRendererState extends State { ), RichText( textScaleFactor: widget.scaleFactor, - text: TextSpan(text: line.lyrics, style: getLineTextStyle()), + text: + TextSpan(text: line.lyrics, style: getLineTextStyle()), ) ], ); @@ -215,7 +222,8 @@ class _LyricsRendererState extends State { if (_controller.offset >= _controller.position.maxScrollExtent) return; - final seconds = (_controller.position.maxScrollExtent / (widget.scrollSpeed)).floor(); + final seconds = + (_controller.position.maxScrollExtent / (widget.scrollSpeed)).floor(); _controller.animateTo( _controller.position.maxScrollExtent, From 46b40f7cc3a6768efe9ea8115ee532e42a5e054f Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 22:35:53 -0400 Subject: [PATCH 19/20] add test --- example/pubspec.lock | 105 ++++++++------- lib/src/model/chord_lyrics_line.dart | 4 +- pubspec.lock | 186 ++++++++++++++++----------- test/chord_lyrics_line_test.dart | 35 +++++ 4 files changed, 208 insertions(+), 122 deletions(-) create mode 100644 test/chord_lyrics_line_test.dart diff --git a/example/pubspec.lock b/example/pubspec.lock index 0747c08..10f87ae 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,58 +5,58 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.17.2" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + sha256: "486b7bc707424572cdf7bd7e812a0c146de3fd47ecadf070254cc60383f21dd8" + url: "https://pub.dev" source: hosted version: "1.0.3" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -78,30 +78,34 @@ packages: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + url: "https://pub.dev" source: hosted - version: "0.1.4" + version: "0.5.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.9.1" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -111,51 +115,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + url: "https://pub.dev" source: hosted - version: "0.4.9" + version: "0.6.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + web: + dependency: transitive + description: + name: web + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "0.1.4-beta" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=1.17.0" diff --git a/lib/src/model/chord_lyrics_line.dart b/lib/src/model/chord_lyrics_line.dart index cbd8543..370c7fc 100644 --- a/lib/src/model/chord_lyrics_line.dart +++ b/lib/src/model/chord_lyrics_line.dart @@ -16,7 +16,7 @@ class ChordLyricsLine { lyrics.contains(startOfChorusAbbreviation); if (out) { lyrics = lyrics.replaceAll(startOfChorus, ''); - lyrics = lyrics.replaceAll(startOfChorusAbbreviation, ''); + lyrics = lyrics.replaceAll(startOfChorusAbbreviation, '').trim(); } return out; } @@ -29,7 +29,7 @@ class ChordLyricsLine { lyrics.contains(endOfChorusAbbreviation); if (out) { lyrics = lyrics.replaceAll(endOfChorus, ''); - lyrics = lyrics.replaceAll(endOfChorusAbbreviation, ''); + lyrics = lyrics.replaceAll(endOfChorusAbbreviation, '').trim(); } return out; } diff --git a/pubspec.lock b/pubspec.lock index ae3ee7e..e06fddd 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,140 +5,144 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - url: "https://pub.dartlang.org" + sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a + url: "https://pub.dev" source: hosted - version: "32.0.0" + version: "61.0.0" analyzer: dependency: transitive description: name: analyzer - url: "https://pub.dartlang.org" + sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562 + url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "5.13.0" args: dependency: transitive description: name: args - url: "https://pub.dartlang.org" + sha256: "0bd9a99b6eb96f07af141f0eb53eace8983e8e5aa5de59777aca31684680ef22" + url: "https://pub.dev" source: hosted version: "2.3.0" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" build: dependency: transitive description: name: build - url: "https://pub.dartlang.org" + sha256: "3fbda25365741f8251b39f3917fb3c8e286a96fd068a5a242e11c2012d495777" + url: "https://pub.dev" source: hosted - version: "2.2.1" + version: "2.3.1" built_collection: dependency: transitive description: name: built_collection - url: "https://pub.dartlang.org" + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" source: hosted version: "5.1.1" built_value: dependency: transitive description: name: built_value - url: "https://pub.dartlang.org" + sha256: "0ef2d0947df2804424d9f23e5349d210350dd3c7d39ab53845ecabb2db996f64" + url: "https://pub.dev" source: hosted version: "8.1.3" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.3.1" - cli_util: - dependency: transitive - description: - name: cli_util - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.5" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" code_builder: dependency: transitive description: name: code_builder - url: "https://pub.dartlang.org" + sha256: "1be9be30396d7e4c0db42c35ea6ccd7cc6a1e19916b5dc64d6ac216b5544d677" + url: "https://pub.dev" source: hosted - version: "4.1.0" + version: "4.7.0" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.17.2" convert: dependency: transitive description: name: convert - url: "https://pub.dartlang.org" + sha256: f08428ad63615f96a27e34221c65e1a451439b5f26030f78d790f461c686d65d + url: "https://pub.dev" source: hosted version: "3.0.1" crypto: dependency: transitive description: name: crypto - url: "https://pub.dartlang.org" + sha256: cf75650c66c0316274e21d7c43d3dea246273af5955bd94e8184837cd577575c + url: "https://pub.dev" source: hosted version: "3.0.1" dart_style: dependency: transitive description: name: dart_style - url: "https://pub.dartlang.org" + sha256: "1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55" + url: "https://pub.dev" source: hosted - version: "2.2.1" + version: "2.3.2" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" file: dependency: transitive description: name: file - url: "https://pub.dartlang.org" + sha256: b69516f2c26a5bcac4eee2e32512e1a5205ab312b3536c1c1227b2b942b5f9ad + url: "https://pub.dev" source: hosted version: "6.1.2" fixnum: dependency: transitive description: name: fixnum - url: "https://pub.dartlang.org" + sha256: "6a2ef17156f4dc49684f9d99aaf4a93aba8ac49f5eac861755f5730ddf6e2e4e" + url: "https://pub.dev" source: hosted version: "1.0.0" flutter: @@ -155,63 +159,72 @@ packages: dependency: transitive description: name: glob - url: "https://pub.dartlang.org" + sha256: "8321dd2c0ab0683a91a51307fa844c6db4aa8e3981219b78961672aaab434658" + url: "https://pub.dev" source: hosted version: "2.0.2" logging: dependency: transitive description: name: logging - url: "https://pub.dartlang.org" + sha256: "293ae2d49fd79d4c04944c3a26dfd313382d5f52e821ec57119230ae16031ad4" + url: "https://pub.dev" source: hosted version: "1.0.2" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + url: "https://pub.dev" source: hosted - version: "0.1.4" + version: "0.5.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.9.1" mockito: dependency: "direct dev" description: name: mockito - url: "https://pub.dartlang.org" + sha256: "7d5b53bcd556c1bc7ffbe4e4d5a19c3e112b7e925e9e172dd7c6ad0630812616" + url: "https://pub.dev" source: hosted - version: "5.0.17" + version: "5.4.2" package_config: dependency: transitive description: name: package_config - url: "https://pub.dartlang.org" + sha256: a4d5ede5ca9c3d88a2fef1147a078570c861714c806485c596b109819135bc12 + url: "https://pub.dev" source: hosted version: "2.0.2" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.8.3" pub_semver: dependency: transitive description: name: pub_semver - url: "https://pub.dartlang.org" + sha256: b5a5fcc6425ea43704852ba4453ba94b08c2226c63418a260240c3a054579014 + url: "https://pub.dev" source: hosted version: "2.1.0" sky_engine: @@ -223,79 +236,98 @@ packages: dependency: transitive description: name: source_gen - url: "https://pub.dartlang.org" + sha256: fc0da689e5302edb6177fdd964efcb7f58912f43c28c2047a808f5bfff643d16 + url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.4.0" source_span: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + url: "https://pub.dev" source: hosted - version: "0.4.9" + version: "0.6.0" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + sha256: "53bdf7e979cfbf3e28987552fd72f637e63f3c8724c9e56d9246942dc2fa36ee" + url: "https://pub.dev" source: hosted version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" watcher: dependency: transitive description: name: watcher - url: "https://pub.dartlang.org" + sha256: e42dfcc48f67618344da967b10f62de57e04bae01d9d3af4c2596f3712a88c99 + url: "https://pub.dev" source: hosted version: "1.0.1" + web: + dependency: transitive + description: + name: web + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + url: "https://pub.dev" + source: hosted + version: "0.1.4-beta" yaml: dependency: transitive description: name: yaml - url: "https://pub.dartlang.org" + sha256: "3cee79b1715110341012d27756d9bae38e650588acd38d3f3c610822e1337ace" + url: "https://pub.dev" source: hosted version: "3.1.0" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=1.17.0" diff --git a/test/chord_lyrics_line_test.dart b/test/chord_lyrics_line_test.dart new file mode 100644 index 0000000..16be6cf --- /dev/null +++ b/test/chord_lyrics_line_test.dart @@ -0,0 +1,35 @@ +import 'package:flutter_chord/flutter_chord.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('isStartOfChorus', (WidgetTester tester) async { + final ChordLyricsLine line = ChordLyricsLine(); + line.lyrics = "{start_of_chorus} I Am the Start of the Chorus {soc}"; + final isStart = line.isStartOfChorus(); + expect(isStart, true); + expect(line.lyrics, "I Am the Start of the Chorus"); + line.lyrics = "I Am Not the Start of the Chorus"; + final isNotStart = line.isStartOfChorus(); + expect(isNotStart, false); + }); + + testWidgets('isEndOfChorus', (WidgetTester tester) async { + final ChordLyricsLine line = ChordLyricsLine(); + line.lyrics = "{end_of_chorus} I Am the End of the Chorus {eoc}"; + final isEnd = line.isEndOfChorus(); + expect(isEnd, true); + line.lyrics = "I Am Not the End of the Chorus"; + final isNotEnd = line.isEndOfChorus(); + expect(isNotEnd, false); + }); + + testWidgets('isComment', (WidgetTester tester) async { + final ChordLyricsLine line = ChordLyricsLine(); + line.lyrics = "{comment: I Am a comment}"; + final isComment = line.isComment(); + expect(isComment, true); + line.lyrics = "I Am a comment"; + final isNotEnd = line.isComment(); + expect(isNotEnd, false); + }); +} From 3bf0b110700247153460c8781a26c4fb9f3f6c48 Mon Sep 17 00:00:00 2001 From: Jeremiah Parrack Date: Sun, 22 Oct 2023 22:49:06 -0400 Subject: [PATCH 20/20] move flutter format to dart format its been removed --- .github/workflows/test.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 24f6b20..4760eb4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,33 +2,33 @@ name: Test # Run on every pull-requests on: [push, pull_request] - - + + jobs: test: # This job will run on ubuntu virtual machine runs-on: ubuntu-latest steps: - + # Setup Java environment in order to build the Android app. - uses: actions/checkout@v2 - uses: actions/setup-java@v1 with: java-version: '12.x' - + # Setup the flutter environment. - uses: subosito/flutter-action@v1 with: flutter-version: '3.0.x' - + # Get flutter dependencies. - run: flutter pub get - + # Check for any formatting issues in the code. - - run: flutter format --set-exit-if-changed . - + - run: dart format -l 80 --set-exit-if-changed . + # Statically analyze the Dart code for any errors. - run: flutter analyze . - + # Run unit and widget tests for our flutter project. - run: flutter test