Skip to content

Commit

Permalink
Fix text scale factor for progress and total labels
Browse files Browse the repository at this point in the history
  • Loading branch information
suragch committed Oct 11, 2023
1 parent 06929b9 commit 03a857a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
22 changes: 20 additions & 2 deletions lib/audio_video_progress_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -280,6 +281,7 @@ class ProgressBar extends LeafRenderObjectWidget {
timeLabelType: timeLabelType ?? TimeLabelType.totalTime,
timeLabelTextStyle: textStyle,
timeLabelPadding: timeLabelPadding,
textScaleFactor: textScaleFactor,
);
}

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

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: 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
Expand Down

0 comments on commit 03a857a

Please sign in to comment.