Skip to content

Add clipRRect parameter to WaveStyle#258

Open
seelrd wants to merge 3 commits into
SimformSolutionsPvtLtd:mainfrom
undecagon:main
Open

Add clipRRect parameter to WaveStyle#258
seelrd wants to merge 3 commits into
SimformSolutionsPvtLtd:mainfrom
undecagon:main

Conversation

@seelrd

@seelrd seelrd commented Jan 11, 2024

Copy link
Copy Markdown

With this, you can provide an RRect to clip paint with to WaveStyle.
For example:

AudioWaveforms(
                    size: Size(MediaQuery.of(context).size.width, 200.0),
                    recorderController: recorderController,
                    waveStyle: WaveStyle(
                      clipRRect: RRect.fromLTRBR(0, 0, MediaQuery.of(context).size.width,
                          200, const Radius.circular(18)),
                    ),
                  );

This way waveforms can be painted inside a rectangle with border radius.

@ujas-m-simformsolutions

Copy link
Copy Markdown
Contributor

@seelrd Thanks for your contribution. Can you please share what issue you were facing? Also, if it was with labels then you can pass durationLinesHeight to change height of the line height.

@seelrd

seelrd commented Apr 27, 2024

Copy link
Copy Markdown
Author

@ujas-m-simformsolutions
I needed clipRRect to be able to have border radius on wave style lines.

hemantbeast added a commit to hemantbeast/audio_waveforms that referenced this pull request May 28, 2024
Comment on lines +82 to +86
try {
return await _methodChannel.invokeMethod(Constants.getDecibel);
} catch (e) {
return 0;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change to getDecibel looks unrelated to the clipRRect feature — could it move to its own PR? Beyond scope, returning 0 in the catch is risky: the method returns Future<double?>, so 0 reads as a genuine decibel value and callers can't distinguish a real reading from a failure.

I'd let the PlatformException propagate, or return null to signal "no value", and log the error rather than discard it. The bound e is also unused (the analyzer flags unused_catch_clause) — catch (_) or on PlatformException catch would be cleaner.

Comment on lines +68 to +69
/// Applies this clipRRect to waveforms.
final RRect? clipRRect;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposing this as a raw RRect means callers have to hardcode absolute LTRB coordinates and the box size, then recompute them whenever the layout or orientation changes. The idiomatic shape for a rounded-rect parameter is BorderRadius, which the painter can resolve against its own size on each paint and stay correct across devices. Could we take a BorderRadius here instead? The doc comment also just restates the field name — a line on what gets clipped, with a short example like gradient has, would help.

@lavigarg-simform

Copy link
Copy Markdown

@seelrd Thanks for this, and apologies for the delay.

A few things before this can move forward:

  • Rebase needed - Could you rebase on the latest main?

  • Please split out the getDecibel change. Wrapping the platform call in a try/catch
    that returns 0 is unrelated to the clipRRect feature, please create a separate PR for it if its still needed.

  • API shape - I left an inline note on this. Please check it out.

  • Clipping the duration UI. The clip is applied before the duration labels and lines
    are drawn, and those are drawn below the waveform box. With showDurationLabel: true and
    a clip bounded to the wave area, the labels get clipped away. It would be worth scoping
    the clip (save/restore) so it only affects the waves, or documenting the interaction.

  • Title + changelog. Could the title follow the repo convention (feat: ✨ ...), and a
    CHANGELOG entry be added under the unreleased section?

Thanks!

@lavigarg-simform lavigarg-simform added the waiting-for-response Waiting for someone to respond. label Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-response Waiting for someone to respond.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants