fix edit message

This commit is contained in:
Salvatore Giordano
2020-03-03 18:01:55 +01:00
parent f37b8d3cc4
commit c686540306
3 changed files with 226 additions and 168 deletions
+28
View File
@@ -1,10 +1,20 @@
PODS: PODS:
- file_picker (0.0.1):
- Flutter
- Flutter (1.0.0) - Flutter (1.0.0)
- flutter_plugin_android_lifecycle (0.0.1):
- Flutter
- FMDB (2.7.5): - FMDB (2.7.5):
- FMDB/standard (= 2.7.5) - FMDB/standard (= 2.7.5)
- FMDB/standard (2.7.5) - FMDB/standard (2.7.5)
- image_picker (0.0.1):
- Flutter
- keyboard_visibility (0.5.0):
- Flutter
- Reachability
- path_provider (0.0.1): - path_provider (0.0.1):
- Flutter - Flutter
- Reachability (3.2)
- screen (0.0.1): - screen (0.0.1):
- Flutter - Flutter
- sqflite (0.0.1): - sqflite (0.0.1):
@@ -22,7 +32,11 @@ PODS:
- Flutter - Flutter
DEPENDENCIES: DEPENDENCIES:
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- Flutter (from `Flutter`) - Flutter (from `Flutter`)
- flutter_plugin_android_lifecycle (from `.symlinks/plugins/flutter_plugin_android_lifecycle/ios`)
- image_picker (from `.symlinks/plugins/image_picker/ios`)
- keyboard_visibility (from `.symlinks/plugins/keyboard_visibility/ios`)
- path_provider (from `.symlinks/plugins/path_provider/ios`) - path_provider (from `.symlinks/plugins/path_provider/ios`)
- screen (from `.symlinks/plugins/screen/ios`) - screen (from `.symlinks/plugins/screen/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`) - sqflite (from `.symlinks/plugins/sqflite/ios`)
@@ -35,10 +49,19 @@ DEPENDENCIES:
SPEC REPOS: SPEC REPOS:
trunk: trunk:
- FMDB - FMDB
- Reachability
EXTERNAL SOURCES: EXTERNAL SOURCES:
file_picker:
:path: ".symlinks/plugins/file_picker/ios"
Flutter: Flutter:
:path: Flutter :path: Flutter
flutter_plugin_android_lifecycle:
:path: ".symlinks/plugins/flutter_plugin_android_lifecycle/ios"
image_picker:
:path: ".symlinks/plugins/image_picker/ios"
keyboard_visibility:
:path: ".symlinks/plugins/keyboard_visibility/ios"
path_provider: path_provider:
:path: ".symlinks/plugins/path_provider/ios" :path: ".symlinks/plugins/path_provider/ios"
screen: screen:
@@ -57,9 +80,14 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/video_player_web/ios" :path: ".symlinks/plugins/video_player_web/ios"
SPEC CHECKSUMS: SPEC CHECKSUMS:
file_picker: 408623be2125b79a4539cf703be3d4b3abe5e245
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
flutter_plugin_android_lifecycle: 47de533a02850f070f5696a623995e93eddcdb9b
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
image_picker: e3eacd46b94694dde7cf2705955cece853aa1a8f
keyboard_visibility: 96a24de806fe6823c3ad956c01ba2ec6d056616f
path_provider: fb74bd0465e96b594bb3b5088ee4a4e7bb1f2a9d path_provider: fb74bd0465e96b594bb3b5088ee4a4e7bb1f2a9d
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
screen: abd91ca7bf3426e1cc3646d27e9b2358d6bf07b0 screen: abd91ca7bf3426e1cc3646d27e9b2358d6bf07b0
sqflite: 4001a31ff81d210346b500c55b17f4d6c7589dd0 sqflite: 4001a31ff81d210346b500c55b17f4d6c7589dd0
url_launcher: a1c0cc845906122c4784c542523d8cacbded5626 url_launcher: a1c0cc845906122c4784c542523d8cacbded5626
+93 -67
View File
@@ -76,15 +76,12 @@ class MessageInput extends StatefulWidget {
} }
class _MessageInputState extends State<MessageInput> { class _MessageInputState extends State<MessageInput> {
final List<_SendingAttachment> _attachments = [];
final _focusNode = FocusNode();
TextEditingController _textController; TextEditingController _textController;
bool _messageIsPresent = false; bool _messageIsPresent = false;
bool _typingStarted = false; bool _typingStarted = false;
final List<_SendingAttachment> _attachments = [];
final _focusNode = FocusNode();
bool _modalOn = false;
OverlayEntry _commandsOverlay; OverlayEntry _commandsOverlay;
@override @override
@@ -95,43 +92,49 @@ class _MessageInputState extends State<MessageInput> {
child: Stack( child: Stack(
overflow: Overflow.visible, overflow: Overflow.visible,
children: <Widget>[ children: <Widget>[
Positioned.fill( _buildBorder(context),
child: Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
gradient: _getGradient(context),
),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
),
child: Container(
decoration: BoxDecoration(
color: StreamChatTheme.of(context)
.channelTheme
.inputBackground,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(
color: _typingStarted
? Colors.transparent
: Colors.black.withOpacity(.2)),
),
),
),
),
),
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
_buildAttachments(), _buildAttachments(),
Flex( _buildTextField(context),
],
),
],
),
),
);
}
Flex _buildTextField(BuildContext context) {
return Flex(
direction: Axis.horizontal, direction: Axis.horizontal,
children: <Widget>[ children: <Widget>[
_buildAttachmentButton(), _buildAttachmentButton(),
Expanded( _buildTextInput(context),
_animateSendButton(context),
],
);
}
AnimatedCrossFade _animateSendButton(BuildContext context) {
print(
'_messageIsPresent || _attachments.isNotEmpty: ${_messageIsPresent || _attachments.isNotEmpty}');
print('_attachments.isNotEmpty: ${_attachments.isNotEmpty}');
print('_messageIsPresent: ${_messageIsPresent}');
return AnimatedCrossFade(
crossFadeState: (_messageIsPresent || _attachments.isNotEmpty)
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
firstChild: _buildSendButton(context),
secondChild: SizedBox(),
duration: Duration(milliseconds: 300),
alignment: Alignment.center,
);
}
Expanded _buildTextInput(BuildContext context) {
return Expanded(
child: TextField( child: TextField(
minLines: null, minLines: null,
maxLines: null, maxLines: null,
@@ -142,21 +145,17 @@ class _MessageInputState extends State<MessageInput> {
focusNode: _focusNode, focusNode: _focusNode,
onChanged: (s) { onChanged: (s) {
StreamChannel.of(context).channel.keyStroke(); StreamChannel.of(context).channel.keyStroke();
setState(() { setState(() {
_messageIsPresent = s.trim().isNotEmpty; _messageIsPresent = s.trim().isNotEmpty;
}); });
if (s.startsWith('/')) {
_modalOn = true;
_commandsOverlay?.remove(); _commandsOverlay?.remove();
_commandsOverlay = null; _commandsOverlay = null;
if (s.startsWith('/')) {
_commandsOverlay = _buildOverlayEntry(); _commandsOverlay = _buildOverlayEntry();
Overlay.of(context).insert(_commandsOverlay); Overlay.of(context).insert(_commandsOverlay);
} else if (!s.startsWith('/') && _modalOn) {
_modalOn = false;
_commandsOverlay?.remove();
_commandsOverlay = null;
} }
}, },
onTap: () { onTap: () {
@@ -172,22 +171,33 @@ class _MessageInputState extends State<MessageInput> {
border: InputBorder.none, border: InputBorder.none,
), ),
), ),
);
}
Positioned _buildBorder(BuildContext context) {
return Positioned.fill(
child: Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
gradient: _getGradient(context),
), ),
AnimatedCrossFade( child: Container(
crossFadeState: decoration: BoxDecoration(
(_messageIsPresent || _attachments.isNotEmpty) color: Colors.white,
? CrossFadeState.showFirst borderRadius: BorderRadius.circular(10.0),
: CrossFadeState.showSecond,
firstChild: _buildSendButton(context),
secondChild: SizedBox(),
duration: Duration(milliseconds: 300),
alignment: Alignment.center,
), ),
], child: Container(
decoration: BoxDecoration(
color: StreamChatTheme.of(context).channelTheme.inputBackground,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(
color: _typingStarted
? Colors.transparent
: Colors.black.withOpacity(.2)),
), ),
],
), ),
],
), ),
), ),
); );
@@ -199,7 +209,7 @@ class _MessageInputState extends State<MessageInput> {
.channel .channel
.config .config
.commands .commands
.where((c) => c.name.startsWith(text.substring(1))) .where((c) => c.name.startsWith(text.replaceFirst('/', '')))
.toList(); .toList();
RenderBox renderBox = context.findRenderObject(); RenderBox renderBox = context.findRenderObject();
@@ -256,12 +266,11 @@ class _MessageInputState extends State<MessageInput> {
text: '/${c.name} ', text: '/${c.name} ',
selection: TextSelection.fromPosition( selection: TextSelection.fromPosition(
TextPosition( TextPosition(
offset: c.name.length + 1, offset: c.name.length + 2,
), ),
), ),
); );
}); });
_modalOn = false;
_commandsOverlay?.remove(); _commandsOverlay?.remove();
_commandsOverlay = null; _commandsOverlay = null;
} }
@@ -530,8 +539,6 @@ class _MessageInputState extends State<MessageInput> {
_typingStarted = false; _typingStarted = false;
}); });
_modalOn = false;
_commandsOverlay?.remove(); _commandsOverlay?.remove();
_commandsOverlay = null; _commandsOverlay = null;
@@ -541,7 +548,10 @@ class _MessageInputState extends State<MessageInput> {
final message = widget.editMessage.copyWith( final message = widget.editMessage.copyWith(
parentId: widget.parentMessage?.id, parentId: widget.parentMessage?.id,
text: text, text: text,
attachments: _getAttachments(attachments).toList(), attachments: widget.editMessage.attachments
.where((attachment) => attachment.type == 'giphy')
.toList() +
_getAttachments(attachments).toList(),
); );
StreamChat.of(context).client.updateMessage(message).then((_) { StreamChat.of(context).client.updateMessage(message).then((_) {
if (widget.onMessageSent != null) { if (widget.onMessageSent != null) {
@@ -589,17 +599,21 @@ class _MessageInputState extends State<MessageInput> {
void initState() { void initState() {
super.initState(); super.initState();
_keyboardListener = KeyboardVisibilityNotification().addNewListener( _keyboardListener =
onChange: (_) { KeyboardVisibilityNotification().addNewListener(onHide: () {
if (_modalOn) { if (_commandsOverlay != null) {
_commandsOverlay?.remove(); _commandsOverlay.remove();
}
}, onShow: () {
if (_commandsOverlay != null) {
if (_textController.text.startsWith('/')) {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
_commandsOverlay = _buildOverlayEntry(); _commandsOverlay = _buildOverlayEntry();
Overlay.of(context).insert(_commandsOverlay); Overlay.of(context).insert(_commandsOverlay);
}); });
} }
}, }
); });
if (widget.editMessage != null) { if (widget.editMessage != null) {
_textController = TextEditingController(text: widget.editMessage.text); _textController = TextEditingController(text: widget.editMessage.text);
@@ -614,6 +628,18 @@ class _MessageInputState extends State<MessageInput> {
url: attachment.imageUrl, url: attachment.imageUrl,
uploaded: true, uploaded: true,
)); ));
} else if (attachment.type == 'video') {
_attachments.add(_SendingAttachment(
type: FileType.VIDEO,
url: attachment.assetUrl,
uploaded: true,
));
} else if (attachment.type != 'giphy') {
_attachments.add(_SendingAttachment(
type: FileType.ANY,
url: attachment.assetUrl,
uploaded: true,
));
} }
}); });
} else { } else {
+7 -3
View File
@@ -574,7 +574,9 @@ class _MessageWidgetState extends State<MessageWidget>
), ),
), ),
builder: (context) { builder: (context) {
return Flex( return StreamChannel(
channel: streamChannel.channel,
child: Flex(
direction: Axis.vertical, direction: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@@ -633,8 +635,8 @@ class _MessageWidgetState extends State<MessageWidget>
.channel .channel
.state .state
.messages .messages
.firstWhere( .firstWhere((message) =>
(message) => message.id == widget.message.parentId) message.id == widget.message.parentId)
: null, : null,
onMessageSent: (_) { onMessageSent: (_) {
Navigator.pop(context); Navigator.pop(context);
@@ -642,6 +644,7 @@ class _MessageWidgetState extends State<MessageWidget>
), ),
), ),
], ],
),
); );
}, },
); );
@@ -719,6 +722,7 @@ class _MessageWidgetState extends State<MessageWidget>
imageUrl: imageUrl:
attachment.thumbUrl ?? attachment.imageUrl ?? attachment.assetUrl, attachment.thumbUrl ?? attachment.imageUrl ?? attachment.assetUrl,
fit: BoxFit.cover, fit: BoxFit.cover,
placeholderFadeInDuration: Duration(milliseconds: 300),
placeholder: (_, __) { placeholder: (_, __) {
return SizedBox( return SizedBox(
height: 200, height: 200,