Skip to content

Commit 01c4d8c

Browse files
committed
feat: ✨ Add support for plus icon and action items in chat text field
1 parent 180c0d0 commit 01c4d8c

16 files changed

+521
-316
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## [2.4.2] (unreleased)
22

3+
* **Breaking**: [318](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/318)
4+
Provide support for action item widgets on the chat text field. Also, provide a way to add plus/attach
5+
button to open the overlay for action items.
36
* **Fix**: [303](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/303)
47
Hit ENTER button on PC keyboard, then send out message immediately
58
* **Fix**: [289](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/289)

doc/documentation.md

Lines changed: 32 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -502,182 +502,48 @@ real-time messaging with supporting media uploads.
502502

503503
# Migration Guide
504504

505-
## Migration Guide for ChatView 2.0.0
506-
This guide will help you migrate your code from previous versions of ChatView to version 2.0.0.
505+
## Migration Guide for ChatView 3.0.0
506+
This guide will help you migrate your code from previous versions of ChatView to version 3.0.0.
507507

508508
## Key Changes
509509

510-
### Renamed Properties
510+
### Add action item widgets for text field
511511

512-
- Renamed `sendBy` field to `sentBy` in `Message` class.
513-
- Renamed `chatUsers` field to `otherUsers` in `ChatController` class.
512+
- Add `CameraActionButton` and `GalleryActionButton` widgets to the text field for camera and gallery actions.
513+
- Now, you can add overlay action button to show overlay action items in the text field.
514+
- With multiple action items
514515

515-
### Moved Properties
516+
To show camera and gallery action items in the text field, you can use `textFieldActionWidgets`.
516517

517-
- Moved `currentUser` field from `ChatView` widget to `ChatController` class.
518-
519-
### Updated Methods
520-
521-
- Updated `id` value in `copyWith` method of `Message` to have correct value.
522-
- Removed `showTypingIndicator` field from `ChatView` and replaced it with `ChatController.showTypingIndicator`.
523-
524-
### JSON Serialization Changes
525-
526-
The format for `fromJson` and `toJson` methods changed for several classes:
527-
528-
#### ChatUser
529-
530-
**Before (`ChatUser.fromJson`):**
531-
```dart
532-
ChatUser.fromJson(
533-
{
534-
...
535-
'imageType': ImageType.asset,
536-
...
537-
},
538-
),
539-
```
540-
541-
**After (`ChatUser.fromJson`):**
542-
```dart
543-
ChatUser.fromJson(
544-
{
545-
...
546-
'imageType': 'asset',
547-
...
548-
},
549-
),
550-
```
551-
552-
**Before (`ChatUser.toJson`):**
553-
```dart
554-
{
555-
...
556-
imageType: ImageType.asset,
557-
...
558-
}
559-
```
560-
561-
**After (`ChatUser.toJson`):**
562-
```dart
563-
{
564-
...
565-
imageType: asset,
566-
...
567-
}
568-
```
569-
570-
#### Message
571-
572-
**Before (`Message.fromJson`):**
573-
```dart
574-
Message.fromJson(
575-
{
576-
...
577-
'createdAt': DateTime.now(),
578-
'message_type': MessageType.text,
579-
'voice_message_duration': Duration(seconds: 5),
580-
...
581-
}
582-
)
583-
```
584-
585-
**After (`Message.fromJson`):**
586-
```dart
587-
Message.fromJson(
588-
{
589-
...
590-
'createdAt': '2024-06-13T17:32:19.586412',
591-
'message_type': 'text',
592-
'voice_message_duration': '5000000',
593-
...
594-
}
595-
)
596-
```
597-
598-
**Before (`Message.toJson`):**
599-
```dart
600-
{
601-
...
602-
createdAt: 2024-06-13 17:23:19.454789,
603-
message_type: MessageType.text,
604-
voice_message_duration: 0:00:05.000000,
605-
...
606-
}
607-
```
608-
609-
**After (`Message.toJson`):**
610-
```dart
611-
{
612-
...
613-
createdAt: 2024-06-13T17:32:19.586412,
614-
message_type: text,
615-
voice_message_duration: 5000000,
616-
...
617-
}
618-
```
619-
620-
#### ReplyMessage
621-
622-
**Before (`ReplyMessage.fromJson`):**
623-
```dart
624-
ReplyMessage.fromJson(
625-
{
626-
...
627-
'message_type': MessageType.text,
628-
'voiceMessageDuration': Duration(seconds: 5),
629-
...
630-
}
631-
)
632-
```
633-
634-
**After (`ReplyMessage.fromJson`):**
635518
```dart
636-
ReplyMessage.fromJson(
637-
{
638-
...
639-
'message_type': 'text',
640-
'voiceMessageDuration': '5000000',
641-
...
642-
}
643-
)
644-
```
645-
646-
**Before (`ReplyMessage.toJson`):**
647-
```dart
648-
{
649-
...
650-
message_type: MessageType.text,
651-
voiceMessageDuration: 0:00:05.000000,
652-
...
653-
}
654-
```
655-
656-
**After (`ReplyMessage.toJson`):**
657-
```dart
658-
{
659-
...
660-
message_type: text,
661-
voiceMessageDuration: 5000000,
662-
...
663-
}
664-
```
665-
666-
## Typing Indicator Changes
667-
668-
**Before:**
669-
```dart
670-
ChatView(
671-
showTypingIndicator: false,
519+
...
520+
textFieldConfig: TextFieldConfiguration(
521+
textFieldActionWidgets: [
522+
CameraActionButton(
523+
icon: const Icon(
524+
Icons.camera_alt,
525+
),
526+
onPressed: (path) {
527+
if (path != null) {
528+
_onSendTap(path, const ReplyMessage(), MessageType.image);
529+
}
530+
},
531+
),
532+
GalleryActionButton(
533+
icon: const Icon(
534+
Icons.photo_library,
535+
),
536+
onPressed: (path) {
537+
if (path != null) {
538+
_onSendTap(path, const ReplyMessage(), MessageType.image);
539+
}
540+
},
541+
),
542+
],
672543
),
544+
...
673545
```
674546

675-
**After:**
676-
```dart
677-
// Use it with your ChatController instance
678-
_chatController.setTypingIndicator = true; // for showing indicator
679-
_chatController.setTypingIndicator = false; // for hiding indicator
680-
```
681547

682548
# Contributors
683549

example/lib/main.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,28 @@ class _ChatScreenState extends State<ChatScreen> {
4343
_chatController = ChatController(
4444
initialMessageList: Data.messageList,
4545
scrollController: ScrollController(),
46-
currentUser: ChatUser(
46+
currentUser: const ChatUser(
4747
id: '1',
4848
name: 'Flutter',
4949
profilePhoto: Data.profileImage,
5050
),
5151
otherUsers: [
52-
ChatUser(
52+
const ChatUser(
5353
id: '2',
5454
name: 'Simform',
5555
profilePhoto: Data.profileImage,
5656
),
57-
ChatUser(
57+
const ChatUser(
5858
id: '3',
5959
name: 'Jhon',
6060
profilePhoto: Data.profileImage,
6161
),
62-
ChatUser(
62+
const ChatUser(
6363
id: '4',
6464
name: 'Mike',
6565
profilePhoto: Data.profileImage,
6666
),
67-
ChatUser(
67+
const ChatUser(
6868
id: '5',
6969
name: 'Rich',
7070
profilePhoto: Data.profileImage,

lib/chatview.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@
2222

2323
library chatview;
2424

25-
export 'src/widgets/chat_view.dart';
26-
export 'src/models/models.dart';
27-
export 'src/widgets/chat_view_appbar.dart';
28-
export 'src/values/enumeration.dart';
29-
export 'src/values/typedefs.dart';
30-
export 'package:chatview_utils/chatview_utils.dart';
3125
export 'package:audio_waveforms/audio_waveforms.dart'
3226
show
3327
WaveStyle,
3428
PlayerWaveStyle,
3529
AndroidEncoder,
3630
IosEncoder,
3731
AndroidOutputFormat;
38-
export 'src/models/config_models/receipts_widget_config.dart';
39-
export 'src/extensions/extensions.dart' show MessageTypes;
32+
export 'package:chatview_utils/chatview_utils.dart';
4033
export 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
34+
35+
export 'src/extensions/extensions.dart' show MessageTypes;
36+
export 'src/models/config_models/receipts_widget_config.dart';
37+
export 'src/models/models.dart';
38+
export 'src/values/enumeration.dart';
39+
export 'src/values/typedefs.dart';
40+
export 'src/widgets/action_widgets/camera_action_button.dart';
41+
export 'src/widgets/action_widgets/gallery_action_button.dart';
42+
export 'src/widgets/action_widgets/overlay_action_button.dart';
43+
export 'src/widgets/action_widgets/text_field_action_button.dart';
44+
export 'src/widgets/chat_view.dart';
45+
export 'src/widgets/chat_view_appbar.dart';

lib/src/models/config_models/send_message_configuration.dart

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222

2323
import 'package:audio_waveforms/audio_waveforms.dart';
24+
import 'package:chatview_utils/chatview_utils.dart';
2425
import 'package:flutter/material.dart';
2526
import 'package:flutter/services.dart';
26-
import 'package:chatview_utils/chatview_utils.dart';
2727
import 'package:image_picker/image_picker.dart';
2828

2929
import '../../values/typedefs.dart';
@@ -62,12 +62,6 @@ class SendMessageConfiguration {
6262
/// Enable/disable voice recording. Enabled by default.
6363
final bool allowRecordingVoice;
6464

65-
/// Enable/disable image picker from gallery. Enabled by default.
66-
final bool enableGalleryImagePicker;
67-
68-
/// Enable/disable send image from camera. Enabled by default.
69-
final bool enableCameraImagePicker;
70-
7165
/// Color of mic icon when replying to some voice message.
7266
final Color? micIconColor;
7367

@@ -89,8 +83,6 @@ class SendMessageConfiguration {
8983
this.replyMessageColor,
9084
this.closeIconColor,
9185
this.allowRecordingVoice = true,
92-
this.enableCameraImagePicker = true,
93-
this.enableGalleryImagePicker = true,
9486
this.voiceRecordingConfiguration,
9587
this.micIconColor,
9688
this.cancelRecordConfiguration,
@@ -168,6 +160,17 @@ class TextFieldConfiguration {
168160
/// Default is [true].
169161
final bool enabled;
170162

163+
/// List of widgets to be shown as action widget in text field.
164+
final List<Widget>? textFieldTrailingActionWidgets;
165+
166+
/// List of widgets to be shown as leading action widget in text field.
167+
final List<Widget>? textFieldLeadingActionWidgets;
168+
169+
/// hint text max lines in text field.
170+
final int? hintMaxLines;
171+
172+
final bool hideLeadingActionsOnType;
173+
171174
const TextFieldConfiguration({
172175
this.contentPadding,
173176
this.maxLines,
@@ -184,6 +187,10 @@ class TextFieldConfiguration {
184187
this.inputFormatters,
185188
this.textCapitalization,
186189
this.enabled = true,
190+
this.textFieldLeadingActionWidgets,
191+
this.textFieldTrailingActionWidgets,
192+
this.hintMaxLines,
193+
this.hideLeadingActionsOnType = true,
187194
});
188195
}
189196

lib/src/models/models.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,25 @@
2020
* SOFTWARE.
2121
*/
2222
export 'chat_bubble.dart';
23+
export 'config_models/chat_bubble_configuration.dart';
24+
export 'config_models/chat_view_states_configuration.dart';
25+
export 'config_models/emoji_message_configuration.dart';
26+
export 'config_models/feature_active_config.dart';
2327
export 'config_models/image_message_configuration.dart';
28+
export 'config_models/link_preview_configuration.dart';
29+
export 'config_models/message_configuration.dart';
30+
export 'config_models/message_list_configuration.dart';
2431
export 'config_models/message_reaction_configuration.dart';
2532
export 'config_models/profile_circle_configuration.dart';
26-
export 'config_models/chat_bubble_configuration.dart';
27-
export 'config_models/replied_message_configuration.dart';
28-
export 'config_models/swipe_to_reply_configuration.dart';
29-
export 'config_models/reply_popup_configuration.dart';
3033
export 'config_models/reaction_popup_configuration.dart';
31-
export 'config_models/message_list_configuration.dart';
32-
export 'config_models/emoji_message_configuration.dart';
33-
export 'config_models/message_configuration.dart';
34-
export 'config_models/send_message_configuration.dart';
35-
export 'config_models/link_preview_configuration.dart';
36-
export 'config_models/type_indicator_configuration.dart';
37-
export 'config_models/chat_view_states_configuration.dart';
34+
export 'config_models/replied_message_configuration.dart';
3835
export 'config_models/replied_msg_auto_scroll_config.dart';
39-
export 'config_models/feature_active_config.dart';
36+
export 'config_models/reply_popup_configuration.dart';
4037
export 'config_models/reply_suggestions_config.dart';
41-
export 'config_models/suggestion_list_config.dart';
4238
export 'config_models/scroll_to_bottom_button_config.dart';
39+
export 'config_models/send_message_configuration.dart';
40+
export 'config_models/suggestion_list_config.dart';
41+
export 'config_models/swipe_to_reply_configuration.dart';
42+
export 'config_models/type_indicator_configuration.dart';
4343
export 'config_models/voice_message_configuration.dart';
44+
export 'overlay_action_widget.dart';

0 commit comments

Comments
 (0)