iMessage clone (#1)
* first draft : static views wip * refactor to ChatMessage and ChatMessageHeader * add pedantic * fix lints * remove hardcoded message * appBar title : iMessage * format date * cupertino style and model view * fix display of message based on isReceived or sent * SendMessageInput * refactor to MessagesPage * MissingPluginException * use builtins instead of custom stream builders * handle isReceived * delete channel header * fix layout issues in ChannelPreview * fix formatDate * sticky message input * usage of builtin MessageListCore * remove unused imports and a todo * rename channelsStates to channels * replace file imports /w package:imessage/filename * remove size required ChannelNameText * lint and format * sendMessage * transition animation * stream_chat_flutter_core instead * format Date differently if same week * add padding to bubble * remove iMessage text from header * reverse message order * if same day don't display date * padding chat bubble right * remove unused extension * constraint message width * group messages By dates * unused import * fix bug input + layout+ preview onTap * change updatedAt to createdAt * add filter on channel * handle refresh * handle pagination with core LazyLoadScrollView * preview simple medias * upload bug * fix attachment * visual changes to message input * remove size * clean up * wait 5 sec before displaying image(hack) Co-authored-by: Salvatore Giordano <[email protected]>
This commit is contained in:
co-authored by
Salvatore Giordano
parent
8af74183ad
commit
2c2787c419
@@ -0,0 +1,96 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart'
|
||||
show Attachment, AttachmentFile, Message, MultipartFile, StreamChannel;
|
||||
|
||||
class MessageInput extends StatefulWidget {
|
||||
const MessageInput({
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_MessageInputState createState() => _MessageInputState();
|
||||
}
|
||||
|
||||
class _MessageInputState extends State<MessageInput> {
|
||||
final textController = TextEditingController();
|
||||
File _image;
|
||||
final picker = ImagePicker();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Align(
|
||||
alignment: FractionalOffset.bottomCenter,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 32.0),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final pickedFile =
|
||||
await picker.getImage(source: ImageSource.gallery);
|
||||
final bytes = await File(pickedFile.path).readAsBytes();
|
||||
final channel = StreamChannel.of(context).channel;
|
||||
final message =
|
||||
Message(text: textController.value.text, attachments: [
|
||||
Attachment(
|
||||
type: 'image',
|
||||
file: AttachmentFile(bytes: bytes, path: pickedFile.path),
|
||||
),
|
||||
]);
|
||||
await channel.sendMessage(message);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
CupertinoIcons.camera_fill,
|
||||
color: CupertinoColors.systemGrey,
|
||||
size: 35,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: CupertinoTextField(
|
||||
controller: textController,
|
||||
onSubmitted: (input) async {
|
||||
await sendMessage(context, input);
|
||||
},
|
||||
placeholder: 'Text Message',
|
||||
prefix: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
"") //trick to add padding around placeholder iMessage text
|
||||
),
|
||||
suffix: GestureDetector(
|
||||
onTap: () async {
|
||||
if (textController.value.text.isNotEmpty) {
|
||||
await sendMessage(context, textController.value.text);
|
||||
textController.clear();
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(CupertinoIcons.arrow_up_circle_fill,
|
||||
color: CupertinoColors.activeGreen, size: 35),
|
||||
),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: CupertinoColors.systemGrey,
|
||||
),
|
||||
borderRadius: BorderRadius.all(Radius.circular(35))),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> sendMessage(BuildContext context, String input) async {
|
||||
final streamChannel = StreamChannel.of(context);
|
||||
await streamChannel.channel.sendMessage(Message(text: input));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user