Skip to content
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

Merged
merged 3 commits into from
Mar 4, 2024

Conversation

ujas-m-simformsolutions
Copy link
Collaborator

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

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) {
Copy link
Contributor

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.

lib/src/painters/player_wave_painter.dart Show resolved Hide resolved
lib/src/audio_waveforms.dart Outdated Show resolved Hide resolved
lib/src/painters/player_wave_painter.dart Outdated Show resolved Hide resolved
Signed-off-by: Ujas-Majithiya <ujasthakkar54@gmail.com>
@ujas-m-simformsolutions ujas-m-simformsolutions changed the title fix: 🐛 Rendering logic to fix unnecessary rendering fix: 🐛 unnecessary rendering Sep 28, 2023
});
widget.recorderController
..addListener(_updateOnControllerUpdate)
..onCurrentDuration.listen((duration) {
Copy link
Contributor

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)) {
Copy link
Contributor

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);
Copy link
Contributor

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.

@@ -178,4 +185,10 @@ class _AudioWaveformsState extends State<AudioWaveforms> {
setState(() {});
});
}

void _updateOnControllerUpdate() {
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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.

@ujas-m-simformsolutions ujas-m-simformsolutions merged commit e65649e into main Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rendering the entire waveform data is not necissary and it becomes very slow when your waveform data is long
3 participants