fix messageinput

This commit is contained in:
Salvatore Giordano
2020-11-18 18:06:27 +01:00
parent 6411afdee0
commit 6c4bcd2073
5 changed files with 98 additions and 79 deletions
+83 -66
View File
@@ -6,8 +6,8 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'chips_input_text_field.dart';
import 'chips_input_text_field.dart';
import 'notifications_service.dart';
void main() async {
@@ -422,9 +422,12 @@ class _NewChatScreenState extends State<NewChatScreen> {
bool _isSearchActive = false;
Channel channel;
@override
void initState() {
super.initState();
channel = StreamChat.of(context).client.channel('messaging');
_controller = TextEditingController()
..addListener(() {
setState(() {
@@ -452,74 +455,88 @@ class _NewChatScreenState extends State<NewChatScreen> {
style: TextStyle(color: Colors.black),
),
),
body: UsersBloc(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ChipsInputTextField<User>(
key: _chipInputTextFieldStateKey,
controller: _controller,
focusNode: FocusNode(),
chipBuilder: (context, user) {
return InputChip(
key: ObjectKey(user),
label: Text(
user.name,
style: TextStyle(color: Colors.black),
),
avatar: UserAvatar(
user: user,
),
onDeleted: () => _chipInputTextFieldState.removeItem(user),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
);
},
onChipAdded: (user) {
setState(() => _selectedUsers.add(user));
},
onChipRemoved: (user) {
setState(() => _selectedUsers.remove(user));
},
),
Container(
width: double.maxFinite,
color: Colors.white54,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 8,
),
child: Text(
_isSearchActive
? "Matches for \"$_userNameQuery\""
: 'On the platform',
style: TextStyle(
fontWeight: FontWeight.w500,
),
),
),
),
Expanded(
child: UserListView(
filterByUserName: _userNameQuery,
selectedUsers: _selectedUsers,
groupAlphabetically: _isSearchActive ? false : true,
onUserTap: (user, _) {
if (!_selectedUsers.contains(user)) {
_controller.clear();
_chipInputTextFieldState
..addItem(user)
..pauseItemAddition();
}
body: StreamChannel(
showLoading: false,
channel: channel,
child: UsersBloc(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ChipsInputTextField<User>(
key: _chipInputTextFieldStateKey,
controller: _controller,
focusNode: FocusNode(),
chipBuilder: (context, user) {
return InputChip(
key: ObjectKey(user),
label: Text(
user.name,
style: TextStyle(color: Colors.black),
),
avatar: UserAvatar(
user: user,
),
onDeleted: () => _chipInputTextFieldState.removeItem(user),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
);
},
pagination: PaginationParams(
limit: 25,
onChipAdded: (user) {
setState(() => _selectedUsers.add(user));
},
onChipRemoved: (user) {
setState(() => _selectedUsers.remove(user));
},
),
Container(
width: double.maxFinite,
color: Colors.white54,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 8,
),
child: Text(
_isSearchActive
? "Matches for \"$_userNameQuery\""
: 'On the platform',
style: TextStyle(
fontWeight: FontWeight.w500,
),
),
),
),
),
MessageInput(
),
],
Expanded(
child: UserListView(
filterByUserName: _userNameQuery,
selectedUsers: _selectedUsers,
groupAlphabetically: _isSearchActive ? false : true,
onUserTap: (user, _) {
if (!_selectedUsers.contains(user)) {
_controller.clear();
_chipInputTextFieldState
..addItem(user)
..pauseItemAddition();
}
},
pagination: PaginationParams(
limit: 25,
),
),
),
MessageInput(
preMessageSending: (message) async {
channel.extraData = {
'members': [
..._selectedUsers.map((e) => e.id),
channel.client.state.user.id,
],
};
await channel.watch();
return message;
},
),
],
),
),
),
);
+1 -1
View File
@@ -1,6 +1,6 @@
name: example
description: A new Flutter project.
version: 1.0.59+61
version: 1.0.60+62
environment:
sdk: ">=2.2.2 <3.0.0"
+10 -10
View File
@@ -364,7 +364,10 @@ class MessageInputState extends State<MessageInput> {
controller: textEditingController,
focusNode: _focusNode,
onChanged: (s) {
StreamChannel.of(context).channel.keyStroke();
StreamChannel.of(context)
.channel
.keyStroke()
.catchError((e) {});
setState(() {
_messageIsPresent = s.trim().isNotEmpty;
@@ -479,7 +482,9 @@ class MessageInputState extends State<MessageInput> {
void _checkMentions(String s, BuildContext context) {
if (textEditingController.selection.isCollapsed &&
(s.isNotEmpty && s[textEditingController.selection.start - 1] == '@' ||
(s.isNotEmpty &&
textEditingController.selection.start > 0 &&
s[textEditingController.selection.start - 1] == '@' ||
textEditingController.text
.substring(0, textEditingController.selection.start)
.split(' ')
@@ -1569,14 +1574,9 @@ class MessageInputState extends State<MessageInput> {
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: InkWell(
onTap: () {
sendMessage();
},
child: Icon(
_getIdleSendIcon(),
color: Colors.grey,
),
child: Icon(
_getIdleSendIcon(),
color: Colors.grey,
)),
),
);
+3 -1
View File
@@ -12,12 +12,14 @@ class StreamChannel extends StatefulWidget {
Key key,
@required this.child,
@required this.channel,
this.showLoading = true,
}) : super(
key: key,
);
final Widget child;
final Channel channel;
final bool showLoading;
/// Use this method to get the current [StreamChannelState] instance
static StreamChannelState of(BuildContext context) {
@@ -155,7 +157,7 @@ class StreamChannelState extends State<StreamChannel> {
future: widget.channel.initialized,
initialData: widget.channel.state != null,
builder: (context, snapshot) {
if (!snapshot.hasData || !snapshot.data) {
if (widget.showLoading && (!snapshot.hasData || !snapshot.data)) {
return Container(
height: 30,
child: Center(
+1 -1
View File
@@ -27,7 +27,7 @@ dependencies:
file_picker: ^2.0.12
image_picker: ^0.6.7+2
flutter_keyboard_visibility: ^3.3.0
stream_chat: ^0.2.13
stream_chat: ^0.2.13+1
mime: ^0.9.6+3
visibility_detector: ^0.1.5
http_parser: ^3.1.4