Merge pull request #24 from GetStream/hotfix/attachments
Hotfix/attachments
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>IDEDidComputeMac32BitWarning</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
+58
-24
@@ -56,13 +56,15 @@ import 'stream_channel.dart';
|
|||||||
/// The widget renders the ui based on the first ancestor of type [StreamChatTheme].
|
/// The widget renders the ui based on the first ancestor of type [StreamChatTheme].
|
||||||
/// Modify it to change the widget appearance.
|
/// Modify it to change the widget appearance.
|
||||||
class MessageInput extends StatefulWidget {
|
class MessageInput extends StatefulWidget {
|
||||||
MessageInput(
|
MessageInput({
|
||||||
{Key key,
|
Key key,
|
||||||
this.onMessageSent,
|
this.onMessageSent,
|
||||||
this.parentMessage,
|
this.parentMessage,
|
||||||
this.editMessage,
|
this.editMessage,
|
||||||
this.maxHeight = 150})
|
this.maxHeight = 150,
|
||||||
: super(key: key);
|
this.keyboardType = TextInputType.multiline,
|
||||||
|
this.disableAttachments = false,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Message to edit
|
/// Message to edit
|
||||||
final Message editMessage;
|
final Message editMessage;
|
||||||
@@ -76,6 +78,12 @@ class MessageInput extends StatefulWidget {
|
|||||||
/// Maximum Height for the TextField to grow before it starts scrolling
|
/// Maximum Height for the TextField to grow before it starts scrolling
|
||||||
final double maxHeight;
|
final double maxHeight;
|
||||||
|
|
||||||
|
/// The keyboard type assigned to the TextField
|
||||||
|
final TextInputType keyboardType;
|
||||||
|
|
||||||
|
/// If true the attachments button will not be displayed
|
||||||
|
final bool disableAttachments;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageInputState createState() => _MessageInputState();
|
_MessageInputState createState() => _MessageInputState();
|
||||||
}
|
}
|
||||||
@@ -86,6 +94,7 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
final List<User> _mentionedUsers = [];
|
final List<User> _mentionedUsers = [];
|
||||||
|
|
||||||
TextEditingController _textController;
|
TextEditingController _textController;
|
||||||
|
bool _inputEnabled = true;
|
||||||
bool _messageIsPresent = false;
|
bool _messageIsPresent = false;
|
||||||
bool _typingStarted = false;
|
bool _typingStarted = false;
|
||||||
OverlayEntry _commandsOverlay, _mentionsOverlay;
|
OverlayEntry _commandsOverlay, _mentionsOverlay;
|
||||||
@@ -93,20 +102,27 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Padding(
|
child: GestureDetector(
|
||||||
padding: const EdgeInsets.all(8.0),
|
onPanUpdate: (details) {
|
||||||
child: Stack(
|
if (details.delta.dy > 0) {
|
||||||
overflow: Overflow.visible,
|
_focusNode.unfocus();
|
||||||
children: <Widget>[
|
}
|
||||||
_buildBorder(context),
|
},
|
||||||
Column(
|
child: Padding(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
padding: const EdgeInsets.all(8.0),
|
||||||
children: [
|
child: Stack(
|
||||||
_buildAttachments(),
|
overflow: Overflow.visible,
|
||||||
_buildTextField(context),
|
children: <Widget>[
|
||||||
],
|
_buildBorder(context),
|
||||||
),
|
Column(
|
||||||
],
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
_buildAttachments(),
|
||||||
|
_buildTextField(context),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -117,7 +133,7 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
direction: Axis.horizontal,
|
direction: Axis.horizontal,
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
_buildAttachmentButton(),
|
if (!widget.disableAttachments) _buildAttachmentButton(),
|
||||||
_buildTextInput(context),
|
_buildTextInput(context),
|
||||||
_animateSendButton(context),
|
_animateSendButton(context),
|
||||||
],
|
],
|
||||||
@@ -126,7 +142,8 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
|
|
||||||
AnimatedCrossFade _animateSendButton(BuildContext context) {
|
AnimatedCrossFade _animateSendButton(BuildContext context) {
|
||||||
return AnimatedCrossFade(
|
return AnimatedCrossFade(
|
||||||
crossFadeState: (_messageIsPresent || _attachments.isNotEmpty)
|
crossFadeState: ((_messageIsPresent || _attachments.isNotEmpty) &&
|
||||||
|
_attachments.every((a) => a.uploaded == true))
|
||||||
? CrossFadeState.showFirst
|
? CrossFadeState.showFirst
|
||||||
: CrossFadeState.showSecond,
|
: CrossFadeState.showSecond,
|
||||||
firstChild: _buildSendButton(context),
|
firstChild: _buildSendButton(context),
|
||||||
@@ -142,11 +159,13 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
maxHeight: widget.maxHeight,
|
maxHeight: widget.maxHeight,
|
||||||
child: TextField(
|
child: TextField(
|
||||||
key: Key('messageInputText'),
|
key: Key('messageInputText'),
|
||||||
|
enabled: _inputEnabled,
|
||||||
minLines: null,
|
minLines: null,
|
||||||
maxLines: null,
|
maxLines: null,
|
||||||
onSubmitted: (_) {
|
onSubmitted: (_) {
|
||||||
_sendMessage(context);
|
_sendMessage(context);
|
||||||
},
|
},
|
||||||
|
keyboardType: widget.keyboardType,
|
||||||
controller: _textController,
|
controller: _textController,
|
||||||
focusNode: _focusNode,
|
focusNode: _focusNode,
|
||||||
onChanged: (s) {
|
onChanged: (s) {
|
||||||
@@ -506,6 +525,10 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showAttachmentModal() {
|
void _showAttachmentModal() {
|
||||||
|
if (_focusNode.hasFocus) {
|
||||||
|
_focusNode.unfocus();
|
||||||
|
}
|
||||||
|
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
clipBehavior: Clip.hardEdge,
|
clipBehavior: Clip.hardEdge,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
@@ -548,7 +571,6 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
leading: Icon(Icons.camera_alt),
|
leading: Icon(Icons.camera_alt),
|
||||||
title: Text('Photo from camera'),
|
title: Text('Photo from camera'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
ImagePicker.pickImage(source: ImageSource.camera);
|
|
||||||
_pickFile(FileType.image, true);
|
_pickFile(FileType.image, true);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
@@ -575,6 +597,10 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _pickFile(FileType type, bool camera) async {
|
void _pickFile(FileType type, bool camera) async {
|
||||||
|
setState(() {
|
||||||
|
_inputEnabled = false;
|
||||||
|
});
|
||||||
|
|
||||||
File file;
|
File file;
|
||||||
|
|
||||||
if (camera) {
|
if (camera) {
|
||||||
@@ -587,6 +613,14 @@ class _MessageInputState extends State<MessageInput> {
|
|||||||
file = await FilePicker.getFile(type: type);
|
file = await FilePicker.getFile(type: type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_inputEnabled = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (file == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final channel = StreamChannel.of(context).channel;
|
final channel = StreamChannel.of(context).channel;
|
||||||
|
|
||||||
final bytes = await file.readAsBytes();
|
final bytes = await file.readAsBytes();
|
||||||
|
|||||||
+49
-34
@@ -39,6 +39,7 @@ class MessageWidget extends StatefulWidget {
|
|||||||
this.isParent = false,
|
this.isParent = false,
|
||||||
this.onMentionTap,
|
this.onMentionTap,
|
||||||
this.showOtherMessageUsername = false,
|
this.showOtherMessageUsername = false,
|
||||||
|
this.showVideoFullScreen = true,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function called on mention tap
|
/// Function called on mention tap
|
||||||
@@ -65,6 +66,9 @@ class MessageWidget extends StatefulWidget {
|
|||||||
/// True if this is the parent of the thread being showed
|
/// True if this is the parent of the thread being showed
|
||||||
final bool isParent;
|
final bool isParent;
|
||||||
|
|
||||||
|
/// True if the video player will allow fullscreen mode
|
||||||
|
final bool showVideoFullScreen;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageWidgetState createState() => _MessageWidgetState();
|
_MessageWidgetState createState() => _MessageWidgetState();
|
||||||
}
|
}
|
||||||
@@ -944,42 +948,53 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
_videoControllers[attachment.assetUrl] = videoController;
|
_videoControllers[attachment.assetUrl] = videoController;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChewieController chewieController;
|
return FutureBuilder<void>(
|
||||||
if (_chuwieControllers.containsKey(attachment.assetUrl)) {
|
future: videoController.initialize(),
|
||||||
chewieController = _chuwieControllers[attachment.assetUrl];
|
builder: (_, snapshot) {
|
||||||
} else {
|
if (snapshot.connectionState != ConnectionState.done) {
|
||||||
chewieController = ChewieController(
|
return Center(
|
||||||
videoPlayerController: videoController,
|
child: CircularProgressIndicator(),
|
||||||
autoInitialize: true,
|
);
|
||||||
errorBuilder: (_, e) {
|
}
|
||||||
return Stack(
|
ChewieController chewieController;
|
||||||
children: <Widget>[
|
if (_chuwieControllers.containsKey(attachment.assetUrl)) {
|
||||||
Container(
|
chewieController = _chuwieControllers[attachment.assetUrl];
|
||||||
decoration: BoxDecoration(
|
} else {
|
||||||
image: DecorationImage(
|
chewieController = ChewieController(
|
||||||
fit: BoxFit.cover,
|
allowFullScreen: widget.showVideoFullScreen,
|
||||||
image: CachedNetworkImageProvider(
|
videoPlayerController: videoController,
|
||||||
attachment.thumbUrl,
|
autoInitialize: false,
|
||||||
|
aspectRatio: videoController.value.aspectRatio,
|
||||||
|
errorBuilder: (_, e) {
|
||||||
|
return Stack(
|
||||||
|
children: <Widget>[
|
||||||
|
Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
image: DecorationImage(
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
image: CachedNetworkImageProvider(
|
||||||
|
attachment.thumbUrl,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
Material(
|
||||||
),
|
color: Colors.transparent,
|
||||||
Material(
|
child: InkWell(
|
||||||
color: Colors.transparent,
|
onTap: () => _launchURL(attachment.titleLink),
|
||||||
child: InkWell(
|
),
|
||||||
onTap: () => _launchURL(attachment.titleLink),
|
),
|
||||||
),
|
],
|
||||||
),
|
);
|
||||||
],
|
});
|
||||||
);
|
_chuwieControllers[attachment.assetUrl] = chewieController;
|
||||||
});
|
}
|
||||||
_chuwieControllers[attachment.assetUrl] = chewieController;
|
return Chewie(
|
||||||
}
|
key: ValueKey<String>(
|
||||||
|
'ATTACHMENT-${attachment.title}-${widget.message.id}'),
|
||||||
return Chewie(
|
controller: chewieController,
|
||||||
key: ValueKey<String>(
|
);
|
||||||
'ATTACHMENT-${attachment.title}-${widget.message.id}'),
|
},
|
||||||
controller: chewieController,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ dependencies:
|
|||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
rxdart: ^0.23.1
|
rxdart: ^0.23.1
|
||||||
|
|
||||||
|
|
||||||
jiffy: ^3.0.1
|
jiffy: ^3.0.1
|
||||||
cached_network_image: ^2.0.0
|
cached_network_image: ^2.0.0
|
||||||
flutter_markdown: ^0.3.4
|
flutter_markdown: ^0.3.4
|
||||||
|
|||||||
Reference in New Issue
Block a user