Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions example/lib/widgets/custom_chat_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ class _CustomChatBarState extends State<CustomChatBar> {
Future<void> _recordOrStop() async {
if (!isRecording.value) {
await controller?.record(
recorderSettings:
voiceRecordingConfig.recorderSettings ?? const RecorderSettings(),
recorderSettings: voiceRecordingConfig.recorderSettings,
);
isRecording.value = true;
} else {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/models/config_models/send_message_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import '../../values/typedefs.dart';

class SendMessageConfiguration {
const SendMessageConfiguration({
this.voiceRecordingConfiguration = const VoiceRecordingConfiguration(),
this.shouldSendImageWithText = false,
this.allowRecordingVoice = true,
this.textFieldConfig,
Expand All @@ -42,7 +43,6 @@ class SendMessageConfiguration {
this.replyTitleColor,
this.replyMessageColor,
this.closeIconColor,
this.voiceRecordingConfiguration,
this.micIconColor,
this.cancelRecordConfiguration,
this.removeImageIcon,
Expand Down Expand Up @@ -92,7 +92,7 @@ class SendMessageConfiguration {
final Color? micIconColor;

/// Styling configuration for recorder widget.
final VoiceRecordingConfiguration? voiceRecordingConfiguration;
final VoiceRecordingConfiguration voiceRecordingConfiguration;

/// Configuration for cancel voice recording
final CancelRecordConfiguration? cancelRecordConfiguration;
Expand Down Expand Up @@ -271,7 +271,7 @@ class VoiceRecordingConfiguration {
/// Styling configuration for the recorder widget as well as
/// configuring the audio recording quality.
const VoiceRecordingConfiguration({
this.recorderSettings,
this.recorderSettings = const RecorderSettings(),
this.waveStyle,
this.padding,
this.margin,
Expand Down Expand Up @@ -309,8 +309,8 @@ class VoiceRecordingConfiguration {

/// Configures audio recording settings for Android and iOS.
///
/// if null, default settings will be used.
final RecorderSettings? recorderSettings;
/// Default is [RecorderSettings] with default values.
final RecorderSettings recorderSettings;
}

class CancelRecordConfiguration {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/widgets/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class ChatView extends StatefulWidget {
this.appBar,
ChatBackgroundConfiguration? chatBackgroundConfig,
this.sendMessageBuilder,
this.sendMessageConfig,
this.onChatListTap,
required this.chatViewState,
ChatViewStateConfiguration? chatViewStateConfig,
this.featureActiveConfig = const FeatureActiveConfig(),
this.sendMessageConfig = const SendMessageConfiguration(),
this.emojiPickerSheetConfig,
this.replyMessageBuilder,
this.replySuggestionsConfig,
Expand Down Expand Up @@ -123,7 +123,7 @@ class ChatView extends StatefulWidget {
final ChatController chatController;

/// Provides configuration of default text field in chat.
final SendMessageConfiguration? sendMessageConfig;
final SendMessageConfiguration sendMessageConfig;

/// Provides current state of chat.
final ChatViewState chatViewState;
Expand Down Expand Up @@ -296,7 +296,7 @@ class _ChatViewState extends State<ChatView>
_sendMessageKey.currentState
?.assignReplyMessage(message),
textFieldConfig:
widget.sendMessageConfig?.textFieldConfig,
widget.sendMessageConfig.textFieldConfig,
),
),
if (featureActiveConfig.enableTextField)
Expand Down
58 changes: 28 additions & 30 deletions lib/src/widgets/chatui_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class ChatUITextField extends StatefulWidget {
required this.onPressed,
required this.onRecordingComplete,
required this.onImageSelected,
this.sendMessageConfig,
required this.sendMessageConfig,
super.key,
});

/// Provides configuration of default text field in chat.
final SendMessageConfiguration? sendMessageConfig;
final SendMessageConfiguration sendMessageConfig;

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

bool Function(KeyEvent)? _keyboardHandler;

SendMessageConfiguration? get sendMessageConfig => widget.sendMessageConfig;
SendMessageConfiguration get sendMessageConfig => widget.sendMessageConfig;

VoiceRecordingConfiguration? get voiceRecordingConfig =>
widget.sendMessageConfig?.voiceRecordingConfiguration;
VoiceRecordingConfiguration get voiceRecordingConfig =>
widget.sendMessageConfig.voiceRecordingConfiguration;

ImagePickerIconsConfiguration? get imagePickerIconsConfig =>
sendMessageConfig?.imagePickerIconsConfig;
sendMessageConfig.imagePickerIconsConfig;

TextFieldConfiguration? get textFieldConfig =>
sendMessageConfig?.textFieldConfig;
sendMessageConfig.textFieldConfig;

CancelRecordConfiguration? get cancelRecordConfiguration =>
sendMessageConfig?.cancelRecordConfiguration;
sendMessageConfig.cancelRecordConfiguration;

OutlineInputBorder get _outLineBorder => OutlineInputBorder(
borderSide: const BorderSide(color: Colors.transparent),
borderRadius: widget.sendMessageConfig?.textFieldConfig?.borderRadius ??
borderRadius: widget.sendMessageConfig.textFieldConfig?.borderRadius ??
BorderRadius.circular(textFieldBorderRadius),
);

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

Expand Down Expand Up @@ -142,7 +142,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {

void attachListeners() {
composingStatus.addListener(() {
widget.sendMessageConfig?.textFieldConfig?.onMessageTyping
widget.sendMessageConfig.textFieldConfig?.onMessageTyping
?.call(composingStatus.value);
});
}
Expand Down Expand Up @@ -198,7 +198,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
decoration: BoxDecoration(
borderRadius: textFieldConfig?.borderRadius ??
BorderRadius.circular(textFieldBorderRadius),
color: sendMessageConfig?.textFieldBackgroundColor ?? Colors.white,
color: sendMessageConfig.textFieldBackgroundColor ?? Colors.white,
),
child: ChatTextFieldViewBuilder<bool>(
valueListenable: isRecording,
Expand All @@ -210,22 +210,22 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
child: AudioWaveforms(
size: const Size(double.maxFinite, 50),
recorderController: controller!,
margin: voiceRecordingConfig?.margin,
padding: voiceRecordingConfig?.padding ??
margin: voiceRecordingConfig.margin,
padding: voiceRecordingConfig.padding ??
EdgeInsets.symmetric(
horizontal: cancelRecordConfiguration == null ? 8 : 5,
),
decoration: voiceRecordingConfig?.decoration ??
decoration: voiceRecordingConfig.decoration ??
BoxDecoration(
color: voiceRecordingConfig?.backgroundColor,
color: voiceRecordingConfig.backgroundColor,
borderRadius: BorderRadius.circular(12),
),
waveStyle: voiceRecordingConfig?.waveStyle ??
waveStyle: voiceRecordingConfig.waveStyle ??
WaveStyle(
extendWaveform: true,
showMiddleLine: false,
waveColor:
voiceRecordingConfig?.waveStyle?.waveColor ??
voiceRecordingConfig.waveStyle?.waveColor ??
Colors.black,
),
),
Expand Down Expand Up @@ -271,7 +271,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
hintText: textFieldConfig?.hintText ??
PackageStrings.currentLocale.message,
fillColor:
sendMessageConfig?.textFieldBackgroundColor ??
sendMessageConfig.textFieldBackgroundColor ??
Colors.white,
filled: true,
hintMaxLines: textFieldConfig?.hintMaxLines ?? 1,
Expand Down Expand Up @@ -300,13 +300,13 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
builder: (_, isNotEmpty, child) {
if (isNotEmpty) {
return IconButton(
color: sendMessageConfig?.defaultSendButtonColor ??
color: sendMessageConfig.defaultSendButtonColor ??
Colors.green,
style: sendMessageConfig?.sendButtonStyle,
style: sendMessageConfig.sendButtonStyle,
onPressed: (textFieldConfig?.enabled ?? true)
? _onPressed
: null,
icon: sendMessageConfig?.sendButtonIcon ??
icon: sendMessageConfig.sendButtonIcon ??
const Icon(Icons.send),
);
} else {
Expand Down Expand Up @@ -353,20 +353,19 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
],

// Always add the voice button at the end if allowed
if ((sendMessageConfig?.allowRecordingVoice ?? false) &&
if ((sendMessageConfig.allowRecordingVoice) &&
!kIsWeb &&
(Platform.isIOS || Platform.isAndroid))
IconButton(
onPressed: (textFieldConfig?.enabled ?? true)
? _recordOrStop
: null,
icon: (isRecordingValue
? voiceRecordingConfig?.stopIcon
: voiceRecordingConfig?.micIcon) ??
? voiceRecordingConfig.stopIcon
: voiceRecordingConfig.micIcon) ??
Icon(
isRecordingValue ? Icons.stop : Icons.mic,
color:
voiceRecordingConfig?.recorderIconColor,
color: voiceRecordingConfig.recorderIconColor,
),
),

Expand All @@ -380,7 +379,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
icon: cancelRecordConfiguration?.icon ??
const Icon(Icons.cancel_outlined),
color: cancelRecordConfiguration?.iconColor ??
voiceRecordingConfig?.recorderIconColor,
voiceRecordingConfig.recorderIconColor,
),
],
);
Expand Down Expand Up @@ -428,8 +427,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
);
if (!isRecording.value) {
await controller?.record(
recorderSettings:
voiceRecordingConfig?.recorderSettings ?? const RecorderSettings(),
recorderSettings: voiceRecordingConfig.recorderSettings,
);
isRecording.value = true;
} else {
Expand Down
16 changes: 7 additions & 9 deletions lib/src/widgets/send_message_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ import 'selected_image_view_widget.dart';

class SendMessageWidget extends StatefulWidget {
const SendMessageWidget({
Key? key,
required this.onSendTap,
this.sendMessageConfig,
required this.sendMessageConfig,
this.sendMessageBuilder,
this.messageConfig,
this.replyMessageBuilder,
}) : super(key: key);
super.key,
});

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

/// Provides configuration for text field appearance.
final SendMessageConfiguration? sendMessageConfig;
final SendMessageConfiguration sendMessageConfig;

/// Allow user to set custom text field.
final ReplyMessageWithReturnWidget? sendMessageBuilder;
Expand Down Expand Up @@ -165,9 +165,8 @@ class SendMessageWidgetState extends State<SendMessageWidget> {
builder: widget.replyMessageBuilder,
onChange: (value) => _replyMessage = value,
),
if (widget.sendMessageConfig
?.shouldSendImageWithText ??
false)
if (widget
.sendMessageConfig.shouldSendImageWithText)
SelectedImageViewWidget(
key: _selectedImageViewWidgetKey,
sendMessageConfig: widget.sendMessageConfig,
Expand All @@ -180,8 +179,7 @@ class SendMessageWidgetState extends State<SendMessageWidget> {
onRecordingComplete: _onRecordingComplete,
onImageSelected: (images, messageId) {
if (widget.sendMessageConfig
?.shouldSendImageWithText ??
false) {
.shouldSendImageWithText) {
if (images.isNotEmpty) {
_selectedImageViewWidgetKey.currentState
?.selectedImages.value = [
Expand Down