Skip to content

Commit

Permalink
fix: lyrics view silliness
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed May 14, 2024
1 parent 18671d5 commit 060ccef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions lib/packages/lyrics_lrc_parsed_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ class LyricsLRCParsedViewState extends State<LyricsLRCParsedView> {
late final ItemScrollController controller;
late final ItemPositionsListener positionListener;

late final int topDummyItems;
late final int bottomDummyItems;
late final double _paddingVertical = widget.isFullScreenView ? 32 * 12.0 : 12 * 12.0;
int _currentIndex = -1;

@override
void initState() {
super.initState();
topDummyItems = widget.isFullScreenView ? 32 : 12;
bottomDummyItems = widget.isFullScreenView ? 32 : 12;
controller = ItemScrollController();
positionListener = ItemPositionsListener.create();
fillLists(widget.initialLrc);
Expand Down Expand Up @@ -125,25 +123,32 @@ class LyricsLRCParsedViewState extends State<LyricsLRCParsedView> {
}

void _updateHighlightedLine(Duration dur, {bool forceAnimate = false, bool jump = false}) {
final lrcDur = lyrics.lastWhereEff((e) {
return e.timestamp <= dur;
});
final lrcDur = lyrics.lastWhereEff((e) => e.timestamp <= dur);
WidgetsBinding.instance.addPostFrameCallback((_) {
_latestUpdatedLine.value = lrcDur?.timestamp;

final newIndex = timestampsMap[_latestUpdatedLine.value]?.$1 ?? -1;
int newIndex = timestampsMap[_latestUpdatedLine.value]?.$1 ?? -1;
_latestUpdatedLineIndex.value = newIndex;
if (newIndex + 1 == lyrics.length) {
final alreadyHighlightingLastLine = _currentIndex == newIndex;
if (alreadyHighlightingLastLine) {
return; // overscrolling
} else {
newIndex = lyrics.length - 1; // go to last line
}
}

if ((_canAnimateScroll || forceAnimate) && controller.isAttached) {
final index = (newIndex + topDummyItems).toIf(0, -1);
if (newIndex < 0) newIndex = 0;
_currentIndex = newIndex;
jump
? controller.jumpTo(
alignment: 0.4,
index: index,
index: newIndex,
)
: controller.scrollTo(
alignment: 0.4,
index: index,
index: newIndex,
duration: const Duration(milliseconds: 300),
curve: Curves.easeOut,
);
Expand Down Expand Up @@ -261,8 +266,8 @@ class LyricsLRCParsedViewState extends State<LyricsLRCParsedView> {
child: BorderRadiusClip(
borderRadius: fullscreen ? BorderRadius.zero : BorderRadius.circular(16.0.multipliedRadius),
child: NamidaBgBlur(
blur: fullscreen ? 0.0 : 14.0,
enabled: true,
blur: fullscreen ? 0.0 : 12.0,
enabled: !fullscreen,
child: Container(
color: context.theme.scaffoldBackgroundColor.withOpacity(fullscreen ? 0.8 : 0.6),
alignment: Alignment.center,
Expand Down Expand Up @@ -319,15 +324,10 @@ class LyricsLRCParsedViewState extends State<LyricsLRCParsedView> {
return PageStorage(
bucket: PageStorageBucket(),
child: ScrollablePositionedList.builder(
key: PageStorageKey(widget.key),
// initialAlignment: 0.4,
padding: EdgeInsets.symmetric(vertical: _paddingVertical),
itemScrollController: controller,
itemCount: lyrics.length + topDummyItems + bottomDummyItems,
itemBuilder: (context, indexBefore) {
if (indexBefore < topDummyItems) return const SizedBox(height: 12.0);
if (indexBefore >= (lyrics.length + topDummyItems)) return const SizedBox(height: 12.0);

final index = indexBefore - topDummyItems;
itemCount: lyrics.length,
itemBuilder: (context, index) {
final lrc = lyrics[index];
final selected = highlighted?.timestamp == lrc.timestamp;
final text = lrc.lyrics;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 2.3.5-beta+240513136
version: 2.3.6-beta+240513138

environment:
sdk: ">=3.1.4 <4.0.0"
Expand Down

0 comments on commit 060ccef

Please sign in to comment.