From b20ba2e30629fcf10869dc3b14088d44153683b0 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 20 Apr 2020 09:43:54 +0200 Subject: [PATCH] update dependencies --- CHANGELOG.md | 2 +- lib/src/channel_image.dart | 29 ++++++++++++++++++++--------- lib/src/channel_name.dart | 16 +++++++++++++--- lib/src/message_input.dart | 28 ++++++++++++++-------------- lib/src/stream_chat.dart | 1 - lib/src/user_avatar.dart | 6 +++--- pubspec.yaml | 12 ++++++------ 7 files changed, 57 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b7ddcf..894a5de8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.2.0-alpha+6 +## 0.2.0-alpha+7 - Update llc dependency diff --git a/lib/src/channel_image.dart b/lib/src/channel_image.dart index 7c07bf3e..4f6c3bf9 100644 --- a/lib/src/channel_image.dart +++ b/lib/src/channel_image.dart @@ -38,7 +38,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart'; /// The widget uses a [StreamBuilder] to render the channel information image as soon as it updates. /// /// By default the widget radius size is 40x40 pixels. -/// Set the property [size] to set a custom dimension. +/// Set the property [constraints] to set a custom dimension. /// /// The widget renders the ui based on the first ancestor of type [StreamChatTheme]. /// Modify it to change the widget appearance. @@ -47,38 +47,49 @@ class ChannelImage extends StatelessWidget { const ChannelImage({ Key key, this.channel, - this.size = 40, + this.constraints, }) : super(key: key); /// The channel to show the image of final Channel channel; /// The diameter of the image - final double size; + final BoxConstraints constraints; @override Widget build(BuildContext context) { + final client = StreamChat.of(context); final channel = this.channel ?? StreamChannel.of(context).channel; return StreamBuilder>( stream: channel.extraDataStream, initialData: channel.extraData, builder: (context, snapshot) { + String image; + if (snapshot.data?.containsKey('image') == true) { + image = snapshot.data['image']; + } else if (channel.state.members.length == 2) { + final otherMember = channel.state.members + .firstWhere((member) => member.user.id != client.user.id); + image = otherMember.user.extraData['image']; + } + return ClipRRect( borderRadius: StreamChatTheme.of(context) .channelPreviewTheme .avatarTheme .borderRadius, child: Container( - constraints: StreamChatTheme.of(context) - .channelPreviewTheme - .avatarTheme - .constraints, + constraints: constraints ?? + StreamChatTheme.of(context) + .channelPreviewTheme + .avatarTheme + .constraints, decoration: BoxDecoration( color: StreamChatTheme.of(context).accentColor, ), - child: snapshot.data?.containsKey('image') ?? false + child: image != null ? CachedNetworkImage( - imageUrl: snapshot.data['image'], + imageUrl: image, errorWidget: (_, __, ___) { return Center( child: Text( diff --git a/lib/src/channel_name.dart b/lib/src/channel_name.dart index 45193001..ef7599b7 100644 --- a/lib/src/channel_name.dart +++ b/lib/src/channel_name.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:stream_chat/stream_chat.dart'; +import '../stream_chat_flutter.dart'; import 'stream_channel.dart'; /// It shows the current [Channel] name using a [Text] widget. @@ -22,15 +23,24 @@ class ChannelName extends StatelessWidget { @override Widget build(BuildContext context) { + final client = StreamChat.of(context); final channel = this.channel ?? StreamChannel.of(context).channel; return StreamBuilder>( stream: channel.extraDataStream, initialData: channel.extraData, builder: (context, snapshot) { + String title; + if (snapshot.data['name'] == null && + channel.state.members.length == 2) { + final otherMember = channel.state.members + .firstWhere((member) => member.user.id != client.user.id); + title = otherMember.user.name; + } else { + title = snapshot.data['name'] ?? channel.id; + } + return Text( - snapshot.data != null - ? (snapshot.data['name'] ?? channel.cid) - : channel.cid, + title, style: textStyle, ); }, diff --git a/lib/src/message_input.dart b/lib/src/message_input.dart index 7f76dbf1..d3d6482e 100644 --- a/lib/src/message_input.dart +++ b/lib/src/message_input.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io'; import 'package:file_picker/file_picker.dart'; @@ -765,7 +766,7 @@ class _MessageInputState extends State { }); } - int _keyboardListener; + StreamSubscription _keyboardListener; @override void initState() { @@ -773,16 +774,8 @@ class _MessageInputState extends State { StreamChannel.of(context).queryMembersAndWatchers(); - _keyboardListener = KeyboardVisibilityNotification().addNewListener( - onHide: () { - if (_commandsOverlay != null) { - _commandsOverlay.remove(); - } - if (_mentionsOverlay != null) { - _mentionsOverlay.remove(); - } - }, - onShow: () { + _keyboardListener = KeyboardVisibility.onChange.listen((visible) { + if (visible) { if (_commandsOverlay != null) { if (_textController.text.startsWith('/')) { WidgetsBinding.instance.addPostFrameCallback((_) { @@ -800,8 +793,15 @@ class _MessageInputState extends State { }); } } - }, - ); + } else { + if (_commandsOverlay != null) { + _commandsOverlay.remove(); + } + if (_mentionsOverlay != null) { + _mentionsOverlay.remove(); + } + } + }); if (widget.editMessage != null) { _textController = TextEditingController(text: widget.editMessage.text); @@ -842,7 +842,7 @@ class _MessageInputState extends State { void dispose() { _commandsOverlay?.remove(); _mentionsOverlay?.remove(); - KeyboardVisibilityNotification().removeListener(_keyboardListener); + _keyboardListener.cancel(); super.dispose(); } diff --git a/lib/src/stream_chat.dart b/lib/src/stream_chat.dart index b5db1f72..e2551dab 100644 --- a/lib/src/stream_chat.dart +++ b/lib/src/stream_chat.dart @@ -214,7 +214,6 @@ class StreamChatState extends State with WidgetsBindingObserver { createdAt: channel.createdAt, extraData: channel.extraData, type: channel.type, - members: channel.state.members, memberCount: channel.memberCount, frozen: channel.frozen, cid: channel.cid, diff --git a/lib/src/user_avatar.dart b/lib/src/user_avatar.dart index 478ae3b3..aaaa6a27 100644 --- a/lib/src/user_avatar.dart +++ b/lib/src/user_avatar.dart @@ -8,11 +8,11 @@ class UserAvatar extends StatelessWidget { const UserAvatar({ Key key, @required this.user, - this.radius = 16, + this.constraints, }) : super(key: key); final User user; - final double radius; + final BoxConstraints constraints; @override Widget build(BuildContext context) { @@ -20,7 +20,7 @@ class UserAvatar extends StatelessWidget { borderRadius: StreamChatTheme.of(context).ownMessageTheme.avatarTheme.borderRadius, child: Container( - constraints: + constraints: constraints ?? StreamChatTheme.of(context).ownMessageTheme.avatarTheme.constraints, decoration: BoxDecoration( color: StreamChatTheme.of(context).accentColor, diff --git a/pubspec.yaml b/pubspec.yaml index ead788f8..e53248ad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: stream_chat_flutter homepage: https://github.com/GetStream/stream-chat-flutter description: Stream Chat official Flutter SDK. Build your own chat experience using Dart and Flutter. -version: 0.2.0-alpha+6 +version: 0.2.0-alpha+7 environment: sdk: ">=2.3.0 <3.0.0" @@ -10,17 +10,17 @@ dependencies: flutter: sdk: flutter photo_view: ^0.9.2 + rxdart: ^0.24.0 jiffy: ^3.0.1 cached_network_image: ^2.1.0+1 - flutter_markdown: ^0.3.4 + flutter_markdown: ^0.3.5 url_launcher: ^5.4.2 video_player: ^0.10.8+1 chewie: ^0.9.10 - rxdart: ^0.23.0 - file_picker: ^1.6.2 + file_picker: ^1.6.3+2 image_picker: ^0.6.5 - flutter_keyboard_visibility: ^0.8.0 - stream_chat: ^0.2.0-alpha+4 + flutter_keyboard_visibility: ^2.0.0 + stream_chat: ^0.2.0-alpha+5 mime: ^0.9.6+3 visibility_detector: ^0.1.4 http_parser: ^3.1.4