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,120 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart'
|
||||
show
|
||||
Channel,
|
||||
ChannelListController,
|
||||
ChannelListCore,
|
||||
ChannelsBloc,
|
||||
LazyLoadScrollView,
|
||||
Level,
|
||||
PaginationParams,
|
||||
SortOption,
|
||||
StreamChatClient,
|
||||
StreamChatCore,
|
||||
User;
|
||||
|
||||
import 'package:imessage/channel_list_view.dart';
|
||||
|
||||
import 'package:imessage/channel_page_appbar.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
final client = StreamChatClient('b67pax5b2wdq', logLevel: Level.INFO); //
|
||||
await client.connectUser(
|
||||
User(
|
||||
id: 'cool-shadow-7',
|
||||
extraData: {
|
||||
'image':
|
||||
'https://getstream.io/random_png/?id=cool-shadow-7&name=Cool+shadow',
|
||||
},
|
||||
),
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiY29vbC1zaGFkb3ctNyJ9.gkOlCRb1qgy4joHPaxFwPOdXcGvSPvp6QY0S4mpRkVo',
|
||||
);
|
||||
|
||||
runApp(IMessage(client: client));
|
||||
}
|
||||
|
||||
class IMessage extends StatelessWidget {
|
||||
final StreamChatClient client;
|
||||
IMessage({@required this.client});
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
initializeDateFormatting('en_US', null);
|
||||
return CupertinoApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: CupertinoThemeData(brightness: Brightness.light),
|
||||
home: StreamChatCore(client: client, child: ChatLoader()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChatLoader extends StatelessWidget {
|
||||
const ChatLoader({
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = StreamChatCore.of(context).user;
|
||||
var channelListController = ChannelListController();
|
||||
return CupertinoPageScaffold(
|
||||
child: ChannelsBloc(
|
||||
child: ChannelListCore(
|
||||
channelListController: channelListController,
|
||||
filter: {
|
||||
r'$and': [
|
||||
{
|
||||
'members': {
|
||||
r'$in': [user.id],
|
||||
}
|
||||
},
|
||||
{
|
||||
'type': {
|
||||
r'$eq': 'messaging',
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
sort: [SortOption('last_message_at')],
|
||||
pagination: PaginationParams(
|
||||
limit: 20,
|
||||
),
|
||||
emptyBuilder: (BuildContext context) {
|
||||
return Center(
|
||||
child: Text('Looks like you are not in any channels'),
|
||||
);
|
||||
},
|
||||
loadingBuilder: (BuildContext context) {
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
height: 100.0,
|
||||
width: 100.0,
|
||||
child: CupertinoActivityIndicator(),
|
||||
),
|
||||
);
|
||||
},
|
||||
errorBuilder: (BuildContext context, dynamic error) {
|
||||
return Center(
|
||||
child: Text(
|
||||
'Oh no, something went wrong. Please check your config.'),
|
||||
);
|
||||
},
|
||||
listBuilder: (
|
||||
BuildContext context,
|
||||
List<Channel> channels,
|
||||
) =>
|
||||
LazyLoadScrollView(
|
||||
onEndOfPage: () async {
|
||||
channelListController.paginateData();
|
||||
},
|
||||
child: CustomScrollView(slivers: [
|
||||
CupertinoSliverRefreshControl(onRefresh: () async {
|
||||
channelListController.loadData();
|
||||
}),
|
||||
ChannelPageAppBar(),
|
||||
ChannelListView(channels: channels)
|
||||
]),
|
||||
))));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user