RecordingIndicator.dart
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import 'package:flutter/material.dart';
class RecordingIndicator extends StatelessWidget {
final bool isRecording;
final bool willCancel;
final double volumeLevel; // 0.0-1.0
const RecordingIndicator({
Key? key,
required this.isRecording,
required this.willCancel,
required this.volumeLevel,
}) : super(key: key);
@override
Widget build(BuildContext context) {
if (!isRecording) return SizedBox.shrink();
return Positioned(
bottom: 100,
left: 0,
right: 0,
child: Column(
children: [
if (willCancel)
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
'松开手指,取消发送',
style: TextStyle(color: Colors.red),
),
)
else
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
'手指上滑,取消发送',
style: TextStyle(color: Colors.white),
),
),
_buildVolumeIndicator(volumeLevel),
],
),
);
}
Widget _buildVolumeIndicator(double level) {
const maxHeight = 100.0;
const minHeight = 20.0;
final height = minHeight + (maxHeight - minHeight) * level.clamp(0, 1);
return Container(
width: 6,
height: height,
decoration: BoxDecoration(
color: willCancel ? Colors.red : Colors.white,
borderRadius: BorderRadius.circular(3),
),
);
}
}