-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: 🐛 unnecessary rendering #243
Conversation
style: durationStyle, | ||
); | ||
|
||
if (_labels[i].offset.dx > -size.width / 2 && | ||
_labels[i].offset.dx < size.width + size.width / 2) { | ||
if (offset.dx > -halfWidth && offset.dx < halfWidth * 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to justify the application of if condition.
19e31ab
to
7e08cc7
Compare
Signed-off-by: Ujas-Majithiya <ujasthakkar54@gmail.com>
7e08cc7
to
6f70f37
Compare
lib/src/audio_waveforms.dart
Outdated
}); | ||
widget.recorderController | ||
..addListener(_updateOnControllerUpdate) | ||
..onCurrentDuration.listen((duration) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please store the StreamSubscription
returned by the listen
method and cancel it when not required.
|
||
if (labelDuration < | ||
Duration( | ||
seconds: currentlyRecordedDuration.inSeconds + durationBuffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format!
Also, it may be better to extract the Duration
object in a separate variable and then use that variable in the condition.
final height = size.height; | ||
final dx = | ||
-totalBackDistance.dx + dragOffset.dx + (spacing * i) - initialPosition; | ||
final scaledWaveHeight = (waveData[i] * scaleFactor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove unnecessary use of brackets.
lib/src/audio_waveforms.dart
Outdated
@@ -178,4 +185,10 @@ class _AudioWaveformsState extends State<AudioWaveforms> { | |||
setState(() {}); | |||
}); | |||
} | |||
|
|||
void _updateOnControllerUpdate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name seems ambiguous. Can you please improve it?
@@ -92,35 +92,31 @@ class PlayerWavePainter extends CustomPainter { | |||
|
|||
void _drawWave(Size size, Canvas canvas) { | |||
final length = waveformData.length; | |||
final halfWidth = size.width / 2; | |||
final halfHeight = size.height / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please prefer multiplication over division. You can use * 0.5
here instead of / 2
.
final label = _labels[i]; | ||
final content = label.content; | ||
final offset = label.offset; | ||
final halfWidth = size.width / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please prefer multiplication over division.
_labelPadding += spacing * updateFrequecy; | ||
} | ||
|
||
void _drawMiddleLine(Canvas canvas, Size size) { | ||
final halfWidth = size.width / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please prefer multiplication over division.
(waveData[i] * scaleFactor) + size.height - bottomPadding), | ||
_wavePaint); | ||
void _drawWave(Canvas canvas, Size size, int i) { | ||
final halfWidth = size.width / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please prefer multiplication over division.
Update method name
This PR adds conditions to rendering function so that it only renders when required. And also adds conditions to duration label list so that it doesn't add to many unnecessary labels.
Fixes #232