Skip to content

Commit 7f50820

Browse files
committed
feat: add voice_recording_attachment_theme.dart
1 parent 8579e78 commit 7f50820

10 files changed

+970
-559
lines changed

analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ linter:
8282
- prefer_const_constructors_in_immutables
8383
- prefer_const_declarations
8484
- prefer_const_literals_to_create_immutables
85-
- prefer_constructors_over_static_methods
8685
- prefer_contains
8786
- prefer_equal_for_default_values
8887
- prefer_final_fields

packages/stream_chat_flutter/lib/src/attachment/builder/voice_recording_attachment_builder/stream_voice_recording_list_player.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class _StreamVoiceRecordingListPlayerState
117117
/// {@template PlayListItem}
118118
/// Represents an audio attachment meta data.
119119
/// {@endtemplate}
120+
@Deprecated("Use 'PlaylistTrack' instead")
120121
class PlayListItem {
121122
/// {@macro PlayListItem}
122123
const PlayListItem({

packages/stream_chat_flutter/lib/src/attachment/file_attachment.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class StreamFileAttachment extends StatelessWidget {
3838

3939
/// The background color of the attachment.
4040
///
41-
/// Defaults to [StreamChatTheme.colorTheme.barsBg].
41+
/// Defaults to [StreamChatTheme._colorTheme.barsBg].
4242
final Color? backgroundColor;
4343

4444
/// The constraints to use when displaying the file.

packages/stream_chat_flutter/lib/src/attachment/voice_recording_attachment.dart

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ class StreamVoiceRecordingAttachment extends StatelessWidget {
112112

113113
@override
114114
Widget build(BuildContext context) {
115-
final theme = StreamVoiceRecordingTheme.of(context).playerTheme;
115+
final theme = StreamVoiceRecordingAttachmentTheme.of(context);
116+
final waveformSliderTheme = theme.audioWaveformSliderTheme;
116117

117118
final shape = this.shape ??
118119
RoundedRectangleBorder(
@@ -157,6 +158,7 @@ class StreamVoiceRecordingAttachment extends StatelessWidget {
157158
AudioDurationText(
158159
duration: track.duration,
159160
position: track.position,
161+
style: theme.durationTextStyle,
160162
),
161163
const SizedBox(width: 8),
162164
Expanded(
@@ -172,6 +174,14 @@ class StreamVoiceRecordingAttachment extends StatelessWidget {
172174
onChangeStart: onTrackSeekStart,
173175
onChanged: onTrackSeekChanged,
174176
onChangeEnd: onTrackSeekEnd,
177+
color: waveformSliderTheme?.color,
178+
progressColor: waveformSliderTheme?.progressColor,
179+
minBarHeight: waveformSliderTheme?.minBarHeight,
180+
spacingRatio: waveformSliderTheme?.spacingRatio,
181+
heightScale: waveformSliderTheme?.heightScale,
182+
thumbColor: waveformSliderTheme?.thumbColor,
183+
thumbBorderColor:
184+
waveformSliderTheme?.thumbBorderColor,
175185
),
176186
),
177187
),
@@ -229,6 +239,7 @@ class AudioDurationText extends StatelessWidget {
229239
super.key,
230240
required this.duration,
231241
required this.position,
242+
this.style,
232243
});
233244

234245
/// The total duration of the audio track.
@@ -237,14 +248,15 @@ class AudioDurationText extends StatelessWidget {
237248
/// The current position of the audio track.
238249
final Duration position;
239250

251+
/// The style to apply to the duration text.
252+
final TextStyle? style;
253+
240254
@override
241255
Widget build(BuildContext context) {
242-
final theme = StreamVoiceRecordingTheme.of(context).playerTheme;
243-
244256
if (position.inMilliseconds > 0) {
245257
return Text(
246258
position.toMinutesAndSeconds(),
247-
style: theme.timerTextStyle?.copyWith(
259+
style: style?.copyWith(
248260
// Use mono space for each num character.
249261
fontFeatures: [const FontFeature.tabularFigures()],
250262
),
@@ -253,7 +265,7 @@ class AudioDurationText extends StatelessWidget {
253265

254266
return Text(
255267
duration.toMinutesAndSeconds(),
256-
style: theme.timerTextStyle?.copyWith(
268+
style: style?.copyWith(
257269
// Use mono space for each num character.
258270
fontFeatures: [const FontFeature.tabularFigures()],
259271
),
@@ -294,39 +306,21 @@ class AudioControlButton extends StatelessWidget {
294306

295307
@override
296308
Widget build(BuildContext context) {
297-
final streamTheme = StreamChatTheme.of(context);
298-
final theme = StreamVoiceRecordingTheme.of(context).playerTheme;
309+
final theme = StreamVoiceRecordingAttachmentTheme.of(context);
299310

300311
return ElevatedButton(
301-
style: ElevatedButton.styleFrom(
302-
elevation: theme.buttonElevation,
303-
padding: theme.buttonPadding,
304-
backgroundColor: theme.buttonBackgroundColor,
305-
disabledBackgroundColor: theme.buttonBackgroundColor,
306-
shape: theme.buttonShape,
307-
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
308-
minimumSize: theme.buttonSize,
309-
),
312+
style: theme.audioControlButtonStyle,
310313
onPressed: switch (state) {
311314
TrackState.loading => null,
312315
TrackState.idle => onPlay,
313316
TrackState.playing => onPause,
314317
TrackState.paused => onPlay,
315318
},
316319
child: switch (state) {
317-
TrackState.loading => SizedBox.fromSize(
318-
size: const Size.square(24 - /* Padding */ 2),
319-
child: Center(
320-
child: CircularProgressIndicator.adaptive(
321-
valueColor: AlwaysStoppedAnimation(
322-
streamTheme.colorTheme.accentPrimary,
323-
),
324-
),
325-
),
326-
),
327-
TrackState.idle => Icon(theme.playIcon, color: theme.iconColor),
328-
TrackState.playing => Icon(theme.pauseIcon, color: theme.iconColor),
329-
TrackState.paused => Icon(theme.playIcon, color: theme.iconColor),
320+
TrackState.loading => theme.loadingIndicator,
321+
TrackState.idle => theme.playIcon,
322+
TrackState.playing => theme.pauseIcon,
323+
TrackState.paused => theme.playIcon,
330324
},
331325
);
332326
}
@@ -353,24 +347,17 @@ class SpeedControlButton extends StatelessWidget {
353347

354348
@override
355349
Widget build(BuildContext context) {
356-
final theme = StreamVoiceRecordingTheme.of(context).playerTheme;
350+
final theme = StreamVoiceRecordingAttachmentTheme.of(context);
357351

358352
return ElevatedButton(
359-
style: ElevatedButton.styleFrom(
360-
elevation: theme.speedButtonElevation,
361-
backgroundColor: theme.speedButtonBackgroundColor,
362-
padding: theme.speedButtonPadding,
363-
shape: theme.speedButtonShape,
364-
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
365-
minimumSize: theme.speedButtonSize,
366-
),
367-
onPressed: () {
368-
final nextSpeed = speed.next;
369-
onChangeSpeed?.call(nextSpeed);
353+
style: theme.speedControlButtonStyle,
354+
onPressed: switch (onChangeSpeed) {
355+
final it? => () => it(speed.next),
356+
_ => null,
370357
},
371358
child: Text(
372359
'x${speed.speed}',
373-
style: theme.speedButtonTextStyle,
360+
style: theme.playbackSpeedTextStyle,
374361
),
375362
);
376363
}

packages/stream_chat_flutter/lib/src/misc/audio_waveform.dart

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:math' as math;
33
import 'package:collection/collection.dart';
44
import 'package:flutter/foundation.dart';
55
import 'package:flutter/material.dart';
6+
import 'package:stream_chat_flutter/src/theme/audio_waveform_slider_theme.dart';
67

78
const _kAudioWaveformSliderThumbWidth = 4.0;
89
const _kAudioWaveformSliderThumbHeight = 28.0;
@@ -20,13 +21,15 @@ class StreamAudioWaveformSlider extends StatefulWidget {
2021
required this.onChanged,
2122
this.onChangeEnd,
2223
this.limit = 100,
23-
this.color = const Color(0xff7E828B),
24+
this.color,
2425
this.progress = 0,
25-
this.progressColor = const Color(0xff005FFF),
26-
this.minBarHeight = 2,
27-
this.spacingRatio = 0.3,
28-
this.heightScale = 1,
26+
this.progressColor,
27+
this.minBarHeight,
28+
this.spacingRatio,
29+
this.heightScale,
2930
this.inverse = true,
31+
this.thumbColor,
32+
this.thumbBorderColor,
3033
});
3134

3235
/// The waveform data to be drawn.
@@ -45,8 +48,8 @@ class StreamAudioWaveformSlider extends StatefulWidget {
4548

4649
/// The color of the wave bars.
4750
///
48-
/// Defaults to [Colors.grey].
49-
final Color color;
51+
/// Defaults to [StreamAudioWaveformSliderThemeData.color].
52+
final Color? color;
5053

5154
/// The number of wave bars that will be draw in the screen. When the length
5255
/// of [waveform] is bigger than [limit] only the X last bars will be shown.
@@ -61,30 +64,40 @@ class StreamAudioWaveformSlider extends StatefulWidget {
6164

6265
/// The color of the progressed wave bars.
6366
///
64-
/// Defaults to [Colors.blue].
65-
final Color progressColor;
67+
/// Defaults to [StreamAudioWaveformSliderThemeData.progressColor].
68+
final Color? progressColor;
6669

6770
/// The minimum height of the bars.
6871
///
69-
/// Defaults to 2.
70-
final double minBarHeight;
72+
/// Defaults to [StreamAudioWaveformSliderThemeData.minBarHeight].
73+
final double? minBarHeight;
7174

7275
/// The ratio of the spacing between the bars.
7376
///
74-
/// Defaults to 0.2.
75-
final double spacingRatio;
77+
/// Defaults to [StreamAudioWaveformSliderThemeData.spacingRatio].
78+
final double? spacingRatio;
7679

7780
/// The scale of the height of the bars.
7881
///
79-
/// Defaults to 1.
80-
final double heightScale;
82+
/// Defaults to [StreamAudioWaveformSliderThemeData.heightScale].
83+
final double? heightScale;
8184

8285
/// If true, the bars grow from right to left otherwise they grow from left
8386
/// to right.
8487
///
8588
/// Defaults to true.
8689
final bool inverse;
8790

91+
/// The color of the slider thumb.
92+
///
93+
/// Defaults to [StreamAudioWaveformSliderThemeData.thumbColor].
94+
final Color? thumbColor;
95+
96+
/// The color of the slider thumb border.
97+
///
98+
/// Defaults to [StreamAudioWaveformSliderThemeData.thumbBorderColor].
99+
final Color? thumbBorderColor;
100+
88101
@override
89102
State<StreamAudioWaveformSlider> createState() =>
90103
_StreamAudioWaveformSliderState();
@@ -93,6 +106,16 @@ class StreamAudioWaveformSlider extends StatefulWidget {
93106
class _StreamAudioWaveformSliderState extends State<StreamAudioWaveformSlider> {
94107
@override
95108
Widget build(BuildContext context) {
109+
final theme = StreamAudioWaveformSliderTheme.of(context);
110+
111+
final color = widget.color ?? theme.color!;
112+
final progressColor = widget.progressColor ?? theme.progressColor!;
113+
final minBarHeight = widget.minBarHeight ?? theme.minBarHeight!;
114+
final spacingRatio = widget.spacingRatio ?? theme.spacingRatio!;
115+
final heightScale = widget.heightScale ?? theme.heightScale!;
116+
final thumbColor = widget.thumbColor ?? theme.thumbColor!;
117+
final thumbBorderColor = widget.thumbBorderColor ?? theme.thumbBorderColor!;
118+
96119
return HorizontalSlider(
97120
onChangeStart: widget.onChangeStart,
98121
onChanged: widget.onChanged,
@@ -106,12 +129,12 @@ class _StreamAudioWaveformSliderState extends State<StreamAudioWaveformSlider> {
106129
StreamAudioWaveform(
107130
waveform: widget.waveform,
108131
limit: widget.limit,
109-
color: widget.color,
132+
color: color,
110133
progress: widget.progress,
111-
progressColor: widget.progressColor,
112-
minBarHeight: widget.minBarHeight,
113-
spacingRatio: widget.spacingRatio,
114-
heightScale: widget.heightScale,
134+
progressColor: progressColor,
135+
minBarHeight: minBarHeight,
136+
spacingRatio: spacingRatio,
137+
heightScale: heightScale,
115138
inverse: widget.inverse,
116139
),
117140
Builder(
@@ -123,6 +146,8 @@ class _StreamAudioWaveformSliderState extends State<StreamAudioWaveformSlider> {
123146
duration: const Duration(milliseconds: 300),
124147
left: progressWidth - _kAudioWaveformSliderThumbWidth / 2,
125148
child: StreamAudioWaveformSliderThumb(
149+
color: thumbColor,
150+
borderColor: thumbBorderColor,
126151
height: constraints.maxHeight,
127152
),
128153
);

0 commit comments

Comments
 (0)