Skip to content

Commit 85a9136

Browse files
feat: 🌟 less null in configs
1 parent 2369637 commit 85a9136

9 files changed

+402
-354
lines changed

example/lib/main.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@ class _ChatScreenState extends State<ChatScreen> {
142142
cameraIconColor: theme.cameraIconColor,
143143
galleryIconColor: theme.galleryIconColor,
144144
),
145-
replyMessageColor: theme.replyMessageColor,
146-
defaultSendButtonColor: theme.sendButtonColor,
147-
replyDialogColor: theme.replyDialogColor,
148-
replyTitleColor: theme.replyTitleColor,
149-
textFieldBackgroundColor: theme.textFieldBackgroundColor,
150-
closeIconColor: theme.closeIconColor,
151145
textFieldConfig: TextFieldConfiguration(
152146
onMessageTyping: (status) {
153147
/// Do with status

lib/src/models/message_configuration.dart

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,47 @@
2121
*/
2222
import 'package:chatview/src/models/models.dart';
2323
import 'package:chatview/src/models/voice_message_configuration.dart';
24+
import 'package:chatview/src/widgets/message_view.dart';
2425
import 'package:flutter/material.dart';
2526

2627
import '../values/typedefs.dart';
2728

2829
class MessageConfiguration {
29-
/// Provides configuration of image message appearance.
30-
final ImageMessageConfiguration? imageMessageConfig;
31-
32-
/// Provides configuration of image message appearance.
30+
/// Provides configuration of message reaction.
3331
final MessageReactionConfiguration? messageReactionConfig;
3432

3533
/// Provides configuration of emoji messages appearance.
3634
final EmojiMessageConfiguration? emojiMessageConfig;
3735

38-
/// Provides builder to create view for custom messages.
39-
final Widget Function(Message)? customMessageBuilder;
36+
/// Provides configuration of image message appearance.
37+
final ImageMessageConfiguration? imageMessageConfig;
4038

4139
/// Configurations for voice message bubble
4240
final VoiceMessageConfiguration? voiceMessageConfig;
4341

42+
/// Provides builder to create view for emoji messages.
43+
final Widget Function(MessageView)? emojiMessageBuilder;
44+
45+
/// Provides builder to create view for image messages.
46+
final Widget Function(MessageView)? imageMessageBuilder;
47+
48+
/// Provides builder to create view for text messages.
49+
final Widget Function(MessageView)? textMessageBuilder;
50+
51+
/// Provides builder to create view for voice messages.
52+
final Widget Function(MessageView)? voiceMessageBuilder;
53+
54+
/// Provides builder to create view for custom messages.
55+
final Widget Function(MessageView)? customMessageBuilder;
56+
4457
/// To customize reply view for custom message type
4558
final CustomMessageReplyViewBuilder? customMessageReplyViewBuilder;
4659

4760
const MessageConfiguration({
61+
this.imageMessageBuilder,
62+
this.textMessageBuilder,
63+
this.emojiMessageBuilder,
64+
this.voiceMessageBuilder,
4865
this.imageMessageConfig,
4966
this.messageReactionConfig,
5067
this.emojiMessageConfig,

lib/src/models/send_message_configuration.dart

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import '../values/typedefs.dart';
3030

3131
class SendMessageConfiguration {
3232
/// Used to give background color to text field.
33-
final Color? textFieldBackgroundColor;
33+
final Color textFieldBackgroundColor;
3434

3535
/// Used to give color to send button.
3636
final Color? defaultSendButtonColor;
@@ -39,16 +39,16 @@ class SendMessageConfiguration {
3939
final Widget? sendButtonIcon;
4040

4141
/// Used to give reply dialog color.
42-
final Color? replyDialogColor;
42+
final Color replyDialogColor;
4343

4444
/// Used to give color to title of reply pop-up.
45-
final Color? replyTitleColor;
45+
final Color replyTitleColor;
4646

4747
/// Used to give color to reply message.
48-
final Color? replyMessageColor;
48+
final Color replyMessageColor;
4949

5050
/// Used to give color to close icon in reply pop-up.
51-
final Color? closeIconColor;
51+
final Color closeIconColor;
5252

5353
/// Provides configuration of image picker functionality.
5454
final ImagePickerIconsConfiguration? imagePickerIconsConfig;
@@ -57,7 +57,7 @@ class SendMessageConfiguration {
5757
final ImagePickerConfiguration? imagePickerConfiguration;
5858

5959
/// Provides configuration of text field.
60-
final TextFieldConfiguration? textFieldConfig;
60+
final TextFieldConfiguration textFieldConfig;
6161

6262
/// Enable/disable voice recording. Enabled by default.
6363
final bool allowRecordingVoice;
@@ -77,20 +77,23 @@ class SendMessageConfiguration {
7777
/// Configuration for cancel voice recording
7878
final CancelRecordConfiguration? cancelRecordConfiguration;
7979

80+
bool get allowImageSending =>
81+
enableCameraImagePicker || enableGalleryImagePicker;
82+
8083
const SendMessageConfiguration({
81-
this.textFieldConfig,
82-
this.textFieldBackgroundColor,
84+
this.textFieldConfig = const TextFieldConfiguration(),
85+
this.textFieldBackgroundColor = Colors.white,
8386
this.imagePickerIconsConfig,
8487
this.imagePickerConfiguration,
8588
this.defaultSendButtonColor,
8689
this.sendButtonIcon,
87-
this.replyDialogColor,
88-
this.replyTitleColor,
89-
this.replyMessageColor,
90-
this.closeIconColor,
90+
this.replyDialogColor = const Color.fromRGBO(238, 238, 238, 1),
91+
this.replyTitleColor = Colors.deepPurple,
92+
this.replyMessageColor = Colors.black,
93+
this.closeIconColor = Colors.black,
9194
this.allowRecordingVoice = true,
92-
this.enableCameraImagePicker = true,
9395
this.enableGalleryImagePicker = true,
96+
this.enableCameraImagePicker = true,
9497
this.voiceRecordingConfiguration,
9598
this.micIconColor,
9699
this.cancelRecordConfiguration,
@@ -118,6 +121,32 @@ class ImagePickerIconsConfiguration {
118121
});
119122
}
120123

124+
class ImagePickerConfiguration {
125+
/// Used to give max width of image.
126+
final double? maxWidth;
127+
128+
/// Used to give max height of image.
129+
final double? maxHeight;
130+
131+
/// Used to give image quality.
132+
final int? imageQuality;
133+
134+
/// Preferred camera device to pick image from.
135+
final CameraDevice? preferredCameraDevice;
136+
137+
/// Callback when image is picked from camera or gallery,
138+
/// we can perform our task on image like adding crop options and return new image path
139+
final Future<String?> Function(String? path)? onImagePicked;
140+
141+
const ImagePickerConfiguration({
142+
this.maxWidth,
143+
this.maxHeight,
144+
this.imageQuality,
145+
this.preferredCameraDevice,
146+
this.onImagePicked,
147+
});
148+
}
149+
121150
class TextFieldConfiguration {
122151
/// Used to give max lines in text field.
123152
final int? maxLines;
@@ -140,6 +169,9 @@ class TextFieldConfiguration {
140169
/// Used to give text style of actual text in text field.
141170
final TextStyle? textStyle;
142171

172+
/// Used to give a border to the text field.
173+
final BoxBorder? border;
174+
143175
/// Used to give border radius in text field.
144176
final BorderRadius? borderRadius;
145177

@@ -171,6 +203,7 @@ class TextFieldConfiguration {
171203
const TextFieldConfiguration({
172204
this.contentPadding,
173205
this.maxLines,
206+
this.border,
174207
this.borderRadius,
175208
this.hintText,
176209
this.hintStyle,
@@ -187,32 +220,6 @@ class TextFieldConfiguration {
187220
});
188221
}
189222

190-
class ImagePickerConfiguration {
191-
/// Used to give max width of image.
192-
final double? maxWidth;
193-
194-
/// Used to give max height of image.
195-
final double? maxHeight;
196-
197-
/// Used to give image quality.
198-
final int? imageQuality;
199-
200-
/// Preferred camera device to pick image from.
201-
final CameraDevice? preferredCameraDevice;
202-
203-
/// Callback when image is picked from camera or gallery,
204-
/// we can perform our task on image like adding crop options and return new image path
205-
final Future<String?> Function(String? path)? onImagePicked;
206-
207-
const ImagePickerConfiguration({
208-
this.maxWidth,
209-
this.maxHeight,
210-
this.imageQuality,
211-
this.preferredCameraDevice,
212-
this.onImagePicked,
213-
});
214-
}
215-
216223
class VoiceRecordingConfiguration {
217224
/// Styling configuration for the recorder widget as well as
218225
/// configuring the audio recording quality.

lib/src/models/voice_message_configuration.dart

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ import 'package:flutter/material.dart';
44
/// A configuration model class for voice message bubble.
55
class VoiceMessageConfiguration {
66
const VoiceMessageConfiguration({
7-
this.playerWaveStyle,
7+
this.playerWaveStyle = const PlayerWaveStyle(scaleFactor: 70),
88
this.padding = const EdgeInsets.symmetric(horizontal: 8),
99
this.margin,
1010
this.decoration,
11-
this.animationCurve,
12-
this.animationDuration,
13-
this.pauseIcon,
11+
this.animationCurve = Curves.easeIn,
12+
this.animationDuration = const Duration(milliseconds: 500),
1413
this.playIcon,
14+
this.playIconColor,
15+
this.pauseIcon,
16+
this.pauseIconColor,
1517
this.waveformMargin,
16-
this.waveformPadding,
18+
this.waveformPadding = const EdgeInsets.only(right: 10),
1719
this.enableSeekGesture = true,
1820
});
1921

2022
/// Applies style to waveform.
21-
final PlayerWaveStyle? playerWaveStyle;
23+
final PlayerWaveStyle playerWaveStyle;
2224

2325
/// Applies padding to message bubble.
2426
final EdgeInsets padding;
@@ -27,7 +29,7 @@ class VoiceMessageConfiguration {
2729
final EdgeInsets? margin;
2830

2931
/// Applies padding to waveform.
30-
final EdgeInsets? waveformPadding;
32+
final EdgeInsets waveformPadding;
3133

3234
/// Applies padding to waveform.
3335
final EdgeInsets? waveformMargin;
@@ -36,17 +38,23 @@ class VoiceMessageConfiguration {
3638
final BoxDecoration? decoration;
3739

3840
/// Duration for grow animation for waveform. Default to 500 ms.
39-
final Duration? animationDuration;
41+
final Duration animationDuration;
4042

4143
/// Curve for for grow animation for waveform. Default to Curve.easeIn.
42-
final Curve? animationCurve;
44+
final Curve animationCurve;
4345

4446
/// Icon for playing the audio.
4547
final Icon? playIcon;
4648

49+
/// Color for the playIcon if it is not overridden
50+
final Color? playIconColor;
51+
4752
/// Icon for pausing audio
4853
final Icon? pauseIcon;
4954

55+
/// Color for the pauseIcon if it is not overridden
56+
final Color? pauseIconColor;
57+
5058
/// Enable/disable seeking with gestures. Enabled by default.
5159
final bool enableSeekGesture;
5260
}

lib/src/widgets/chat_view.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ChatView extends StatefulWidget {
4747
ChatBackgroundConfiguration? chatBackgroundConfig,
4848
this.typeIndicatorConfig,
4949
this.sendMessageBuilder,
50-
this.sendMessageConfig,
50+
this.sendMessageConfig = const SendMessageConfiguration(),
5151
this.onChatListTap,
5252
required this.chatViewState,
5353
ChatViewStateConfiguration? chatViewStateConfig,
@@ -113,7 +113,7 @@ class ChatView extends StatefulWidget {
113113
final ChatController chatController;
114114

115115
/// Provides configuration of default text field in chat.
116-
final SendMessageConfiguration? sendMessageConfig;
116+
final SendMessageConfiguration sendMessageConfig;
117117

118118
/// Provides current state of chat.
119119
final ChatViewState chatViewState;
@@ -263,6 +263,8 @@ class _ChatViewState extends State<ChatView>
263263
if (featureActiveConfig.enableTextField)
264264
SendMessageWidget(
265265
key: _sendMessageKey,
266+
enabled:
267+
chatViewState.hasMessages || chatViewState.noMessages,
266268
chatController: chatController,
267269
sendMessageBuilder: widget.sendMessageBuilder,
268270
sendMessageConfig: widget.sendMessageConfig,

0 commit comments

Comments
 (0)