Restore voice information grid
All checks were successful
Build and deploy Flutter Web / build (push) Successful in 2m14s

This commit is contained in:
Ruslan Bakiev
2026-05-13 16:22:18 +07:00
parent d7b419fea6
commit 2366587693

View File

@@ -733,6 +733,7 @@ class _AddExperienceFlowState extends ConsumerState<AddExperienceFlow> {
noiseSuppress: true, noiseSuppress: true,
), ),
); );
final _voiceSamples = List<double>.filled(160, 0.0);
Future<List<PlaceRecommendation>>? _nearbyPlacesFuture; Future<List<PlaceRecommendation>>? _nearbyPlacesFuture;
StreamSubscription<Amplitude>? _amplitudeSub; StreamSubscription<Amplitude>? _amplitudeSub;
@@ -790,6 +791,7 @@ class _AddExperienceFlowState extends ConsumerState<AddExperienceFlow> {
_recording = true; _recording = true;
_liveLevel = 0; _liveLevel = 0;
_informationUnits = 0; _informationUnits = 0;
_voiceSamples.fillRange(0, _voiceSamples.length, 0);
}); });
} }
@@ -814,6 +816,9 @@ class _AddExperienceFlowState extends ConsumerState<AddExperienceFlow> {
final informationDelta = _consumeInformationDelta(level, now); final informationDelta = _consumeInformationDelta(level, now);
setState(() { setState(() {
_voiceSamples
..removeAt(0)
..add(level);
_liveLevel = _smoothLevel(_liveLevel, level); _liveLevel = _smoothLevel(_liveLevel, level);
_informationUnits = math.min( _informationUnits = math.min(
_minimumInformationUnits, _minimumInformationUnits,
@@ -870,7 +875,7 @@ class _AddExperienceFlowState extends ConsumerState<AddExperienceFlow> {
isRecording: _recording, isRecording: _recording,
isSubmitting: _submitting, isSubmitting: _submitting,
micAllowed: _micAllowed, micAllowed: _micAllowed,
waveController: _waveController, samples: _voiceSamples,
liveLevel: _liveLevel, liveLevel: _liveLevel,
canContinue: widget.hasTelegramAuth && informationProgress >= 1, canContinue: widget.hasTelegramAuth && informationProgress >= 1,
onToggleRecording: _toggleRecording, onToggleRecording: _toggleRecording,
@@ -1069,7 +1074,7 @@ class _VoiceStep extends StatelessWidget {
required this.isRecording, required this.isRecording,
required this.isSubmitting, required this.isSubmitting,
required this.micAllowed, required this.micAllowed,
required this.waveController, required this.samples,
required this.liveLevel, required this.liveLevel,
required this.canContinue, required this.canContinue,
required this.onToggleRecording, required this.onToggleRecording,
@@ -1082,7 +1087,7 @@ class _VoiceStep extends StatelessWidget {
final bool isRecording; final bool isRecording;
final bool isSubmitting; final bool isSubmitting;
final bool micAllowed; final bool micAllowed;
final WaveformRecorderController waveController; final List<double> samples;
final double liveLevel; final double liveLevel;
final bool canContinue; final bool canContinue;
final Future<void> Function() onToggleRecording; final Future<void> Function() onToggleRecording;
@@ -1090,7 +1095,7 @@ class _VoiceStep extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final showNext = canContinue && !isRecording; final canFinish = canContinue && !isRecording;
return Column( return Column(
children: [ children: [
@@ -1108,8 +1113,8 @@ class _VoiceStep extends StatelessWidget {
], ],
Expanded( Expanded(
child: Center( child: Center(
child: _LibraryWaveSurface( child: _VoiceInformationField(
controller: waveController, samples: samples,
active: isRecording, active: isRecording,
progress: informationProgress, progress: informationProgress,
liveLevel: liveLevel, liveLevel: liveLevel,
@@ -1125,29 +1130,13 @@ class _VoiceStep extends StatelessWidget {
size: 22, size: 22,
), ),
), ),
AnimatedSwitcher(
duration: const Duration(milliseconds: 180),
child: showNext
? Padding(
key: const ValueKey('next'),
padding: const EdgeInsets.only(bottom: 14),
child: FilledButton(
style: FilledButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: const Color(0xFF090613),
),
onPressed: isSubmitting ? null : onNext,
child: Text(isSubmitting ? 'Отправляем' : 'Далее'),
),
)
: const SizedBox.shrink(key: ValueKey('empty-next')),
),
_VoiceRecordButton( _VoiceRecordButton(
progress: informationProgress, progress: informationProgress,
liveLevel: liveLevel, liveLevel: liveLevel,
isRecording: isRecording, isRecording: isRecording,
canFinish: canFinish,
enabled: hasTelegramAuth && !isSubmitting, enabled: hasTelegramAuth && !isSubmitting,
onPressed: onToggleRecording, onPressed: canFinish ? onNext : onToggleRecording,
), ),
], ],
); );
@@ -1159,6 +1148,7 @@ class _VoiceRecordButton extends StatefulWidget {
required this.progress, required this.progress,
required this.liveLevel, required this.liveLevel,
required this.isRecording, required this.isRecording,
required this.canFinish,
required this.enabled, required this.enabled,
required this.onPressed, required this.onPressed,
}); });
@@ -1166,8 +1156,9 @@ class _VoiceRecordButton extends StatefulWidget {
final double progress; final double progress;
final double liveLevel; final double liveLevel;
final bool isRecording; final bool isRecording;
final bool canFinish;
final bool enabled; final bool enabled;
final Future<void> Function() onPressed; final VoidCallback onPressed;
@override @override
State<_VoiceRecordButton> createState() => _VoiceRecordButtonState(); State<_VoiceRecordButton> createState() => _VoiceRecordButtonState();
@@ -1264,7 +1255,7 @@ class _VoiceRecordButtonState extends State<_VoiceRecordButton>
width: 120, width: 120,
height: 120, height: 120,
child: FilledButton( child: FilledButton(
onPressed: widget.enabled ? () => widget.onPressed() : null, onPressed: widget.enabled ? widget.onPressed : null,
style: FilledButton.styleFrom( style: FilledButton.styleFrom(
backgroundColor: Colors.white, backgroundColor: Colors.white,
foregroundColor: const Color(0xFF090613), foregroundColor: const Color(0xFF090613),
@@ -1275,7 +1266,11 @@ class _VoiceRecordButtonState extends State<_VoiceRecordButton>
elevation: 0, elevation: 0,
), ),
child: Icon( child: Icon(
widget.isRecording ? Icons.pause_rounded : Icons.mic_rounded, widget.canFinish
? Icons.check_rounded
: widget.isRecording
? Icons.pause_rounded
: Icons.mic_rounded,
size: 48, size: 48,
), ),
), ),
@@ -1285,15 +1280,15 @@ class _VoiceRecordButtonState extends State<_VoiceRecordButton>
} }
} }
class _LibraryWaveSurface extends StatelessWidget { class _VoiceInformationField extends StatelessWidget {
const _LibraryWaveSurface({ const _VoiceInformationField({
required this.controller, required this.samples,
required this.active, required this.active,
required this.progress, required this.progress,
required this.liveLevel, required this.liveLevel,
}); });
final WaveformRecorderController controller; final List<double> samples;
final bool active; final bool active;
final double progress; final double progress;
final double liveLevel; final double liveLevel;
@@ -1310,14 +1305,14 @@ class _LibraryWaveSurface extends StatelessWidget {
BoxShadow( BoxShadow(
color: const Color( color: const Color(
0xFFFF2D75, 0xFFFF2D75,
).withValues(alpha: active ? 0.20 + liveLevel * 0.18 : 0.06), ).withValues(alpha: active ? 0.18 + liveLevel * 0.18 : 0.06),
blurRadius: 110, blurRadius: 110,
spreadRadius: 24, spreadRadius: 24,
), ),
BoxShadow( BoxShadow(
color: const Color( color: const Color(
0xFF38F5D3, 0xFF38F5D3,
).withValues(alpha: active ? 0.10 + liveLevel * 0.12 : 0.04), ).withValues(alpha: active ? 0.08 + liveLevel * 0.10 : 0.03),
blurRadius: 130, blurRadius: 130,
spreadRadius: 14, spreadRadius: 14,
), ),
@@ -1325,122 +1320,141 @@ class _LibraryWaveSurface extends StatelessWidget {
), ),
child: const SizedBox.square(dimension: 210), child: const SizedBox.square(dimension: 210),
), ),
Positioned.fill( LayoutBuilder(
child: Padding( builder: (context, constraints) {
padding: const EdgeInsets.symmetric(horizontal: 4), return CustomPaint(
child: active size: Size(
? AnimatedWaveList( constraints.maxWidth,
key: ValueKey(controller.startTime), constraints.maxHeight.clamp(300.0, 520.0),
stream: controller.amplitudeStream, ),
barBuilder: (animation, amplitude) => _VoiceWaveBar( painter: _VoiceInformationPainter(
animation: animation, samples: samples,
amplitude: amplitude, active: active,
progress: progress, progress: progress,
), liveLevel: liveLevel,
) ),
: _IdleWaveBars(progress: progress), );
), },
), ),
], ],
); );
} }
} }
class _VoiceWaveBar extends StatelessWidget { class _VoiceInformationPainter extends CustomPainter {
const _VoiceWaveBar({ const _VoiceInformationPainter({
required this.animation, required this.samples,
required this.amplitude, required this.active,
required this.progress, required this.progress,
required this.liveLevel,
}); });
final Animation<double> animation; final List<double> samples;
final Amplitude amplitude; final bool active;
final double progress; final double progress;
final double liveLevel;
@override @override
Widget build(BuildContext context) { void paint(Canvas canvas, Size size) {
final level = _amplitudeLevel(amplitude.current); const columns = 18;
final height = 14 + level * 210; const rows = 12;
final color = Color.lerp( const gap = 6.0;
Colors.white.withValues(alpha: 0.28), final cellSize = math
const Color(0xFFFF2D75), .min(
progress.clamp(0.0, 1.0), (size.width - gap * (columns - 1)) / columns,
)!; (size.height - gap * (rows - 1)) / rows,
)
.clamp(8.0, 22.0);
final gridWidth = columns * cellSize + (columns - 1) * gap;
final gridHeight = rows * cellSize + (rows - 1) * gap;
final startX = (size.width - gridWidth) / 2;
final startY = (size.height - gridHeight) / 2;
final totalCells = columns * rows;
final activeCells = (progress * totalCells).round();
return SizeTransition( final backgroundPaint = Paint()
sizeFactor: animation, ..color = Colors.white.withValues(alpha: 0.10)
axis: Axis.horizontal, ..style = PaintingStyle.fill;
child: Align( final borderPaint = Paint()
alignment: Alignment.center, ..color = Colors.white.withValues(alpha: 0.05)
child: Container( ..style = PaintingStyle.stroke
width: 5, ..strokeWidth = 1;
height: height, final glowPaint = Paint()
margin: const EdgeInsets.symmetric(horizontal: 2.5), ..color = const Color(0xFFFF2D75).withValues(alpha: active ? 0.18 : 0.08)
decoration: BoxDecoration( ..maskFilter = const MaskFilter.blur(BlurStyle.normal, 18);
borderRadius: BorderRadius.circular(20),
gradient: LinearGradient( for (var row = 0; row < rows; row++) {
begin: Alignment.bottomCenter, for (var column = 0; column < columns; column++) {
end: Alignment.topCenter, final cellIndex = row * columns + column;
final sampleIndex = samples.isEmpty
? 0
: ((cellIndex / (totalCells - 1)) * (samples.length - 1)).round();
final signal = samples.isEmpty
? 0.0
: samples[sampleIndex].clamp(0.0, 1.0);
final filled = _cellOrder(cellIndex, totalCells) < activeCells;
final x = startX + column * (cellSize + gap);
final y = startY + row * (cellSize + gap);
final rect = RRect.fromRectAndRadius(
Rect.fromLTWH(x, y, cellSize, cellSize),
const Radius.circular(4),
);
canvas.drawRRect(rect, backgroundPaint);
canvas.drawRRect(rect, borderPaint);
final centerDistance = (row - (rows - 1) / 2).abs();
final columnSignal = (signal * 0.80 + liveLevel * 0.20).clamp(0.0, 1.0);
final waveReach = 0.5 + columnSignal * rows * 0.42;
final inWave =
centerDistance <= waveReach + _hashUnit(cellIndex) * 0.55;
if (inWave) {
canvas.drawRRect(
rect,
Paint()
..color = Colors.white.withValues(
alpha: active
? 0.09 + columnSignal * 0.18
: 0.06 + columnSignal * 0.06,
),
);
}
if (filled) {
final paint = Paint()
..shader = LinearGradient(
begin: Alignment.bottomLeft,
end: Alignment.topRight,
colors: [ colors: [
color.withValues(alpha: 0.42), const Color(
color, 0xFFE11D48,
const Color(0xFFFF7A90), ).withValues(alpha: 0.76 + columnSignal * 0.18),
const Color(
0xFFFF6B8A,
).withValues(alpha: 0.56 + columnSignal * 0.18),
], ],
), ).createShader(rect.outerRect)
boxShadow: [ ..style = PaintingStyle.fill;
BoxShadow( canvas.drawRRect(rect.inflate(1.2 + columnSignal * 1.8), glowPaint);
color: color.withValues(alpha: 0.38), canvas.drawRRect(rect, paint);
blurRadius: 18, }
spreadRadius: 1, }
), }
],
),
),
),
);
} }
double _amplitudeLevel(double db) { int _cellOrder(int index, int total) => ((index + 11) * 73) % total;
final normalized = ((db.clamp(-76.0, -6.0) + 76.0) / 70.0).clamp(0.0, 1.0);
return math.pow(normalized, 0.62).toDouble(); double _hashUnit(int index) {
final value = math.sin(index * 12.9898 + 78.233) * 43758.5453;
return value - value.floorToDouble();
} }
}
class _IdleWaveBars extends StatelessWidget {
const _IdleWaveBars({required this.progress});
final double progress;
@override @override
Widget build(BuildContext context) { bool shouldRepaint(covariant _VoiceInformationPainter oldDelegate) {
final color = Color.lerp( return oldDelegate.samples != samples ||
Colors.white.withValues(alpha: 0.18), oldDelegate.active != active ||
const Color(0xFFFF2D75), oldDelegate.progress != progress ||
progress.clamp(0.0, 1.0), oldDelegate.liveLevel != liveLevel;
)!;
return Center(
child: SizedBox(
height: 220,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: List.generate(26, (index) {
final distance = (index - 12.5).abs();
final height = 18 + math.max(0.0, 1 - distance / 13) * 56;
return Container(
width: 4,
height: height,
margin: const EdgeInsets.symmetric(horizontal: 3),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(20),
),
);
}),
),
),
);
} }
} }