diff --git a/CHANGELOG.md b/CHANGELOG.md index 388af78f..3b711bf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [1.3.2] (Unreleased) +* **Fix**: [164](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/164) + Add flag to enable/disable chat text field. * **Fix**: [131](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/131) Fix unsupported operation while running on the web. * **Fix**: [160](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/160) Added diff --git a/README.md b/README.md index 2be310be..e8289423 100644 --- a/README.md +++ b/README.md @@ -533,6 +533,23 @@ ChatView( ) ``` +23. Added `enabled` to enable/disable chat text field. + +```dart +ChatView( + ... + sendMessageConfig: SendMessageConfiguration( + ... + textFieldConfig: TextFieldConfig( + enabled: false // [false] to disable text field. default is [true] + ), + ... + ), + ... + +) +``` + ## How to use diff --git a/lib/src/models/send_message_configuration.dart b/lib/src/models/send_message_configuration.dart index fe5b5e0e..c552f4c2 100644 --- a/lib/src/models/send_message_configuration.dart +++ b/lib/src/models/send_message_configuration.dart @@ -156,6 +156,11 @@ class TextFieldConfiguration { /// Default is 1 second. final Duration compositionThresholdTime; + /// Used for enable or disable the chat text field. + /// [false] also will disable the buttons for send images, record audio or take picture. + /// Default is [true]. + final bool enabled; + const TextFieldConfiguration({ this.contentPadding, this.maxLines, @@ -171,6 +176,7 @@ class TextFieldConfiguration { this.compositionThresholdTime = const Duration(seconds: 1), this.inputFormatters, this.textCapitalization, + this.enabled = true, }); } diff --git a/lib/src/widgets/chatui_textfield.dart b/lib/src/widgets/chatui_textfield.dart index d5bccf80..42137a92 100644 --- a/lib/src/widgets/chatui_textfield.dart +++ b/lib/src/widgets/chatui_textfield.dart @@ -174,6 +174,7 @@ class _ChatUITextFieldState extends State { keyboardType: textFieldConfig?.textInputType, inputFormatters: textFieldConfig?.inputFormatters, onChanged: _onChanged, + enabled: textFieldConfig?.enabled, textCapitalization: textFieldConfig?.textCapitalization ?? TextCapitalization.sentences, decoration: InputDecoration( @@ -198,6 +199,11 @@ class _ChatUITextFieldState extends State { borderRadius: textFieldConfig?.borderRadius ?? BorderRadius.circular(textFieldBorderRadius), ), + disabledBorder: OutlineInputBorder( + borderSide: const BorderSide(color: Colors.transparent), + borderRadius: textFieldConfig?.borderRadius ?? + BorderRadius.circular(textFieldBorderRadius), + ), ), ), ), @@ -208,10 +214,12 @@ class _ChatUITextFieldState extends State { return IconButton( color: sendMessageConfig?.defaultSendButtonColor ?? Colors.green, - onPressed: () { - widget.onPressed(); - _inputText.value = ''; - }, + onPressed: (textFieldConfig?.enabled ?? true) + ? () { + widget.onPressed(); + _inputText.value = ''; + } + : null, icon: sendMessageConfig?.sendButtonIcon ?? const Icon(Icons.send), ); @@ -223,11 +231,13 @@ class _ChatUITextFieldState extends State { true) IconButton( constraints: const BoxConstraints(), - onPressed: () => _onIconPressed( - ImageSource.camera, - config: - sendMessageConfig?.imagePickerConfiguration, - ), + onPressed: (textFieldConfig?.enabled ?? true) + ? () => _onIconPressed( + ImageSource.camera, + config: sendMessageConfig + ?.imagePickerConfiguration, + ) + : null, icon: imagePickerIconsConfig ?.cameraImagePickerIcon ?? Icon( @@ -240,11 +250,13 @@ class _ChatUITextFieldState extends State { true) IconButton( constraints: const BoxConstraints(), - onPressed: () => _onIconPressed( - ImageSource.gallery, - config: - sendMessageConfig?.imagePickerConfiguration, - ), + onPressed: (textFieldConfig?.enabled ?? true) + ? () => _onIconPressed( + ImageSource.gallery, + config: sendMessageConfig + ?.imagePickerConfiguration, + ) + : null, icon: imagePickerIconsConfig ?.galleryImagePickerIcon ?? Icon( @@ -258,12 +270,17 @@ class _ChatUITextFieldState extends State { !kIsWeb && (Platform.isIOS || Platform.isAndroid)) IconButton( - onPressed: _recordOrStop, + onPressed: (textFieldConfig?.enabled ?? true) + ? _recordOrStop + : null, icon: (isRecordingValue ? voiceRecordingConfig?.micIcon : voiceRecordingConfig?.stopIcon) ?? - Icon(isRecordingValue ? Icons.stop : Icons.mic), - color: voiceRecordingConfig?.recorderIconColor, + Icon( + isRecordingValue ? Icons.stop : Icons.mic, + color: + voiceRecordingConfig?.recorderIconColor, + ), ) ], );