Skip to content

Commit 903ece1

Browse files
feat: ⚡ Update audio_waveform dependency
1 parent bb50d24 commit 903ece1

File tree

10 files changed

+94
-78
lines changed

10 files changed

+94
-78
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## [3.0.0] (unreleased)
2+
23
* **Feat**: [401](https://github.com/SimformSolutionsPvtLtd/chatview/pull/401)
34
Add selection and copy options for text view.
45
* **Breaking**: [318](https://github.com/SimformSolutionsPvtLtd/chatview/issues/318)
@@ -53,6 +54,11 @@
5354
* **Breaking**: [390](https://github.com/SimformSolutionsPvtLtd/chatview/pull/390) `playIcon` and
5455
`pauseIcon` Now accepts a callback that provides different icons based on whether the message is
5556
by the sender or not. accept `Widget`.
57+
* **Feat**: [390](https://github.com/SimformSolutionsPvtLtd/chatview/pull/406) Updated
58+
audio_waveforms version to `2.0.0`
59+
* **Breaking**: [390](https://github.com/SimformSolutionsPvtLtd/chatview/pull/406) Moved recording
60+
audio settings from `VoiceRecordingConfiguration` to `RecorderSettings`. Check out the migration
61+
guide [here](https://simform-flutter-packages.web.app/chatView/migration-guide).
5662

5763
## [2.5.0]
5864

doc/documentation.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,45 @@ This guide will help you migrate your code from previous versions of ChatView to
11451145

11461146
## Key Changes
11471147

1148+
### Voice Recording Configuration
1149+
1150+
The `VoiceRecordingConfiguration` class has been updated to utilize `RecorderSettings`, which now
1151+
encapsulates the recorder settings for both iOS and Android platforms. The `androidOutputFormat`
1152+
property has been removed so whatever format will be given by the encoder that will be used.
1153+
1154+
Previous Usage:
1155+
```dart
1156+
ChatView(
1157+
sendMessageConfig: SendMessageConfiguration(
1158+
voiceRecordingConfiguration: VoiceRecordingConfiguration(
1159+
sampleRate: 44100,
1160+
bitRate: 128000,
1161+
iosEncoder: IosEncoder.kAudioFormatMPEG4AAC,
1162+
androidEncoder: AndroidEncoder.aacLc,
1163+
androidOutputFormat: AndroidOutputFormat.mpeg4,
1164+
),
1165+
),
1166+
```
1167+
1168+
New Usage:
1169+
```dart
1170+
ChatView(
1171+
sendMessageConfig: SendMessageConfiguration(
1172+
voiceRecordingConfiguration: VoiceRecordingConfiguration(
1173+
recorderSettings: RecorderSettings(
1174+
bitRate: 128000,
1175+
sampleRate: 44100,
1176+
androidEncoderSettings: AndroidEncoderSettings(
1177+
androidEncoder: AndroidEncoder.aacLc,
1178+
),
1179+
iosEncoderSettings: IosEncoderSetting(
1180+
iosEncoder: IosEncoder.kAudioFormatMPEG4AAC,
1181+
),
1182+
),
1183+
),
1184+
),
1185+
```
1186+
11481187
### Text Field Action Items
11491188

11501189
You can now add action buttons to the input field using two builders:

example/lib/widgets/custom_chat_bar.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,7 @@ class _CustomChatBarState extends State<CustomChatBar> {
375375
Future<void> _recordOrStop() async {
376376
if (!isRecording.value) {
377377
await controller?.record(
378-
sampleRate: voiceRecordingConfig.sampleRate,
379-
bitRate: voiceRecordingConfig.bitRate,
380-
androidEncoder: voiceRecordingConfig.androidEncoder,
381-
iosEncoder: voiceRecordingConfig.iosEncoder,
382-
androidOutputFormat: voiceRecordingConfig.androidOutputFormat,
378+
recorderSettings: voiceRecordingConfig.recorderSettings,
383379
);
384380
isRecording.value = true;
385381
} else {

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies:
1313
sdk: flutter
1414
cupertino_icons: ^1.0.5
1515
flutter_svg: ^2.2.1
16-
audio_waveforms: ^1.3.0
16+
audio_waveforms: ^2.0.0
1717
chatview:
1818
path: ../
1919
intl:

lib/chatview.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ library chatview;
2525
export 'package:audio_waveforms/audio_waveforms.dart'
2626
show
2727
AndroidEncoder,
28-
AndroidOutputFormat,
28+
AndroidEncoderSettings,
2929
IosEncoder,
30+
IosEncoderSetting,
3031
PlayerWaveStyle,
32+
RecorderSettings,
3133
WaveStyle;
3234
export 'package:chatview_utils/chatview_utils.dart'
3335
hide

lib/src/models/config_models/send_message_configuration.dart

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import '../../values/typedefs.dart';
3030

3131
class SendMessageConfiguration {
3232
const SendMessageConfiguration({
33+
this.voiceRecordingConfiguration = const VoiceRecordingConfiguration(),
3334
this.shouldSendImageWithText = false,
3435
this.allowRecordingVoice = true,
3536
this.textFieldConfig,
@@ -42,7 +43,6 @@ class SendMessageConfiguration {
4243
this.replyTitleColor,
4344
this.replyMessageColor,
4445
this.closeIconColor,
45-
this.voiceRecordingConfiguration,
4646
this.micIconColor,
4747
this.cancelRecordConfiguration,
4848
this.removeImageIcon,
@@ -92,7 +92,7 @@ class SendMessageConfiguration {
9292
final Color? micIconColor;
9393

9494
/// Styling configuration for recorder widget.
95-
final VoiceRecordingConfiguration? voiceRecordingConfiguration;
95+
final VoiceRecordingConfiguration voiceRecordingConfiguration;
9696

9797
/// Configuration for cancel voice recording
9898
final CancelRecordConfiguration? cancelRecordConfiguration;
@@ -271,6 +271,7 @@ class VoiceRecordingConfiguration {
271271
/// Styling configuration for the recorder widget as well as
272272
/// configuring the audio recording quality.
273273
const VoiceRecordingConfiguration({
274+
this.recorderSettings = const RecorderSettings(),
274275
this.waveStyle,
275276
this.padding,
276277
this.margin,
@@ -279,11 +280,6 @@ class VoiceRecordingConfiguration {
279280
this.micIcon,
280281
this.recorderIconColor,
281282
this.stopIcon,
282-
this.sampleRate,
283-
this.bitRate,
284-
this.androidEncoder,
285-
this.iosEncoder,
286-
this.androidOutputFormat,
287283
});
288284

289285
/// Applies styles to waveform.
@@ -311,24 +307,8 @@ class VoiceRecordingConfiguration {
311307
/// Applies color to mic and stop icon.
312308
final Color? recorderIconColor;
313309

314-
/// The sample rate for audio is measured in samples per second.
315-
/// A higher sample rate generates more samples per second,
316-
/// resulting in better audio quality but also larger file sizes.
317-
final int? sampleRate;
318-
319-
/// Bitrate is the amount of data per second that the codec uses to
320-
/// encode the audio. A higher bitrate results in better quality
321-
/// but also larger file sizes.
322-
final int? bitRate;
323-
324-
/// Audio encoder to be used for recording for IOS.
325-
final IosEncoder? iosEncoder;
326-
327-
/// Audio encoder to be used for recording for Android.
328-
final AndroidEncoder? androidEncoder;
329-
330-
/// The audio output format to be used for recorded audio files on Android.
331-
final AndroidOutputFormat? androidOutputFormat;
310+
/// Configures audio recording settings for Android and iOS.
311+
final RecorderSettings recorderSettings;
332312
}
333313

334314
class CancelRecordConfiguration {

lib/src/widgets/chat_view.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class ChatView extends StatefulWidget {
5656
this.appBar,
5757
ChatBackgroundConfiguration? chatBackgroundConfig,
5858
this.sendMessageBuilder,
59-
this.sendMessageConfig,
6059
this.onChatListTap,
6160
required this.chatViewState,
6261
ChatViewStateConfiguration? chatViewStateConfig,
6362
this.featureActiveConfig = const FeatureActiveConfig(),
63+
this.sendMessageConfig = const SendMessageConfiguration(),
6464
this.emojiPickerSheetConfig,
6565
this.replyMessageBuilder,
6666
this.replySuggestionsConfig,
@@ -123,7 +123,7 @@ class ChatView extends StatefulWidget {
123123
final ChatController chatController;
124124

125125
/// Provides configuration of default text field in chat.
126-
final SendMessageConfiguration? sendMessageConfig;
126+
final SendMessageConfiguration sendMessageConfig;
127127

128128
/// Provides current state of chat.
129129
final ChatViewState chatViewState;
@@ -296,7 +296,7 @@ class _ChatViewState extends State<ChatView>
296296
_sendMessageKey.currentState
297297
?.assignReplyMessage(message),
298298
textFieldConfig:
299-
widget.sendMessageConfig?.textFieldConfig,
299+
widget.sendMessageConfig.textFieldConfig,
300300
),
301301
),
302302
if (featureActiveConfig.enableTextField)

lib/src/widgets/chatui_textfield.dart

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ class ChatUITextField extends StatefulWidget {
4444
required this.onPressed,
4545
required this.onRecordingComplete,
4646
required this.onImageSelected,
47-
this.sendMessageConfig,
47+
required this.sendMessageConfig,
4848
super.key,
4949
});
5050

5151
/// Provides configuration of default text field in chat.
52-
final SendMessageConfiguration? sendMessageConfig;
52+
final SendMessageConfiguration sendMessageConfig;
5353

5454
/// Provides focusNode for focusing text field.
5555
final FocusNode focusNode;
@@ -80,23 +80,23 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
8080

8181
bool Function(KeyEvent)? _keyboardHandler;
8282

83-
SendMessageConfiguration? get sendMessageConfig => widget.sendMessageConfig;
83+
SendMessageConfiguration get sendMessageConfig => widget.sendMessageConfig;
8484

85-
VoiceRecordingConfiguration? get voiceRecordingConfig =>
86-
widget.sendMessageConfig?.voiceRecordingConfiguration;
85+
VoiceRecordingConfiguration get voiceRecordingConfig =>
86+
widget.sendMessageConfig.voiceRecordingConfiguration;
8787

8888
ImagePickerIconsConfiguration? get imagePickerIconsConfig =>
89-
sendMessageConfig?.imagePickerIconsConfig;
89+
sendMessageConfig.imagePickerIconsConfig;
9090

9191
TextFieldConfiguration? get textFieldConfig =>
92-
sendMessageConfig?.textFieldConfig;
92+
sendMessageConfig.textFieldConfig;
9393

9494
CancelRecordConfiguration? get cancelRecordConfiguration =>
95-
sendMessageConfig?.cancelRecordConfiguration;
95+
sendMessageConfig.cancelRecordConfiguration;
9696

9797
OutlineInputBorder get _outLineBorder => OutlineInputBorder(
9898
borderSide: const BorderSide(color: Colors.transparent),
99-
borderRadius: widget.sendMessageConfig?.textFieldConfig?.borderRadius ??
99+
borderRadius: widget.sendMessageConfig.textFieldConfig?.borderRadius ??
100100
BorderRadius.circular(textFieldBorderRadius),
101101
);
102102

@@ -112,7 +112,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
112112
// onChanged is not called when text is set programmatically.
113113
widget.textEditingController.addListener(_listenTextEditingController);
114114
debouncer = Debouncer(
115-
sendMessageConfig?.textFieldConfig?.compositionThresholdTime ??
115+
sendMessageConfig.textFieldConfig?.compositionThresholdTime ??
116116
const Duration(seconds: 1));
117117
super.initState();
118118

@@ -142,7 +142,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
142142

143143
void attachListeners() {
144144
composingStatus.addListener(() {
145-
widget.sendMessageConfig?.textFieldConfig?.onMessageTyping
145+
widget.sendMessageConfig.textFieldConfig?.onMessageTyping
146146
?.call(composingStatus.value);
147147
});
148148
}
@@ -198,7 +198,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
198198
decoration: BoxDecoration(
199199
borderRadius: textFieldConfig?.borderRadius ??
200200
BorderRadius.circular(textFieldBorderRadius),
201-
color: sendMessageConfig?.textFieldBackgroundColor ?? Colors.white,
201+
color: sendMessageConfig.textFieldBackgroundColor ?? Colors.white,
202202
),
203203
child: ChatTextFieldViewBuilder<bool>(
204204
valueListenable: isRecording,
@@ -210,22 +210,22 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
210210
child: AudioWaveforms(
211211
size: const Size(double.maxFinite, 50),
212212
recorderController: controller!,
213-
margin: voiceRecordingConfig?.margin,
214-
padding: voiceRecordingConfig?.padding ??
213+
margin: voiceRecordingConfig.margin,
214+
padding: voiceRecordingConfig.padding ??
215215
EdgeInsets.symmetric(
216216
horizontal: cancelRecordConfiguration == null ? 8 : 5,
217217
),
218-
decoration: voiceRecordingConfig?.decoration ??
218+
decoration: voiceRecordingConfig.decoration ??
219219
BoxDecoration(
220-
color: voiceRecordingConfig?.backgroundColor,
220+
color: voiceRecordingConfig.backgroundColor,
221221
borderRadius: BorderRadius.circular(12),
222222
),
223-
waveStyle: voiceRecordingConfig?.waveStyle ??
223+
waveStyle: voiceRecordingConfig.waveStyle ??
224224
WaveStyle(
225225
extendWaveform: true,
226226
showMiddleLine: false,
227227
waveColor:
228-
voiceRecordingConfig?.waveStyle?.waveColor ??
228+
voiceRecordingConfig.waveStyle?.waveColor ??
229229
Colors.black,
230230
),
231231
),
@@ -271,7 +271,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
271271
hintText: textFieldConfig?.hintText ??
272272
PackageStrings.currentLocale.message,
273273
fillColor:
274-
sendMessageConfig?.textFieldBackgroundColor ??
274+
sendMessageConfig.textFieldBackgroundColor ??
275275
Colors.white,
276276
filled: true,
277277
hintMaxLines: textFieldConfig?.hintMaxLines ?? 1,
@@ -300,13 +300,13 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
300300
builder: (_, isNotEmpty, child) {
301301
if (isNotEmpty) {
302302
return IconButton(
303-
color: sendMessageConfig?.defaultSendButtonColor ??
303+
color: sendMessageConfig.defaultSendButtonColor ??
304304
Colors.green,
305-
style: sendMessageConfig?.sendButtonStyle,
305+
style: sendMessageConfig.sendButtonStyle,
306306
onPressed: (textFieldConfig?.enabled ?? true)
307307
? _onPressed
308308
: null,
309-
icon: sendMessageConfig?.sendButtonIcon ??
309+
icon: sendMessageConfig.sendButtonIcon ??
310310
const Icon(Icons.send),
311311
);
312312
} else {
@@ -353,20 +353,19 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
353353
],
354354

355355
// Always add the voice button at the end if allowed
356-
if ((sendMessageConfig?.allowRecordingVoice ?? false) &&
356+
if ((sendMessageConfig.allowRecordingVoice) &&
357357
!kIsWeb &&
358358
(Platform.isIOS || Platform.isAndroid))
359359
IconButton(
360360
onPressed: (textFieldConfig?.enabled ?? true)
361361
? _recordOrStop
362362
: null,
363363
icon: (isRecordingValue
364-
? voiceRecordingConfig?.stopIcon
365-
: voiceRecordingConfig?.micIcon) ??
364+
? voiceRecordingConfig.stopIcon
365+
: voiceRecordingConfig.micIcon) ??
366366
Icon(
367367
isRecordingValue ? Icons.stop : Icons.mic,
368-
color:
369-
voiceRecordingConfig?.recorderIconColor,
368+
color: voiceRecordingConfig.recorderIconColor,
370369
),
371370
),
372371

@@ -380,7 +379,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
380379
icon: cancelRecordConfiguration?.icon ??
381380
const Icon(Icons.cancel_outlined),
382381
color: cancelRecordConfiguration?.iconColor ??
383-
voiceRecordingConfig?.recorderIconColor,
382+
voiceRecordingConfig.recorderIconColor,
384383
),
385384
],
386385
);
@@ -428,11 +427,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
428427
);
429428
if (!isRecording.value) {
430429
await controller?.record(
431-
sampleRate: voiceRecordingConfig?.sampleRate,
432-
bitRate: voiceRecordingConfig?.bitRate,
433-
androidEncoder: voiceRecordingConfig?.androidEncoder,
434-
iosEncoder: voiceRecordingConfig?.iosEncoder,
435-
androidOutputFormat: voiceRecordingConfig?.androidOutputFormat,
430+
recorderSettings: voiceRecordingConfig.recorderSettings,
436431
);
437432
isRecording.value = true;
438433
} else {

0 commit comments

Comments
 (0)