Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/attachments #24

Merged
merged 7 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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>
82 changes: 58 additions & 24 deletions lib/src/message_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ import 'stream_channel.dart';
/// The widget renders the ui based on the first ancestor of type [StreamChatTheme].
/// Modify it to change the widget appearance.
class MessageInput extends StatefulWidget {
MessageInput(
{Key key,
this.onMessageSent,
this.parentMessage,
this.editMessage,
this.maxHeight = 150})
: super(key: key);
MessageInput({
Key key,
this.onMessageSent,
this.parentMessage,
this.editMessage,
this.maxHeight = 150,
this.keyboardType = TextInputType.multiline,
this.disableAttachments = false,
}) : super(key: key);

/// Message to edit
final Message editMessage;
Expand All @@ -76,6 +78,12 @@ class MessageInput extends StatefulWidget {
/// Maximum Height for the TextField to grow before it starts scrolling
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
_MessageInputState createState() => _MessageInputState();
}
Expand All @@ -86,27 +94,35 @@ class _MessageInputState extends State<MessageInput> {
final List<User> _mentionedUsers = [];

TextEditingController _textController;
bool _inputEnabled = true;
bool _messageIsPresent = false;
bool _typingStarted = false;
OverlayEntry _commandsOverlay, _mentionsOverlay;

@override
Widget build(BuildContext context) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
_buildBorder(context),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildAttachments(),
_buildTextField(context),
],
),
],
child: GestureDetector(
onPanUpdate: (details) {
if (details.delta.dy > 0) {
_focusNode.unfocus();
}
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
_buildBorder(context),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildAttachments(),
_buildTextField(context),
],
),
],
),
),
),
);
Expand All @@ -117,7 +133,7 @@ class _MessageInputState extends State<MessageInput> {
direction: Axis.horizontal,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
_buildAttachmentButton(),
if (!widget.disableAttachments) _buildAttachmentButton(),
_buildTextInput(context),
_animateSendButton(context),
],
Expand All @@ -126,7 +142,8 @@ class _MessageInputState extends State<MessageInput> {

AnimatedCrossFade _animateSendButton(BuildContext context) {
return AnimatedCrossFade(
crossFadeState: (_messageIsPresent || _attachments.isNotEmpty)
crossFadeState: ((_messageIsPresent || _attachments.isNotEmpty) &&
_attachments.every((a) => a.uploaded == true))
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
firstChild: _buildSendButton(context),
Expand All @@ -142,11 +159,13 @@ class _MessageInputState extends State<MessageInput> {
maxHeight: widget.maxHeight,
child: TextField(
key: Key('messageInputText'),
enabled: _inputEnabled,
minLines: null,
maxLines: null,
onSubmitted: (_) {
_sendMessage(context);
},
keyboardType: widget.keyboardType,
controller: _textController,
focusNode: _focusNode,
onChanged: (s) {
Expand Down Expand Up @@ -506,6 +525,10 @@ class _MessageInputState extends State<MessageInput> {
}

void _showAttachmentModal() {
if (_focusNode.hasFocus) {
_focusNode.unfocus();
}

showModalBottomSheet(
clipBehavior: Clip.hardEdge,
shape: RoundedRectangleBorder(
Expand Down Expand Up @@ -548,7 +571,6 @@ class _MessageInputState extends State<MessageInput> {
leading: Icon(Icons.camera_alt),
title: Text('Photo from camera'),
onTap: () {
ImagePicker.pickImage(source: ImageSource.camera);
_pickFile(FileType.image, true);
Navigator.pop(context);
},
Expand All @@ -575,6 +597,10 @@ class _MessageInputState extends State<MessageInput> {
}

void _pickFile(FileType type, bool camera) async {
setState(() {
_inputEnabled = false;
});

File file;

if (camera) {
Expand All @@ -587,6 +613,14 @@ class _MessageInputState extends State<MessageInput> {
file = await FilePicker.getFile(type: type);
}

setState(() {
_inputEnabled = true;
});

if (file == null) {
return;
}

final channel = StreamChannel.of(context).channel;

final bytes = await file.readAsBytes();
Expand Down
83 changes: 49 additions & 34 deletions lib/src/message_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MessageWidget extends StatefulWidget {
this.isParent = false,
this.onMentionTap,
this.showOtherMessageUsername = false,
this.showVideoFullScreen = true,
}) : super(key: key);

/// Function called on mention tap
Expand All @@ -65,6 +66,9 @@ class MessageWidget extends StatefulWidget {
/// True if this is the parent of the thread being showed
final bool isParent;

/// True if the video player will allow fullscreen mode
final bool showVideoFullScreen;

@override
_MessageWidgetState createState() => _MessageWidgetState();
}
Expand Down Expand Up @@ -944,42 +948,53 @@ class _MessageWidgetState extends State<MessageWidget>
_videoControllers[attachment.assetUrl] = videoController;
}

ChewieController chewieController;
if (_chuwieControllers.containsKey(attachment.assetUrl)) {
chewieController = _chuwieControllers[attachment.assetUrl];
} else {
chewieController = ChewieController(
videoPlayerController: videoController,
autoInitialize: true,
errorBuilder: (_, e) {
return Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: CachedNetworkImageProvider(
attachment.thumbUrl,
return FutureBuilder<void>(
future: videoController.initialize(),
builder: (_, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return Center(
child: CircularProgressIndicator(),
);
}
ChewieController chewieController;
if (_chuwieControllers.containsKey(attachment.assetUrl)) {
chewieController = _chuwieControllers[attachment.assetUrl];
} else {
chewieController = ChewieController(
allowFullScreen: widget.showVideoFullScreen,
videoPlayerController: videoController,
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,
child: InkWell(
onTap: () => _launchURL(attachment.titleLink),
),
),
],
);
});
_chuwieControllers[attachment.assetUrl] = chewieController;
}

return Chewie(
key: ValueKey<String>(
'ATTACHMENT-${attachment.title}-${widget.message.id}'),
controller: chewieController,
Material(
color: Colors.transparent,
child: InkWell(
onTap: () => _launchURL(attachment.titleLink),
),
),
],
);
});
_chuwieControllers[attachment.assetUrl] = chewieController;
}
return Chewie(
key: ValueKey<String>(
'ATTACHMENT-${attachment.title}-${widget.message.id}'),
controller: chewieController,
);
},
);
}

Expand Down
2 changes: 0 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ dependencies:
flutter:
sdk: flutter
rxdart: ^0.23.1


jiffy: ^3.0.1
cached_network_image: ^2.0.0
flutter_markdown: ^0.3.4
Expand Down