fix messageinput
This commit is contained in:
+83
-66
@@ -6,8 +6,8 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:stream_chat_flutter/stream_chat_flutter.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';
|
import 'notifications_service.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
@@ -422,9 +422,12 @@ class _NewChatScreenState extends State<NewChatScreen> {
|
|||||||
|
|
||||||
bool _isSearchActive = false;
|
bool _isSearchActive = false;
|
||||||
|
|
||||||
|
Channel channel;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
channel = StreamChat.of(context).client.channel('messaging');
|
||||||
_controller = TextEditingController()
|
_controller = TextEditingController()
|
||||||
..addListener(() {
|
..addListener(() {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -452,74 +455,88 @@ class _NewChatScreenState extends State<NewChatScreen> {
|
|||||||
style: TextStyle(color: Colors.black),
|
style: TextStyle(color: Colors.black),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: UsersBloc(
|
body: StreamChannel(
|
||||||
child: Column(
|
showLoading: false,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
channel: channel,
|
||||||
children: [
|
child: UsersBloc(
|
||||||
ChipsInputTextField<User>(
|
child: Column(
|
||||||
key: _chipInputTextFieldStateKey,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
controller: _controller,
|
children: [
|
||||||
focusNode: FocusNode(),
|
ChipsInputTextField<User>(
|
||||||
chipBuilder: (context, user) {
|
key: _chipInputTextFieldStateKey,
|
||||||
return InputChip(
|
controller: _controller,
|
||||||
key: ObjectKey(user),
|
focusNode: FocusNode(),
|
||||||
label: Text(
|
chipBuilder: (context, user) {
|
||||||
user.name,
|
return InputChip(
|
||||||
style: TextStyle(color: Colors.black),
|
key: ObjectKey(user),
|
||||||
),
|
label: Text(
|
||||||
avatar: UserAvatar(
|
user.name,
|
||||||
user: user,
|
style: TextStyle(color: Colors.black),
|
||||||
),
|
),
|
||||||
onDeleted: () => _chipInputTextFieldState.removeItem(user),
|
avatar: UserAvatar(
|
||||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
user: user,
|
||||||
);
|
),
|
||||||
},
|
onDeleted: () => _chipInputTextFieldState.removeItem(user),
|
||||||
onChipAdded: (user) {
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
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();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
pagination: PaginationParams(
|
onChipAdded: (user) {
|
||||||
limit: 25,
|
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(
|
||||||
MessageInput(
|
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,6 +1,6 @@
|
|||||||
name: example
|
name: example
|
||||||
description: A new Flutter project.
|
description: A new Flutter project.
|
||||||
version: 1.0.59+61
|
version: 1.0.60+62
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.2.2 <3.0.0"
|
sdk: ">=2.2.2 <3.0.0"
|
||||||
|
|||||||
+10
-10
@@ -364,7 +364,10 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
controller: textEditingController,
|
controller: textEditingController,
|
||||||
focusNode: _focusNode,
|
focusNode: _focusNode,
|
||||||
onChanged: (s) {
|
onChanged: (s) {
|
||||||
StreamChannel.of(context).channel.keyStroke();
|
StreamChannel.of(context)
|
||||||
|
.channel
|
||||||
|
.keyStroke()
|
||||||
|
.catchError((e) {});
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_messageIsPresent = s.trim().isNotEmpty;
|
_messageIsPresent = s.trim().isNotEmpty;
|
||||||
@@ -479,7 +482,9 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
|
|
||||||
void _checkMentions(String s, BuildContext context) {
|
void _checkMentions(String s, BuildContext context) {
|
||||||
if (textEditingController.selection.isCollapsed &&
|
if (textEditingController.selection.isCollapsed &&
|
||||||
(s.isNotEmpty && s[textEditingController.selection.start - 1] == '@' ||
|
(s.isNotEmpty &&
|
||||||
|
textEditingController.selection.start > 0 &&
|
||||||
|
s[textEditingController.selection.start - 1] == '@' ||
|
||||||
textEditingController.text
|
textEditingController.text
|
||||||
.substring(0, textEditingController.selection.start)
|
.substring(0, textEditingController.selection.start)
|
||||||
.split(' ')
|
.split(' ')
|
||||||
@@ -1569,14 +1574,9 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: InkWell(
|
child: Icon(
|
||||||
onTap: () {
|
_getIdleSendIcon(),
|
||||||
sendMessage();
|
color: Colors.grey,
|
||||||
},
|
|
||||||
child: Icon(
|
|
||||||
_getIdleSendIcon(),
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ class StreamChannel extends StatefulWidget {
|
|||||||
Key key,
|
Key key,
|
||||||
@required this.child,
|
@required this.child,
|
||||||
@required this.channel,
|
@required this.channel,
|
||||||
|
this.showLoading = true,
|
||||||
}) : super(
|
}) : super(
|
||||||
key: key,
|
key: key,
|
||||||
);
|
);
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
final Channel channel;
|
final Channel channel;
|
||||||
|
final bool showLoading;
|
||||||
|
|
||||||
/// Use this method to get the current [StreamChannelState] instance
|
/// Use this method to get the current [StreamChannelState] instance
|
||||||
static StreamChannelState of(BuildContext context) {
|
static StreamChannelState of(BuildContext context) {
|
||||||
@@ -155,7 +157,7 @@ class StreamChannelState extends State<StreamChannel> {
|
|||||||
future: widget.channel.initialized,
|
future: widget.channel.initialized,
|
||||||
initialData: widget.channel.state != null,
|
initialData: widget.channel.state != null,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (!snapshot.hasData || !snapshot.data) {
|
if (widget.showLoading && (!snapshot.hasData || !snapshot.data)) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 30,
|
height: 30,
|
||||||
child: Center(
|
child: Center(
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ dependencies:
|
|||||||
file_picker: ^2.0.12
|
file_picker: ^2.0.12
|
||||||
image_picker: ^0.6.7+2
|
image_picker: ^0.6.7+2
|
||||||
flutter_keyboard_visibility: ^3.3.0
|
flutter_keyboard_visibility: ^3.3.0
|
||||||
stream_chat: ^0.2.13
|
stream_chat: ^0.2.13+1
|
||||||
mime: ^0.9.6+3
|
mime: ^0.9.6+3
|
||||||
visibility_detector: ^0.1.5
|
visibility_detector: ^0.1.5
|
||||||
http_parser: ^3.1.4
|
http_parser: ^3.1.4
|
||||||
|
|||||||
Reference in New Issue
Block a user