Skip to content

Commit

Permalink
fix: 🐛 allow to enable/disable chat text field #164
Browse files Browse the repository at this point in the history
- Added flag to enable/disable chat text field.
  • Loading branch information
apurva010 committed May 21, 2024
1 parent 881f324 commit 1e3b3b6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
* **Feat**: [121](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/121)Added support
for configuring the audio recording quality.
* **Fix**: [131](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/131)
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,23 @@ ChatView(
)
```

24. Added `enabled` to enable/disable chat text field.

```dart
ChatView(
...
sendMessageConfig: SendMessageConfiguration(
...
textFieldConfig: TextFieldConfig(
enabled: true // [false] to disable text field.
),
...
),
...
)
```


## How to use

Expand Down
6 changes: 6 additions & 0 deletions lib/src/models/send_message_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -171,6 +176,7 @@ class TextFieldConfiguration {
this.compositionThresholdTime = const Duration(seconds: 1),
this.inputFormatters,
this.textCapitalization,
this.enabled = true,
});
}

Expand Down
51 changes: 34 additions & 17 deletions lib/src/widgets/chatui_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
keyboardType: textFieldConfig?.textInputType,
inputFormatters: textFieldConfig?.inputFormatters,
onChanged: _onChanged,
enabled: textFieldConfig?.enabled,
textCapitalization: textFieldConfig?.textCapitalization ??
TextCapitalization.sentences,
decoration: InputDecoration(
Expand All @@ -198,6 +199,11 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
borderRadius: textFieldConfig?.borderRadius ??
BorderRadius.circular(textFieldBorderRadius),
),
disabledBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.transparent),
borderRadius: textFieldConfig?.borderRadius ??
BorderRadius.circular(textFieldBorderRadius),
),
),
),
),
Expand All @@ -208,10 +214,12 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
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),
);
Expand All @@ -223,11 +231,13 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
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(
Expand All @@ -240,11 +250,13 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
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(
Expand All @@ -258,12 +270,17 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
!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,
),
)
],
);
Expand Down

0 comments on commit 1e3b3b6

Please sign in to comment.