Added a flag to control autocorrect in messageinput and a field to provide a custom scroll to bottom builder
This commit is contained in:
@@ -200,6 +200,7 @@ class MessageInput extends StatefulWidget {
|
|||||||
this.customOverlays = const [],
|
this.customOverlays = const [],
|
||||||
this.mentionAllAppUsers = false,
|
this.mentionAllAppUsers = false,
|
||||||
this.shouldKeepFocusAfterMessage,
|
this.shouldKeepFocusAfterMessage,
|
||||||
|
this.autocorrectEnabled,
|
||||||
}) : assert(
|
}) : assert(
|
||||||
initialMessage == null || editMessage == null,
|
initialMessage == null || editMessage == null,
|
||||||
"Can't provide both `initialMessage` and `editMessage`",
|
"Can't provide both `initialMessage` and `editMessage`",
|
||||||
@@ -322,6 +323,8 @@ class MessageInput extends StatefulWidget {
|
|||||||
/// The default behaviour keeps focus until a command is enabled.
|
/// The default behaviour keeps focus until a command is enabled.
|
||||||
final bool? shouldKeepFocusAfterMessage;
|
final bool? shouldKeepFocusAfterMessage;
|
||||||
|
|
||||||
|
final bool? autocorrectEnabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MessageInputState createState() => MessageInputState();
|
MessageInputState createState() => MessageInputState();
|
||||||
|
|
||||||
@@ -707,6 +710,7 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
textAlignVertical: TextAlignVertical.center,
|
textAlignVertical: TextAlignVertical.center,
|
||||||
decoration: _getInputDecoration(context),
|
decoration: _getInputDecoration(context),
|
||||||
textCapitalization: TextCapitalization.sentences,
|
textCapitalization: TextCapitalization.sentences,
|
||||||
|
autocorrect: widget.autocorrectEnabled ?? true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ class MessageListView extends StatefulWidget {
|
|||||||
const MessageListView({
|
const MessageListView({
|
||||||
Key? key,
|
Key? key,
|
||||||
this.showScrollToBottom = true,
|
this.showScrollToBottom = true,
|
||||||
|
this.scrollToBottomBuilder,
|
||||||
this.messageBuilder,
|
this.messageBuilder,
|
||||||
this.parentMessageBuilder,
|
this.parentMessageBuilder,
|
||||||
this.parentMessage,
|
this.parentMessage,
|
||||||
@@ -242,6 +243,11 @@ class MessageListView extends StatefulWidget {
|
|||||||
/// messages and the scroll offset is not zero
|
/// messages and the scroll offset is not zero
|
||||||
final bool showScrollToBottom;
|
final bool showScrollToBottom;
|
||||||
|
|
||||||
|
final Widget Function(
|
||||||
|
int unreadCount,
|
||||||
|
Future<void> Function(int) scrollToBottomDefaultTapAction,
|
||||||
|
)? scrollToBottomBuilder;
|
||||||
|
|
||||||
/// Parent message in case of a thread
|
/// Parent message in case of a thread
|
||||||
final Message? parentMessage;
|
final Message? parentMessage;
|
||||||
|
|
||||||
@@ -846,6 +852,29 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
.index;
|
.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> scrollToBottomDefaultTapAction(int unreadCount) async {
|
||||||
|
if (unreadCount > 0) {
|
||||||
|
streamChannel!.channel.markRead();
|
||||||
|
}
|
||||||
|
if (!_upToDate) {
|
||||||
|
_bottomPaginationActive = false;
|
||||||
|
initialAlignment = 0;
|
||||||
|
initialIndex = 0;
|
||||||
|
await streamChannel!.reloadChannel();
|
||||||
|
|
||||||
|
WidgetsBinding.instance?.addPostFrameCallback((_) {
|
||||||
|
_scrollController!.jumpTo(index: 0);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
_showScrollToBottom.value = false;
|
||||||
|
_scrollController!.scrollTo(
|
||||||
|
index: 0,
|
||||||
|
duration: const Duration(seconds: 1),
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildScrollToBottom() => StreamBuilder<int>(
|
Widget _buildScrollToBottom() => StreamBuilder<int>(
|
||||||
stream: streamChannel!.channel.state!.unreadCountStream,
|
stream: streamChannel!.channel.state!.unreadCountStream,
|
||||||
builder: (_, snapshot) {
|
builder: (_, snapshot) {
|
||||||
@@ -855,6 +884,12 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
return const Offstage();
|
return const Offstage();
|
||||||
}
|
}
|
||||||
final unreadCount = snapshot.data!;
|
final unreadCount = snapshot.data!;
|
||||||
|
if (widget.scrollToBottomBuilder != null) {
|
||||||
|
return widget.scrollToBottomBuilder!(
|
||||||
|
unreadCount,
|
||||||
|
scrollToBottomDefaultTapAction,
|
||||||
|
);
|
||||||
|
}
|
||||||
final showUnreadCount = unreadCount > 0 &&
|
final showUnreadCount = unreadCount > 0 &&
|
||||||
streamChannel!.channel.state!.members.any((e) =>
|
streamChannel!.channel.state!.members.any((e) =>
|
||||||
e.userId ==
|
e.userId ==
|
||||||
@@ -869,28 +904,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
children: [
|
children: [
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
backgroundColor: _streamTheme.colorTheme.barsBg,
|
backgroundColor: _streamTheme.colorTheme.barsBg,
|
||||||
onPressed: () async {
|
onPressed: () => scrollToBottomDefaultTapAction(unreadCount),
|
||||||
if (unreadCount > 0) {
|
|
||||||
streamChannel!.channel.markRead();
|
|
||||||
}
|
|
||||||
if (!_upToDate) {
|
|
||||||
_bottomPaginationActive = false;
|
|
||||||
initialAlignment = 0;
|
|
||||||
initialIndex = 0;
|
|
||||||
await streamChannel!.reloadChannel();
|
|
||||||
|
|
||||||
WidgetsBinding.instance?.addPostFrameCallback((_) {
|
|
||||||
_scrollController!.jumpTo(index: 0);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
_showScrollToBottom.value = false;
|
|
||||||
_scrollController!.scrollTo(
|
|
||||||
index: 0,
|
|
||||||
duration: const Duration(seconds: 1),
|
|
||||||
curve: Curves.easeInOut,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: widget.reverse
|
child: widget.reverse
|
||||||
? StreamSvgIcon.down(
|
? StreamSvgIcon.down(
|
||||||
color: _streamTheme.colorTheme.textHighEmphasis,
|
color: _streamTheme.colorTheme.textHighEmphasis,
|
||||||
|
|||||||
Reference in New Issue
Block a user