Skip to content

Commit 71c3926

Browse files
chore: 🔨 Minor Code improvement
1 parent 7f21142 commit 71c3926

File tree

5 files changed

+44
-49
lines changed

5 files changed

+44
-49
lines changed

example/lib/widgets/custom_chat_bar.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ class _CustomChatBarState extends State<CustomChatBar> {
375375
Future<void> _recordOrStop() async {
376376
if (!isRecording.value) {
377377
await controller?.record(
378-
recorderSettings:
379-
voiceRecordingConfig.recorderSettings ?? const RecorderSettings(),
378+
recorderSettings: voiceRecordingConfig.recorderSettings,
380379
);
381380
isRecording.value = true;
382381
} else {

lib/src/models/config_models/send_message_configuration.dart

Lines changed: 5 additions & 5 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,7 +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,
274+
this.recorderSettings = const RecorderSettings(),
275275
this.waveStyle,
276276
this.padding,
277277
this.margin,
@@ -309,8 +309,8 @@ class VoiceRecordingConfiguration {
309309

310310
/// Configures audio recording settings for Android and iOS.
311311
///
312-
/// if null, default settings will be used.
313-
final RecorderSettings? recorderSettings;
312+
/// Default is [RecorderSettings] with default values.
313+
final RecorderSettings recorderSettings;
314314
}
315315

316316
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 & 30 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,8 +427,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
428427
);
429428
if (!isRecording.value) {
430429
await controller?.record(
431-
recorderSettings:
432-
voiceRecordingConfig?.recorderSettings ?? const RecorderSettings(),
430+
recorderSettings: voiceRecordingConfig.recorderSettings,
433431
);
434432
isRecording.value = true;
435433
} else {

lib/src/widgets/send_message_widget.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ import 'selected_image_view_widget.dart';
3737

3838
class SendMessageWidget extends StatefulWidget {
3939
const SendMessageWidget({
40-
Key? key,
4140
required this.onSendTap,
42-
this.sendMessageConfig,
41+
required this.sendMessageConfig,
4342
this.sendMessageBuilder,
4443
this.messageConfig,
4544
this.replyMessageBuilder,
46-
}) : super(key: key);
45+
super.key,
46+
});
4747

4848
/// Provides call back when user tap on send button on text field.
4949
final StringMessageCallBack onSendTap;
5050

5151
/// Provides configuration for text field appearance.
52-
final SendMessageConfiguration? sendMessageConfig;
52+
final SendMessageConfiguration sendMessageConfig;
5353

5454
/// Allow user to set custom text field.
5555
final ReplyMessageWithReturnWidget? sendMessageBuilder;
@@ -165,9 +165,8 @@ class SendMessageWidgetState extends State<SendMessageWidget> {
165165
builder: widget.replyMessageBuilder,
166166
onChange: (value) => _replyMessage = value,
167167
),
168-
if (widget.sendMessageConfig
169-
?.shouldSendImageWithText ??
170-
false)
168+
if (widget
169+
.sendMessageConfig.shouldSendImageWithText)
171170
SelectedImageViewWidget(
172171
key: _selectedImageViewWidgetKey,
173172
sendMessageConfig: widget.sendMessageConfig,
@@ -180,8 +179,7 @@ class SendMessageWidgetState extends State<SendMessageWidget> {
180179
onRecordingComplete: _onRecordingComplete,
181180
onImageSelected: (images, messageId) {
182181
if (widget.sendMessageConfig
183-
?.shouldSendImageWithText ??
184-
false) {
182+
.shouldSendImageWithText) {
185183
if (images.isNotEmpty) {
186184
_selectedImageViewWidgetKey.currentState
187185
?.selectedImages.value = [

0 commit comments

Comments
 (0)