Skip to content

Commit f412e36

Browse files
fix: 🐛 reply configuration not working with a custom text field.
1 parent 5385ee5 commit f412e36

File tree

3 files changed

+81
-138
lines changed

3 files changed

+81
-138
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Rendering issue in attached image preview when sending message on web.
55
* **Feat**: [420](https://github.com/SimformSolutionsPvtLtd/chatview/pull/420) Added support for
66
`playerMode` in `VoiceMessageConfiguration` with `single` and `multi`.
7+
* **Fix**: [428](https://github.com/SimformSolutionsPvtLtd/chatview/pull/428) Fixed reply
8+
configuration handling when using a custom text field.
79

810
## [3.0.0]
911

example/lib/widgets/custom_chat_bar.dart

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import 'dart:io';
22

3+
import 'package:audio_waveforms/audio_waveforms.dart';
34
import 'package:chatview/chatview.dart';
45
import 'package:flutter/foundation.dart';
56
import 'package:flutter/material.dart';
67
import 'package:flutter_svg/flutter_svg.dart';
7-
import 'package:audio_waveforms/audio_waveforms.dart';
88

99
import '../../values/colors.dart';
1010
import '../../values/icons.dart';
@@ -48,74 +48,14 @@ class _CustomChatBarState extends State<CustomChatBar> {
4848
if (_replyMessage != null) {
4949
_replyMessage = widget.replyMessage;
5050
}
51-
final repliedUser = _replyMessage?.replyTo.isNotEmpty ?? false
52-
? widget.chatController.getUserFromId(_replyMessage?.replyTo ?? '')
53-
: null;
54-
String replyTo =
55-
_replyMessage?.replyTo == widget.chatController.currentUser.id
56-
? PackageStrings.currentLocale.you
57-
: repliedUser?.name ?? '';
51+
5852
return Container(
5953
color: AppColors.uiTwoBackground,
6054
child: SafeArea(
6155
top: false,
6256
child: Column(
6357
mainAxisSize: MainAxisSize.min,
6458
children: [
65-
if (_replyMessage?.message.isNotEmpty ?? false)
66-
Container(
67-
padding: const EdgeInsets.fromLTRB(8, 8, 7.5, 7.5),
68-
decoration: const BoxDecoration(
69-
border: Border(
70-
left: BorderSide(
71-
color: AppColors.uiTwoReplyLineColor,
72-
width: 4,
73-
),
74-
),
75-
),
76-
child: Row(
77-
children: [
78-
Expanded(
79-
child: Column(
80-
crossAxisAlignment: CrossAxisAlignment.start,
81-
children: [
82-
Text(
83-
replyTo,
84-
style: const TextStyle(
85-
fontStyle: FontStyle.normal,
86-
fontWeight: FontWeight.w600,
87-
fontSize: 14,
88-
height: 1.3571428571,
89-
letterSpacing: -0.01,
90-
color: Color(0xFFD42A66),
91-
),
92-
),
93-
const SizedBox(height: 1.5),
94-
Text(
95-
_replyMessage?.message ?? '',
96-
style: const TextStyle(
97-
fontSize: 12,
98-
height: 1.33,
99-
color: Color(0xFF0A0A0A),
100-
),
101-
),
102-
],
103-
),
104-
),
105-
const SizedBox(width: 16),
106-
SizedBox.square(
107-
dimension: 32,
108-
child: IconButton(
109-
onPressed: () => ChatView.closeReplyMessageView(
110-
context,
111-
),
112-
padding: EdgeInsets.zero,
113-
icon: SvgPicture.asset(AppIcons.closeCircular),
114-
),
115-
),
116-
],
117-
),
118-
),
11959
Padding(
12060
padding: const EdgeInsets.fromLTRB(7, 5.5, 9, 5.5),
12161
child: ValueListenableBuilder(

lib/src/widgets/send_message_widget.dart

Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -95,83 +95,80 @@ class SendMessageWidgetState extends State<SendMessageWidget> {
9595
chatListConfig.scrollToBottomButtonConfig;
9696
return Align(
9797
alignment: Alignment.bottomCenter,
98-
child: isCustomTextField
99-
? Builder(
100-
// Assign the key only when using a custom text field to measure its height,
101-
// to preventing overlap with the message list.
102-
key: chatViewIW?.chatTextFieldViewKey,
103-
builder: (context) {
104-
WidgetsBinding.instance.addPostFrameCallback(
105-
(_) => context.calculateAndUpdateTextFieldHeight(),
106-
);
107-
return widget.sendMessageBuilder?.call(_replyMessage) ??
108-
const SizedBox.shrink();
109-
},
110-
)
111-
: SizedBox(
112-
width: MediaQuery.of(context).size.width,
113-
child: Stack(
98+
child: SizedBox(
99+
width: MediaQuery.of(context).size.width,
100+
child: Stack(
101+
children: [
102+
// This has been added to prevent messages from being
103+
// displayed below the text field
104+
// when the user scrolls the message list.
105+
Positioned(
106+
right: 0,
107+
left: 0,
108+
bottom: 0,
109+
child: Container(
110+
height: MediaQuery.of(context).size.height /
111+
((!kIsWeb && Platform.isIOS) ? 24 : 28),
112+
color: chatListConfig.chatBackgroundConfig.backgroundColor ??
113+
Colors.white,
114+
),
115+
),
116+
Positioned(
117+
right: 0,
118+
left: 0,
119+
bottom: 0,
120+
child: Column(
121+
mainAxisSize: MainAxisSize.min,
114122
children: [
115-
// This has been added to prevent messages from being
116-
// displayed below the text field
117-
// when the user scrolls the message list.
118-
Positioned(
119-
right: 0,
120-
left: 0,
121-
bottom: 0,
122-
child: Container(
123-
height: MediaQuery.of(context).size.height /
124-
((!kIsWeb && Platform.isIOS) ? 24 : 28),
125-
color:
126-
chatListConfig.chatBackgroundConfig.backgroundColor ??
127-
Colors.white,
123+
if (chatViewIW
124+
?.featureActiveConfig.enableScrollToBottomButton ??
125+
true)
126+
Align(
127+
alignment:
128+
scrollToBottomButtonConfig?.alignment?.alignment ??
129+
Alignment.bottomCenter,
130+
child: Padding(
131+
padding: scrollToBottomButtonConfig?.padding ??
132+
EdgeInsets.zero,
133+
child: const ScrollToBottomButton(),
134+
),
128135
),
129-
),
130-
Positioned(
131-
right: 0,
132-
left: 0,
133-
bottom: 0,
134-
child: Column(
135-
mainAxisSize: MainAxisSize.min,
136+
Padding(
137+
key: chatViewIW?.chatTextFieldViewKey,
138+
padding: EdgeInsets.fromLTRB(
139+
bottomPadding4,
140+
bottomPadding4,
141+
bottomPadding4,
142+
_bottomPadding,
143+
),
144+
child: Stack(
145+
alignment: Alignment.bottomCenter,
136146
children: [
137-
if (chatViewIW?.featureActiveConfig
138-
.enableScrollToBottomButton ??
139-
true)
140-
Align(
141-
alignment: scrollToBottomButtonConfig
142-
?.alignment?.alignment ??
143-
Alignment.bottomCenter,
144-
child: Padding(
145-
padding: scrollToBottomButtonConfig?.padding ??
146-
EdgeInsets.zero,
147-
child: const ScrollToBottomButton(),
148-
),
149-
),
150-
Padding(
151-
key: chatViewIW?.chatTextFieldViewKey,
152-
padding: EdgeInsets.fromLTRB(
153-
bottomPadding4,
154-
bottomPadding4,
155-
bottomPadding4,
156-
_bottomPadding,
147+
ReplyMessageView(
148+
key: _replyMessageTextFieldViewKey,
149+
sendMessageConfig: widget.sendMessageConfig,
150+
messageConfig: widget.messageConfig,
151+
builder: widget.replyMessageBuilder,
152+
onChange: (value) => _replyMessage = value,
153+
),
154+
if (widget.sendMessageConfig.shouldSendImageWithText)
155+
SelectedImageViewWidget(
156+
key: _selectedImageViewWidgetKey,
157+
sendMessageConfig: widget.sendMessageConfig,
157158
),
158-
child: Stack(
159-
alignment: Alignment.bottomCenter,
160-
children: [
161-
ReplyMessageView(
162-
key: _replyMessageTextFieldViewKey,
163-
sendMessageConfig: widget.sendMessageConfig,
164-
messageConfig: widget.messageConfig,
165-
builder: widget.replyMessageBuilder,
166-
onChange: (value) => _replyMessage = value,
167-
),
168-
if (widget
169-
.sendMessageConfig.shouldSendImageWithText)
170-
SelectedImageViewWidget(
171-
key: _selectedImageViewWidgetKey,
172-
sendMessageConfig: widget.sendMessageConfig,
173-
),
174-
ChatUITextField(
159+
isCustomTextField
160+
? Builder(
161+
builder: (context) {
162+
WidgetsBinding.instance.addPostFrameCallback(
163+
(_) => context
164+
.calculateAndUpdateTextFieldHeight(),
165+
);
166+
return widget.sendMessageBuilder
167+
?.call(_replyMessage) ??
168+
const SizedBox.shrink();
169+
},
170+
)
171+
: ChatUITextField(
175172
focusNode: _focusNode,
176173
textEditingController: _textEditingController,
177174
onPressed: _onPressed,
@@ -196,15 +193,15 @@ class SendMessageWidgetState extends State<SendMessageWidget> {
196193
}
197194
},
198195
),
199-
],
200-
),
201-
),
202196
],
203197
),
204198
),
205199
],
206200
),
207201
),
202+
],
203+
),
204+
),
208205
);
209206
}
210207

@@ -272,6 +269,10 @@ class SendMessageWidgetState extends State<SendMessageWidget> {
272269
_replyMessageTextFieldViewKey.currentState!.replyMessage.value =
273270
_replyMessage;
274271
}
272+
// Scroll to ensure the reply widget is visible and messages are not overlapped
273+
WidgetsBinding.instance.addPostFrameCallback((_) {
274+
chatViewIW?.chatController.scrollToLastMessage();
275+
});
275276
}
276277

277278
void onCloseTap() {

0 commit comments

Comments
 (0)