From db5d04c37a4489c9fcb3e2fcd56646447aa0a76a Mon Sep 17 00:00:00 2001 From: Jaya Date: Tue, 5 Nov 2024 10:39:58 +0700 Subject: [PATCH] Add optional scroll listener (#31) * Add optional scroll listener * Pass in scrollController --- lib/src/lyrics_renderer.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/src/lyrics_renderer.dart b/lib/src/lyrics_renderer.dart index 85f2c61..eefe306 100644 --- a/lib/src/lyrics_renderer.dart +++ b/lib/src/lyrics_renderer.dart @@ -51,6 +51,9 @@ class LyricsRenderer extends StatefulWidget { /// If not defined it will be the italic version of [textStyle] final TextStyle? commentStyle; + /// Optional external scroll controller, otherwise will be created internally + final ScrollController? scrollController; + const LyricsRenderer( {Key? key, required this.lyrics, @@ -70,7 +73,8 @@ class LyricsRenderer extends StatefulWidget { this.scrollPhysics = const ClampingScrollPhysics(), this.leadingWidget, this.trailingWidget, - this.chordNotation = ChordNotation.american}) + this.chordNotation = ChordNotation.american, + this.scrollController}) : super(key: key); @override @@ -97,7 +101,7 @@ class _LyricsRendererState extends State { fontStyle: FontStyle.italic, fontSize: widget.textStyle.fontSize! - 2, ); - _controller = ScrollController(); + _controller = widget.scrollController ?? ScrollController(); WidgetsBinding.instance.addPostFrameCallback((_) { // executes after build _scrollToEnd();