Skip to content

Commit

Permalink
Add optional scroll listener (#31)
Browse files Browse the repository at this point in the history
* Add optional scroll listener

* Pass in scrollController
  • Loading branch information
jayabrown authored Nov 5, 2024
1 parent 3da46d0 commit db5d04c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/src/lyrics_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -97,7 +101,7 @@ class _LyricsRendererState extends State<LyricsRenderer> {
fontStyle: FontStyle.italic,
fontSize: widget.textStyle.fontSize! - 2,
);
_controller = ScrollController();
_controller = widget.scrollController ?? ScrollController();
WidgetsBinding.instance.addPostFrameCallback((_) {
// executes after build
_scrollToEnd();
Expand Down

0 comments on commit db5d04c

Please sign in to comment.