Skip to content

Commit

Permalink
Fixed #6: label color not updating on theme change
Browse files Browse the repository at this point in the history
  • Loading branch information
suragch committed Apr 26, 2021
1 parent 142e8cb commit fd9a1ee
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [0.3.2] - April 26, 2021

* Fixed bug with failure to update label color on theme change.

## [0.3.1] - April 12, 2021

* Added `thumbGlowColor`
* Added `thumbGlowRadius`
* Added `timeLabelTextStyle`

## [0.3.0] - March 7, 2021

* Null safety release version
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.0"
version: "0.3.2"
boolean_selector:
dependency: transitive
description:
Expand Down
47 changes: 25 additions & 22 deletions lib/audio_video_progress_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ class _RenderProgressBar extends RenderBox {
..onUpdate = _onDragUpdate
..onEnd = _onDragEnd
..onCancel = _finishDrag;
_leftTimeLabel = _setTimeLabel(progress);
_rightTimeLabel = _setTimeLabel(progress);
}

// This is the gesture recognizer used to move the thumb.
Expand Down Expand Up @@ -270,8 +268,8 @@ class _RenderProgressBar extends RenderBox {
double barStart;
double barEnd;
if (_timeLabelLocation == TimeLabelLocation.sides) {
barStart = _leftTimeLabel.width + _thumbRadius;
barEnd = size.width - _rightTimeLabel.width - _thumbRadius;
barStart = _leftTimeLabel().width + _thumbRadius;
barEnd = size.width - _rightTimeLabel().width - _thumbRadius;
} else {
barStart = _thumbRadius;
barEnd = size.width - _thumbRadius;
Expand All @@ -287,23 +285,24 @@ class _RenderProgressBar extends RenderBox {
/// This is used to update the thumb value and the left time label.
Duration get progress => _progress;
Duration _progress;
late TextPainter _leftTimeLabel;
set progress(Duration value) {
if (_progress == value) {
return;
}
_progress = value;
if (!_userIsDraggingThumb) {
_thumbValue = _proportionOfTotal(value);
if (_timeLabelLocation != TimeLabelLocation.none) {
_leftTimeLabel = _setTimeLabel(value);
}
}
markNeedsPaint();
}

TextPainter _setTimeLabel(Duration duration) {
final text = _getTimeString(duration);
TextPainter _leftTimeLabel() {
final text = _getTimeString(progress);
return _layoutText(text);
}

TextPainter _rightTimeLabel() {
final text = _getTimeString(total);
return _layoutText(text);
}

Expand All @@ -319,13 +318,11 @@ class _RenderProgressBar extends RenderBox {
/// The total time length of the media.
Duration get total => _total;
Duration _total;
late TextPainter _rightTimeLabel;
set total(Duration value) {
if (_total == value) {
return;
}
_total = value;
_rightTimeLabel = _setTimeLabel(value);
markNeedsPaint();
}

Expand Down Expand Up @@ -506,7 +503,7 @@ class _RenderProgressBar extends RenderBox {
}

double _textHeight() {
return _leftTimeLabel.height;
return _leftTimeLabel().height;
}

@override
Expand Down Expand Up @@ -545,12 +542,14 @@ class _RenderProgressBar extends RenderBox {

// current time label
final labelOffset = Offset(padding, barHeight);
_leftTimeLabel.paint(canvas, labelOffset);
final leftTimeLabel = _leftTimeLabel();
leftTimeLabel.paint(canvas, labelOffset);

// total time label
final rightLabelDx = size.width - padding - _rightTimeLabel.width;
final rightTimeLabel = _rightTimeLabel();
final rightLabelDx = size.width - padding - rightTimeLabel.width;
final rightLabelOffset = Offset(rightLabelDx, barHeight);
_rightTimeLabel.paint(canvas, rightLabelOffset);
_rightTimeLabel().paint(canvas, rightLabelOffset);

// progress bar
_drawProgressBar(canvas, Offset(padding, 0), Size(barWidth, barHeight));
Expand All @@ -565,20 +564,24 @@ class _RenderProgressBar extends RenderBox {
final padding = _thumbRadius;
final barHeight = 2 * _thumbRadius;

// painters
final leftTimeLabel = _leftTimeLabel();
final rightTimeLabel = _rightTimeLabel();

// current time label
final verticalOffset = size.height / 2 - _leftTimeLabel.height / 2;
final verticalOffset = size.height / 2 - leftTimeLabel.height / 2;
final currentLabelOffset = Offset(0, verticalOffset);
_leftTimeLabel.paint(canvas, currentLabelOffset);
leftTimeLabel.paint(canvas, currentLabelOffset);

// total time label
final totalLabelDx = size.width - _rightTimeLabel.width;
final totalLabelDx = size.width - rightTimeLabel.width;
final totalLabelOffset = Offset(totalLabelDx, verticalOffset);
_rightTimeLabel.paint(canvas, totalLabelOffset);
rightTimeLabel.paint(canvas, totalLabelOffset);

// progress bar
final leftLabelWidth = _leftTimeLabel.width;
final leftLabelWidth = leftTimeLabel.width;
final barWidth =
size.width - 2 * padding - leftLabelWidth - _rightTimeLabel.width;
size.width - 2 * padding - leftLabelWidth - rightTimeLabel.width;
_drawProgressBar(
canvas,
Offset(padding + leftLabelWidth, 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: 0.3.0
version: 0.3.2
homepage: https://github.com/suragch/audio_video_progress_bar

environment:
Expand Down

0 comments on commit fd9a1ee

Please sign in to comment.