migrate app

This commit is contained in:
Salvatore Giordano
2021-05-17 15:58:10 +02:00
parent 273b24bcd8
commit 33622093e0
14 changed files with 93 additions and 82 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart' show Channel;
import 'package:imessage/utils.dart'; import 'package:imessage/utils.dart';
class ChannelImage extends StatelessWidget { class ChannelImage extends StatelessWidget {
const ChannelImage({Key key, @required this.channel, @required this.size}) const ChannelImage({Key? key, required this.channel, required this.size})
: super(key: key); : super(key: key);
final Channel channel; final Channel channel;
@@ -14,7 +14,7 @@ class ChannelImage extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final avatarUrl = channel.extraData.containsKey('image') && final avatarUrl = channel.extraData.containsKey('image') &&
(channel.extraData['image'] as String).isNotEmpty (channel.extraData['image'] as String).isNotEmpty
? channel.extraData['image'] as String ? channel.extraData['image'] as String?
: 'https://4.bp.blogspot.com/-Jx21kNqFSTU/UXemtqPhZCI/AAAAAAAAh74/BMGSzpU6F48/s1600/funny-cat-pictures-047-001.jpg'; : 'https://4.bp.blogspot.com/-Jx21kNqFSTU/UXemtqPhZCI/AAAAAAAAh74/BMGSzpU6F48/s1600/funny-cat-pictures-047-001.jpg';
return CupertinoCircleAvatar( return CupertinoCircleAvatar(
+2 -2
View File
@@ -6,7 +6,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart'
show Channel, StreamChannel; show Channel, StreamChannel;
class ChannelListView extends StatelessWidget { class ChannelListView extends StatelessWidget {
const ChannelListView({Key key, @required this.channels}) : super(key: key); const ChannelListView({Key? key, required this.channels}) : super(key: key);
final List<Channel> channels; final List<Channel> channels;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -36,10 +36,10 @@ class ChannelListView extends StatelessWidget {
child, child,
) => ) =>
SharedAxisTransition( SharedAxisTransition(
child: child,
animation: animation, animation: animation,
secondaryAnimation: secondaryAnimation, secondaryAnimation: secondaryAnimation,
transitionType: SharedAxisTransitionType.horizontal, transitionType: SharedAxisTransitionType.horizontal,
child: child,
), ),
), ),
); );
+3 -3
View File
@@ -3,8 +3,8 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart' show Channel;
class ChannelNameText extends StatelessWidget { class ChannelNameText extends StatelessWidget {
const ChannelNameText({ const ChannelNameText({
Key key, Key? key,
@required this.channel, required this.channel,
this.size = 17, this.size = 17,
}) : super(key: key); }) : super(key: key);
@@ -14,7 +14,7 @@ class ChannelNameText extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Text( return Text(
channel.extraData['name'] as String ?? 'No name', channel.extraData['name'] as String? ?? 'No name',
style: TextStyle( style: TextStyle(
fontSize: size, fontSize: size,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart';
class ChannelPageAppBar extends StatelessWidget { class ChannelPageAppBar extends StatelessWidget {
const ChannelPageAppBar({ const ChannelPageAppBar({
Key key, Key? key,
}) : super(key: key); }) : super(key: key);
@override @override
+12 -11
View File
@@ -11,19 +11,20 @@ class ChannelPreview extends StatelessWidget {
final Channel channel; final Channel channel;
const ChannelPreview({ const ChannelPreview({
Key key, Key? key,
@required this.onTap, required this.onTap,
@required this.channel, required this.channel,
}) : super(key: key); }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final lastMessage = final lastMessage = channel.state!.messages.isNotEmpty
channel.state.messages.isNotEmpty ? channel.state.messages.last : null; ? channel.state!.messages.last
: null;
final prefix = lastMessage?.attachments != null final prefix = lastMessage?.attachments != null
? lastMessage?.attachments //TODO: ugly ? lastMessage?.attachments //TODO: ugly
?.map((e) { .map((e) {
if (e.type == 'image') { if (e.type == 'image') {
return '📷 '; return '📷 ';
} else if (e.type == 'video') { } else if (e.type == 'video') {
@@ -31,8 +32,8 @@ class ChannelPreview extends StatelessWidget {
} }
return null; return null;
}) })
?.where((e) => e != null) .where((e) => e != null)
?.join(' ') .join(' ')
: ''; : '';
return GestureDetector( return GestureDetector(
onTap: onTap, onTap: onTap,
@@ -76,9 +77,9 @@ class ChannelPreview extends StatelessWidget {
child: Row( child: Row(
children: [ children: [
Text( Text(
isSameWeek(channel.lastMessageAt) isSameWeek(channel.lastMessageAt!)
? formatDateSameWeek(channel.lastMessageAt) ? formatDateSameWeek(channel.lastMessageAt!)
: formatDate(channel.lastMessageAt), : formatDate(channel.lastMessageAt!),
style: TextStyle( style: TextStyle(
fontSize: 15, fontSize: 15,
color: CupertinoColors.systemGrey, color: CupertinoColors.systemGrey,
+2 -2
View File
@@ -2,10 +2,10 @@ import 'package:flutter/cupertino.dart';
class ChatBubble extends CustomPainter { class ChatBubble extends CustomPainter {
final Color color; final Color color;
final Alignment alignment; final Alignment? alignment;
ChatBubble({ ChatBubble({
@required this.color, required this.color,
this.alignment, this.alignment,
}); });
+5 -5
View File
@@ -26,7 +26,7 @@ Future<void> main() async {
class IMessage extends StatelessWidget { class IMessage extends StatelessWidget {
final StreamChatClient client; final StreamChatClient client;
IMessage({@required this.client}); IMessage({required this.client});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
initializeDateFormatting('en_US', null); initializeDateFormatting('en_US', null);
@@ -41,14 +41,14 @@ class IMessage extends StatelessWidget {
class ChatLoader extends StatelessWidget { class ChatLoader extends StatelessWidget {
ChatLoader({ ChatLoader({
Key key, Key? key,
}) : super(key: key); }) : super(key: key);
final channelListController = ChannelListController(); final channelListController = ChannelListController();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final user = StreamChatCore.of(context).user; final user = StreamChatCore.of(context).user!;
return CupertinoPageScaffold( return CupertinoPageScaffold(
child: ChannelsBloc( child: ChannelsBloc(
child: ChannelListCore( child: ChannelListCore(
@@ -87,12 +87,12 @@ class ChatLoader extends StatelessWidget {
) => ) =>
LazyLoadScrollView( LazyLoadScrollView(
onEndOfPage: () async { onEndOfPage: () async {
return channelListController.paginateData(); return channelListController.paginateData!();
}, },
child: CustomScrollView( child: CustomScrollView(
slivers: [ slivers: [
CupertinoSliverRefreshControl(onRefresh: () async { CupertinoSliverRefreshControl(onRefresh: () async {
return channelListController.loadData(); return channelListController.loadData!();
}), }),
ChannelPageAppBar(), ChannelPageAppBar(),
SliverPadding( SliverPadding(
+1 -1
View File
@@ -4,7 +4,7 @@ import 'package:imessage/utils.dart';
class MessageHeader extends StatelessWidget { class MessageHeader extends StatelessWidget {
final String rawTimeStamp; final String rawTimeStamp;
const MessageHeader({Key key, @required this.rawTimeStamp}) : super(key: key); const MessageHeader({Key? key, required this.rawTimeStamp}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
+24 -15
View File
@@ -3,11 +3,11 @@ import 'dart:io';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart' import 'package:stream_chat_flutter/stream_chat_flutter.dart'
show Attachment, AttachmentFile, Message, MultipartFile, StreamChannel; show Attachment, AttachmentFile, Message, StreamChannel;
class MessageInput extends StatefulWidget { class MessageInput extends StatefulWidget {
const MessageInput({ const MessageInput({
Key key, Key? key,
}) : super(key: key); }) : super(key: key);
@override @override
@@ -16,7 +16,6 @@ class MessageInput extends StatefulWidget {
class _MessageInputState extends State<MessageInput> { class _MessageInputState extends State<MessageInput> {
final textController = TextEditingController(); final textController = TextEditingController();
File _image;
final picker = ImagePicker(); final picker = ImagePicker();
@override @override
@@ -39,16 +38,25 @@ class _MessageInputState extends State<MessageInput> {
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
final pickedFile = final pickedFile =
await picker.getImage(source: ImageSource.gallery); await (picker.getImage(source: ImageSource.gallery));
if (pickedFile == null) {
return;
}
final bytes = await File(pickedFile.path).readAsBytes(); final bytes = await File(pickedFile.path).readAsBytes();
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
final message = final message = Message(
Message(text: textController.value.text, attachments: [ text: textController.value.text,
Attachment( attachments: [
type: 'image', Attachment(
file: AttachmentFile(bytes: bytes, path: pickedFile.path), type: 'image',
), file: AttachmentFile(
]); bytes: bytes,
path: pickedFile.path,
size: bytes.length,
),
),
],
);
await channel.sendMessage(message); await channel.sendMessage(message);
}, },
child: Padding( child: Padding(
@@ -68,10 +76,11 @@ class _MessageInputState extends State<MessageInput> {
}, },
placeholder: 'Text Message', placeholder: 'Text Message',
prefix: Padding( prefix: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Text( child: Text(
"") //trick to add padding around placeholder iMessage text '',
), ), //trick to add padding around placeholder iMessage text
),
suffix: GestureDetector( suffix: GestureDetector(
onTap: () async { onTap: () async {
if (textController.value.text.isNotEmpty) { if (textController.value.text.isNotEmpty) {
+5 -5
View File
@@ -7,12 +7,12 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart'
show Message, StreamChatCore; show Message, StreamChatCore;
class MessageListView extends StatelessWidget { class MessageListView extends StatelessWidget {
const MessageListView({Key key, this.messages}) : super(key: key); const MessageListView({Key? key, this.messages}) : super(key: key);
final List<Message> messages; final List<Message>? messages;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final entries = groupBy(messages, final entries = groupBy(messages!,
(Message message) => message.createdAt.toString().substring(0, 10)) (Message message) => message.createdAt.toString().substring(0, 10))
.entries .entries
.toList(); .toList();
@@ -64,8 +64,8 @@ class MessageListView extends StatelessWidget {
} }
bool isReceived(Message message, BuildContext context) { bool isReceived(Message message, BuildContext context) {
final currentUserId = StreamChatCore.of(context).user.id; final currentUserId = StreamChatCore.of(context).user!.id;
return message.user.id == currentUserId; return message.user!.id == currentUserId;
} }
bool isSameDay(Message message) => bool isSameDay(Message message) =>
+1 -1
View File
@@ -53,7 +53,7 @@ class MessagePage extends StatelessWidget {
}, },
messageListBuilder: (context, messages) => LazyLoadScrollView( messageListBuilder: (context, messages) => LazyLoadScrollView(
onStartOfPage: () async { onStartOfPage: () async {
messageListController.paginateData(); await messageListController.paginateData!();
}, },
child: MessageListView( child: MessageListView(
messages: messages, messages: messages,
+23 -24
View File
@@ -1,8 +1,7 @@
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:imessage/cutom_painter.dart'; import 'package:imessage/cutom_painter.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart' import 'package:stream_chat_flutter/stream_chat_flutter.dart' show Message;
show Message, AttachmentUploadStateBuilder;
class MessageWidget extends StatelessWidget { class MessageWidget extends StatelessWidget {
final Alignment alignment; final Alignment alignment;
@@ -11,16 +10,16 @@ class MessageWidget extends StatelessWidget {
final Color messageColor; final Color messageColor;
const MessageWidget( const MessageWidget(
{Key key, {Key? key,
@required this.alignment, required this.alignment,
@required this.message, required this.message,
@required this.color, required this.color,
@required this.messageColor}) required this.messageColor})
: super(key: key); : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (message.attachments?.isNotEmpty == true && if (message.attachments.isNotEmpty == true &&
message.attachments.first.type == 'image') { message.attachments.first.type == 'image') {
return MessageImage( return MessageImage(
color: color, message: message, messageColor: messageColor); color: color, message: message, messageColor: messageColor);
@@ -36,10 +35,10 @@ class MessageWidget extends StatelessWidget {
class MessageImage extends StatelessWidget { class MessageImage extends StatelessWidget {
const MessageImage({ const MessageImage({
Key key, Key? key,
@required this.color, required this.color,
@required this.message, required this.message,
@required this.messageColor, required this.messageColor,
}) : super(key: key); }) : super(key: key);
final Color color; final Color color;
@@ -61,23 +60,23 @@ class MessageImage extends StatelessWidget {
children: [ children: [
if (message.attachments.first.file != null) if (message.attachments.first.file != null)
Image.memory( Image.memory(
message.attachments.first.file.bytes, message.attachments.first.file!.bytes!,
fit: BoxFit.cover, fit: BoxFit.cover,
) )
else else
CachedNetworkImage( CachedNetworkImage(
imageUrl: message.attachments.first.thumbUrl ?? imageUrl: message.attachments.first.thumbUrl ??
message.attachments.first.imageUrl ?? message.attachments.first.imageUrl ??
message.attachments.first.assetUrl, message.attachments.first.assetUrl!,
), ),
if (message.attachments.first?.title != null) if (message.attachments.first.title != null)
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Text(message.attachments.first.title, child: Text(message.attachments.first.title!,
style: TextStyle(color: messageColor)), style: TextStyle(color: messageColor)),
), ),
message.attachments.first.pretext != null message.attachments.first.pretext != null
? Text(message.attachments.first.pretext) ? Text(message.attachments.first.pretext!)
: Container() : Container()
], ],
), ),
@@ -92,7 +91,7 @@ class MessageImage extends StatelessWidget {
child: Container( child: Container(
color: color, color: color,
child: CachedNetworkImage( child: CachedNetworkImage(
imageUrl: message.attachments.first.thumbUrl, imageUrl: message.attachments.first.thumbUrl!,
)), )),
); );
} }
@@ -101,11 +100,11 @@ class MessageImage extends StatelessWidget {
class MessageText extends StatelessWidget { class MessageText extends StatelessWidget {
const MessageText({ const MessageText({
Key key, Key? key,
@required this.alignment, required this.alignment,
@required this.color, required this.color,
@required this.message, required this.message,
@required this.messageColor, required this.messageColor,
}) : super(key: key); }) : super(key: key);
final Alignment alignment; final Alignment alignment;
@@ -133,7 +132,7 @@ class MessageText extends StatelessWidget {
child: Padding( child: Padding(
padding: const EdgeInsets.all(4.0), padding: const EdgeInsets.all(4.0),
child: Text( child: Text(
message.text, message.text!,
style: TextStyle(color: messageColor), style: TextStyle(color: messageColor),
), ),
), ),
+11 -9
View File
@@ -26,24 +26,26 @@ bool isSameWeek(DateTime timestamp) =>
DateTime.now().difference(timestamp).inDays < 7; DateTime.now().difference(timestamp).inDays < 7;
class CupertinoCircleAvatar extends StatelessWidget { class CupertinoCircleAvatar extends StatelessWidget {
final String url; final String? url;
final double size; final double? size;
const CupertinoCircleAvatar({Key key, this.url, this.size}) : super(key: key); const CupertinoCircleAvatar({Key? key, this.url, this.size})
: super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ClipRRect( return ClipRRect(
borderRadius: BorderRadius.circular(size / 2), borderRadius: BorderRadius.circular(size! / 2),
child: CachedNetworkImage( child: CachedNetworkImage(
imageUrl: url, imageUrl: url!,
height: size, height: size,
width: size, width: size,
fit: BoxFit.cover, fit: BoxFit.cover,
errorWidget: (context, url, error) { errorWidget: (context, url, error) {
//TODO: this crash the app when getting 404 and in debug mode, see :https://github.com/Baseflow/flutter_cached_network_image/issues/504 //TODO: this crash the app when getting 404 and in debug mode, see :https://github.com/Baseflow/flutter_cached_network_image/issues/504
return CachedNetworkImage( return CachedNetworkImage(
imageUrl: imageUrl:
"https://4.bp.blogspot.com/-Jx21kNqFSTU/UXemtqPhZCI/AAAAAAAAh74/BMGSzpU6F48/s1600/funny-cat-pictures-047-001.jpg"); 'https://4.bp.blogspot.com/-Jx21kNqFSTU/UXemtqPhZCI/AAAAAAAAh74/BMGSzpU6F48/s1600/funny-cat-pictures-047-001.jp',
);
}), }),
); );
} }
@@ -51,18 +53,18 @@ class CupertinoCircleAvatar extends StatelessWidget {
class Divider extends StatelessWidget { class Divider extends StatelessWidget {
const Divider({ const Divider({
Key key, Key? key,
}) : super(key: key); }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Expanded( return Expanded(
child: Align( child: Align(
alignment: Alignment.bottomCenter,
child: Container( child: Container(
height: 1, height: 1,
color: CupertinoColors.systemGrey5, color: CupertinoColors.systemGrey5,
), ),
alignment: Alignment.bottomCenter,
), ),
); );
} }
+1 -1
View File
@@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1 version: 1.0.0+1
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
flutter: flutter: