Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/features/voice_to_text/widget/waveform.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:math' as math;
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class WaveformWidget extends StatefulWidget {
Expand Down Expand Up @@ -51,6 +53,10 @@ class _WaveformWidgetState extends State<WaveformWidget>
super.didUpdateWidget(oldWidget);
_controller.duration = widget.animationDuration;
final normalized = WaveformPainter.normalize(widget.amplitudes);
if (listEquals(normalized, _target) &&
oldWidget.animationDuration == widget.animationDuration) {
return;
}
_start = _resizeList(_displayed, normalized.length);
_target = _resizeList(normalized, normalized.length);
if (_target.isEmpty) {
Expand Down Expand Up @@ -152,7 +158,7 @@ class WaveformPainter extends CustomPainter {

final totalWidth =
amplitudes.length * barWidth + (amplitudes.length - 1) * spacing;
final startX = (size.width - totalWidth) / 2;
final startX = math.max((size.width - totalWidth) / 2, 0.0);
final maxHeight = size.height;

for (var i = 0; i < amplitudes.length; i++) {
Expand Down