From 38300939d391bc55db0f524b2011dc84384cc593 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sun, 15 Mar 2020 11:43:52 +0100 Subject: [PATCH 1/3] fix #6: ChannelListView NULL error when a channel has no messages --- analysis_options.yaml | 122 ++++++++++++++++----------------- lib/src/channel_list_view.dart | 2 +- lib/src/channel_preview.dart | 3 + lib/src/message_widget.dart | 4 +- 4 files changed, 67 insertions(+), 64 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index acc17647..fedac90d 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,61 +1,61 @@ -#include: package:pedantic/analysis_options.yaml -# -#analyzer: -# exclude: -# - lib/**/*.g.dart -# - example/* -# -#linter: -# rules: -# # these rules are documented on and in the same order as -# # the Dart Lint rules page to make maintenance easier -# # https://github.com/dart-lang/linter/blob/master/example/all.yaml -# # - always_declare_return_types -# # - always_specify_types -# # - annotate_overrides -# # - avoid_as -# - avoid_empty_else -# - avoid_init_to_null -# - avoid_return_types_on_setters -# - avoid_web_libraries_in_flutter -# - await_only_futures -# - camel_case_types -# - cancel_subscriptions -# - close_sinks -# # - comment_references # we do not presume as to what people want to reference in their dartdocs -# # - constant_identifier_names # https://github.com/dart-lang/linter/issues/204 -# - control_flow_in_finally -# - empty_constructor_bodies -# - empty_statements -# - hash_and_equals -# - implementation_imports -# # - invariant_booleans -# # - iterable_contains_unrelated_type -# - library_names -# # - library_prefixes -# # - list_remove_unrelated_type -# # - literal_only_boolean_expressions -# - non_constant_identifier_names -# # - one_member_abstracts -# # - only_throw_errors -# # - overridden_fields -## - package_api_docs -# - package_names -# - package_prefixed_library_names -# - prefer_is_not_empty -# # - prefer_mixin # https://github.com/dart-lang/language/issues/32 -## - public_member_api_docs -# - slash_for_doc_comments -# # - sort_constructors_first -# # - sort_unnamed_constructors_first -# # - super_goes_last # no longer needed w/ Dart 2 -# - test_types_in_equals -# - throw_in_finally -# # - type_annotate_public_apis # subset of always_specify_types -# - type_init_formals -# # - unawaited_futures -# - unnecessary_brace_in_string_interps -# - unnecessary_getters_setters -# - unnecessary_statements -# - unrelated_type_equality_checks -# - valid_regexps +include: package:pedantic/analysis_options.yaml + +analyzer: + exclude: + - lib/**/*.g.dart + - example/* + +linter: + rules: + # these rules are documented on and in the same order as + # the Dart Lint rules page to make maintenance easier + # https://github.com/dart-lang/linter/blob/master/example/all.yaml + # - always_declare_return_types + # - always_specify_types + # - annotate_overrides + # - avoid_as + - avoid_empty_else + - avoid_init_to_null + - avoid_return_types_on_setters + - avoid_web_libraries_in_flutter + - await_only_futures + - camel_case_types + - cancel_subscriptions + - close_sinks + # - comment_references # we do not presume as to what people want to reference in their dartdocs + # - constant_identifier_names # https://github.com/dart-lang/linter/issues/204 + - control_flow_in_finally + - empty_constructor_bodies + - empty_statements + - hash_and_equals + - implementation_imports + # - invariant_booleans + # - iterable_contains_unrelated_type + - library_names + # - library_prefixes + # - list_remove_unrelated_type + # - literal_only_boolean_expressions + - non_constant_identifier_names + # - one_member_abstracts + # - only_throw_errors + # - overridden_fields +# - package_api_docs + - package_names + - package_prefixed_library_names + - prefer_is_not_empty + # - prefer_mixin # https://github.com/dart-lang/language/issues/32 +# - public_member_api_docs + - slash_for_doc_comments + # - sort_constructors_first + # - sort_unnamed_constructors_first + # - super_goes_last # no longer needed w/ Dart 2 + - test_types_in_equals + - throw_in_finally + # - type_annotate_public_apis # subset of always_specify_types + - type_init_formals + # - unawaited_futures + - unnecessary_brace_in_string_interps + - unnecessary_getters_setters + - unnecessary_statements + - unrelated_type_equality_checks + - valid_regexps diff --git a/lib/src/channel_list_view.dart b/lib/src/channel_list_view.dart index 329f27a5..e9114403 100644 --- a/lib/src/channel_list_view.dart +++ b/lib/src/channel_list_view.dart @@ -126,7 +126,7 @@ class _ChannelListViewState extends State { return widget.errorBuilder(snapshot.error); } - String message = snapshot.error.toString(); + var message = snapshot.error.toString(); if (snapshot.error is DioError) { final dioError = snapshot.error as DioError; if (dioError.type == DioErrorType.RESPONSE) { diff --git a/lib/src/channel_preview.dart b/lib/src/channel_preview.dart index 93b2d3ff..b6e3beba 100644 --- a/lib/src/channel_preview.dart +++ b/lib/src/channel_preview.dart @@ -68,6 +68,9 @@ class ChannelPreview extends StatelessWidget { stream: channel.lastMessageAtStream, initialData: channel.lastMessageAt, builder: (context, snapshot) { + if (!snapshot.hasData) { + return SizedBox(); + } final lastMessageAt = snapshot.data.toLocal(); String stringDate; diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index 1b9a688d..4067092a 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -93,7 +93,7 @@ class _MessageWidgetState extends State final alignment = _isMyMessage ? Alignment.centerRight : Alignment.centerLeft; - List row = [ + var row = [ Column( crossAxisAlignment: _isMyMessage ? CrossAxisAlignment.end : CrossAxisAlignment.start, @@ -302,7 +302,7 @@ class _MessageWidgetState extends State })); if (widget.message.text.trim().isNotEmpty) { - String text = widget.message.text; + var text = widget.message.text; text = _replaceMentions(text); column.addAll( From 4dc508e1c3ad54f6e01f2f988bd82cb18c4e4ba6 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sun, 15 Mar 2020 11:50:02 +0100 Subject: [PATCH 2/3] update dependencies --- lib/src/message_input.dart | 30 +++++++++++++++--------------- lib/src/message_list_view.dart | 2 +- pubspec.yaml | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/src/message_input.dart b/lib/src/message_input.dart index 0bb8cc31..98f5dcc7 100644 --- a/lib/src/message_input.dart +++ b/lib/src/message_input.dart @@ -449,7 +449,7 @@ class _MessageInputState extends State { Widget _buildAttachment(_SendingAttachment attachment) { switch (attachment.type) { - case FileType.IMAGE: + case FileType.image: return attachment.file != null ? Image.file( attachment.file, @@ -460,7 +460,7 @@ class _MessageInputState extends State { fit: BoxFit.cover, ); break; - case FileType.VIDEO: + case FileType.video: return Container( child: Icon(Icons.videocam), color: Colors.black26, @@ -519,7 +519,7 @@ class _MessageInputState extends State { leading: Icon(Icons.image), title: Text('Upload a photo'), onTap: () { - _pickFile(FileType.IMAGE, false); + _pickFile(FileType.image, false); Navigator.pop(context); }, ), @@ -527,7 +527,7 @@ class _MessageInputState extends State { leading: Icon(Icons.video_library), title: Text('Upload a video'), onTap: () { - _pickFile(FileType.VIDEO, false); + _pickFile(FileType.video, false); Navigator.pop(context); }, ), @@ -536,7 +536,7 @@ class _MessageInputState extends State { title: Text('Photo from camera'), onTap: () { ImagePicker.pickImage(source: ImageSource.camera); - _pickFile(FileType.IMAGE, true); + _pickFile(FileType.image, true); Navigator.pop(context); }, ), @@ -544,7 +544,7 @@ class _MessageInputState extends State { leading: Icon(Icons.videocam), title: Text('Video from camera'), onTap: () { - _pickFile(FileType.VIDEO, true); + _pickFile(FileType.video, true); Navigator.pop(context); }, ), @@ -552,7 +552,7 @@ class _MessageInputState extends State { leading: Icon(Icons.insert_drive_file), title: Text('Upload a file'), onTap: () { - _pickFile(FileType.ANY, false); + _pickFile(FileType.any, false); Navigator.pop(context); }, ), @@ -565,9 +565,9 @@ class _MessageInputState extends State { File file; if (camera) { - if (type == FileType.IMAGE) { + if (type == FileType.image) { file = await ImagePicker.pickImage(source: ImageSource.camera); - } else if (type == FileType.VIDEO) { + } else if (type == FileType.video) { file = await ImagePicker.pickVideo(source: ImageSource.camera); } } else { @@ -688,17 +688,17 @@ class _MessageInputState extends State { return attachments.map((attachment) { String type; switch (attachment.type) { - case FileType.IMAGE: + case FileType.image: type = 'image'; break; - case FileType.VIDEO: + case FileType.video: type = 'video'; break; default: type = 'file'; } return Attachment( - imageUrl: attachment.type == FileType.IMAGE ? attachment.url : null, + imageUrl: attachment.type == FileType.image ? attachment.url : null, assetUrl: attachment.url, type: type, ); @@ -752,19 +752,19 @@ class _MessageInputState extends State { widget.editMessage.attachments.forEach((attachment) { if (attachment.type == 'image') { _attachments.add(_SendingAttachment( - type: FileType.IMAGE, + type: FileType.image, url: attachment.imageUrl, uploaded: true, )); } else if (attachment.type == 'video') { _attachments.add(_SendingAttachment( - type: FileType.VIDEO, + type: FileType.video, url: attachment.assetUrl, uploaded: true, )); } else if (attachment.type != 'giphy') { _attachments.add(_SendingAttachment( - type: FileType.ANY, + type: FileType.any, url: attachment.assetUrl, uploaded: true, )); diff --git a/lib/src/message_list_view.dart b/lib/src/message_list_view.dart index 3d10388b..9d51458b 100644 --- a/lib/src/message_list_view.dart +++ b/lib/src/message_list_view.dart @@ -1,8 +1,8 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:flutter_widgets/flutter_widgets.dart'; import 'package:stream_chat/stream_chat.dart'; +import 'package:visibility_detector/visibility_detector.dart'; import '../stream_chat_flutter.dart'; import 'message_widget.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 725236c4..e771fb8b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,17 +10,17 @@ dependencies: flutter: sdk: flutter rxdart: ^0.23.1 - flutter_widgets: ^0.1.11 jiffy: ^3.0.1 cached_network_image: ^2.0.0 flutter_markdown: ^0.3.4 url_launcher: ^5.4.2 video_player: ^0.10.8+1 chewie: ^0.9.10 - file_picker: ^1.4.3+2 + file_picker: ^1.5.0 image_picker: ^0.6.3+4 keyboard_visibility: ^0.5.6 stream_chat: ^0.1.19 + visibility_detector: ^0.1.4 dev_dependencies: pedantic: ^1.9.0 From ecaed59a7d45e23de93e181bf10c966382afbe6a Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sun, 15 Mar 2020 11:52:03 +0100 Subject: [PATCH 3/3] version bump --- CHANGELOG.md | 4 ++++ README.md | 2 +- pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd82fe8c..c2355893 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.11 + +- Fix bug in ChannelPreview when list of messages is empty + ## 0.1.10 - Do not automatically dispose Client object when disposing StreamChat widget diff --git a/README.md b/README.md index 564fb165..195a3789 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ The example is available under the [example](https://github.com/GetStream/stream ```yaml dependencies: - stream_chat_flutter: ^0.1.10 + stream_chat_flutter: ^0.1.11 ``` You should then run `flutter packages get` diff --git a/pubspec.yaml b/pubspec.yaml index e771fb8b..de2db30a 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.1.10 +version: 0.1.11 environment: sdk: ">=2.3.0 <3.0.0"