Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 allow to enable/disable chat text field #164 #170

Merged
merged 1 commit into from
May 22, 2024
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
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
60 changes: 35 additions & 25 deletions lib/src/widgets/chatui_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class _ChatUITextFieldState extends State<ChatUITextField> {

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

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

@override
Widget build(BuildContext context) {
final outlineBorder = _outLineBorder;
return Container(
padding:
textFieldConfig?.padding ?? const EdgeInsets.symmetric(horizontal: 6),
Expand Down Expand Up @@ -174,6 +175,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 @@ -191,13 +193,10 @@ class _ChatUITextFieldState extends State<ChatUITextField> {
),
contentPadding: textFieldConfig?.contentPadding ??
const EdgeInsets.symmetric(horizontal: 6),
border: _outLineBorder,
focusedBorder: _outLineBorder,
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.transparent),
borderRadius: textFieldConfig?.borderRadius ??
BorderRadius.circular(textFieldBorderRadius),
),
border: outlineBorder,
focusedBorder: outlineBorder,
enabledBorder: outlineBorder,
disabledBorder: outlineBorder,
),
),
),
Expand All @@ -208,10 +207,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 +224,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 +243,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 +263,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