From 03a857a9ad69962b8be05e3d3d00861809202086 Mon Sep 17 00:00:00 2001 From: suragch Date: Wed, 11 Oct 2023 10:31:23 +0800 Subject: [PATCH] Fix text scale factor for progress and total labels --- CHANGELOG.md | 4 ++++ lib/audio_video_progress_bar.dart | 22 ++++++++++++++++++++-- pubspec.yaml | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65d1874..a24a8ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.0.1] - October 11, 2023 + +- Fix text scale factor for progress and total labels (@stutid) (#61 and #63). + ## [2.0.0] - August 24, 2023 - Bump to Dart 3.0 and Flutter 3.0. diff --git a/lib/audio_video_progress_bar.dart b/lib/audio_video_progress_bar.dart index 4325eee..bd3781a 100644 --- a/lib/audio_video_progress_bar.dart +++ b/lib/audio_video_progress_bar.dart @@ -257,6 +257,7 @@ class ProgressBar extends LeafRenderObjectWidget { final theme = Theme.of(context); final primaryColor = theme.colorScheme.primary; final textStyle = timeLabelTextStyle ?? theme.textTheme.bodyLarge; + final textScaleFactor = MediaQuery.textScaleFactorOf(context); return _RenderProgressBar( progress: progress, total: total, @@ -280,6 +281,7 @@ class ProgressBar extends LeafRenderObjectWidget { timeLabelType: timeLabelType ?? TimeLabelType.totalTime, timeLabelTextStyle: textStyle, timeLabelPadding: timeLabelPadding, + textScaleFactor: textScaleFactor, ); } @@ -288,6 +290,7 @@ class ProgressBar extends LeafRenderObjectWidget { final theme = Theme.of(context); final primaryColor = theme.colorScheme.primary; final textStyle = timeLabelTextStyle ?? theme.textTheme.bodyLarge; + final textScaleFactor = MediaQuery.textScaleFactorOf(context); (renderObject as _RenderProgressBar) ..progress = progress ..total = total @@ -310,7 +313,8 @@ class ProgressBar extends LeafRenderObjectWidget { ..timeLabelLocation = timeLabelLocation ?? TimeLabelLocation.below ..timeLabelType = timeLabelType ?? TimeLabelType.totalTime ..timeLabelTextStyle = textStyle - ..timeLabelPadding = timeLabelPadding; + ..timeLabelPadding = timeLabelPadding + ..textScaleFactor = textScaleFactor; } @override @@ -425,6 +429,7 @@ class _RenderProgressBar extends RenderBox { required TimeLabelType timeLabelType, TextStyle? timeLabelTextStyle, double timeLabelPadding = 0.0, + double textScaleFactor = 1.0, }) : _total = total, _buffered = buffered, _onSeek = onSeek, @@ -444,7 +449,8 @@ class _RenderProgressBar extends RenderBox { _timeLabelLocation = timeLabelLocation, _timeLabelType = timeLabelType, _timeLabelTextStyle = timeLabelTextStyle, - _timeLabelPadding = timeLabelPadding { + _timeLabelPadding = timeLabelPadding, + _textScaleFactor = textScaleFactor { _drag = _EagerHorizontalDragGestureRecognizer() ..onStart = _onDragStart ..onUpdate = _onDragUpdate @@ -606,6 +612,7 @@ class _RenderProgressBar extends RenderBox { TextPainter textPainter = TextPainter( text: TextSpan(text: text, style: _timeLabelTextStyle), textDirection: TextDirection.ltr, + textScaleFactor: textScaleFactor, ); textPainter.layout(minWidth: 0, maxWidth: double.infinity); return textPainter; @@ -818,6 +825,17 @@ class _RenderProgressBar extends RenderBox { markNeedsLayout(); } + /// The text scale factor for the `progress` and `total` text labels. + /// By default the value is 1.0. + double get textScaleFactor => _textScaleFactor; + double _textScaleFactor; + set textScaleFactor(double value) { + if (_textScaleFactor == value) return; + _textScaleFactor = value; + _clearLabelCache(); + markNeedsLayout(); + } + // The smallest that this widget would ever want to be. static const _minDesiredWidth = 100.0; diff --git a/pubspec.yaml b/pubspec.yaml index 0443aef..2d4fd7d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: audio_video_progress_bar description: A progress bar widget to show or change the position of an audio or video stream. -version: 2.0.0 +version: 2.0.1 homepage: https://github.com/suragch/audio_video_progress_bar funding: - https://www.buymeacoffee.com/suragchdev