From f859d970095cbef7d2aca75e71d67a0c76f31c0a Mon Sep 17 00:00:00 2001 From: Efthymis Sarmpanis Date: Mon, 4 Mar 2024 17:07:13 +0100 Subject: [PATCH] fix(repo): make stable version compatible with latest flutter versions --- README.md | 21 ++++- .../stream_chat_and_theming.mdx | 17 ++++ .../stream_channel_info_bottom_sheet.dart | 4 +- .../lib/src/stream_chat.dart | 74 +++++++++------- .../src/avatars/gradient_avatar_test.dart | 17 ++-- .../test/src/avatars/group_avatar_test.dart | 3 +- .../test/src/avatars/user_avatar_test.dart | 5 +- .../attachment_modal_sheet_test.dart | 4 +- .../edit_message_sheet_test.dart | 3 +- .../bottom_sheets/error_alert_sheet_test.dart | 3 +- .../test/src/channel/channel_header_test.dart | 3 +- .../download_menu_item_test.dart | 3 +- .../stream_chat_context_menu_item_test.dart | 3 +- .../src/dialogs/confirmation_dialog_test.dart | 4 +- .../dialogs/delete_message_dialog_test.dart | 4 +- .../test/src/dialogs/message_dialog_test.dart | 8 +- .../test/src/gallery/gallery_footer_test.dart | 3 +- .../test/src/gallery/gallery_header_test.dart | 3 +- .../indicators/sending_indicator_test.dart | 8 +- .../upload_progress_indicator_test.dart | 8 +- .../test/src/material_app_wrapper.dart | 28 ++++++ .../message_input/attachment_button_test.dart | 4 +- .../message_input/clear_input_item_test.dart | 4 +- .../message_input/command_button_test.dart | 4 +- .../message_input/countdown_button_test.dart | 4 +- .../src/message_input/dm_checkbox_test.dart | 8 +- .../message_widget/deleted_message_test.dart | 78 +++++++++------- .../src/message_widget/message_text_test.dart | 4 +- .../test/src/misc/reaction_bubble_test.dart | 88 +++++++++++-------- .../test/src/misc/system_message_test.dart | 46 +++++----- .../test/src/misc/thread_header_test.dart | 3 +- .../test/src/widget_tester_extension.dart | 19 ++++ .../test/basics_test.dart | 3 + 33 files changed, 329 insertions(+), 162 deletions(-) create mode 100644 packages/stream_chat_flutter/test/src/material_app_wrapper.dart create mode 100644 packages/stream_chat_flutter/test/src/widget_tester_extension.dart diff --git a/README.md b/README.md index 4cfaaa2b4..496cba777 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,26 @@ Stream allows developers to rapidly deploy scalable feeds and chat messaging wit **V4 Migration Guide** -For upgrading from V3 to V4, please refer to the [V4 Migration Guide](https://getstream.io/chat/docs/sdk/flutter/guides/migration_guide_4_0/) +> [!WARNING] +> Flutter `> = v3.16.x` uses material 3 by default which breaks the UI of some of the components. +> If you want to use these versions, you need to set the `useMaterial3` parameter to `false` +> in the `ThemeData`. +> +> eg. +> +> ```dart +> MaterialApp( +> theme: ThemeData( +> useMaterial3: false, +> ), +> ... +> ); +> ``` +> +> `StreamChat` widget overrides the `useMaterial3` parameter to `false` by default +> so if you are using `StreamChat` widget, you **don't** need to set it manually. + +For upgrading from V6 to V7, please refer to the [V4 Migration Guide](https://getstream.io/chat/docs/sdk/flutter/guides/migration_guide_7_0/) ## Sample apps and demos Our team maintains a dedicated repository for full fledged sample applications and demos. Consider checking out [GetStream/flutter-samples](https://github.com/GetStream/flutter-samples) to learn more or get started by looking at our latest [Stream Chat demo](https://github.com/GetStream/flutter-samples/tree/main/packages/stream_chat_v1). diff --git a/docusaurus/docs/Flutter/02-stream_chat_flutter/stream_chat_and_theming.mdx b/docusaurus/docs/Flutter/02-stream_chat_flutter/stream_chat_and_theming.mdx index ba2e54598..fc9a864a5 100644 --- a/docusaurus/docs/Flutter/02-stream_chat_flutter/stream_chat_and_theming.mdx +++ b/docusaurus/docs/Flutter/02-stream_chat_flutter/stream_chat_and_theming.mdx @@ -18,6 +18,23 @@ Similar to the `Theme` and `ThemeData` in Flutter, Stream Chat uses a top level If you'd like to customize the look and feel of Stream chat across your entire application, we recommend setting your theme at the top level. Conversely, users can customize specific screens or widgets by wrapping components in a `StreamChatTheme`. +### A note on Material 3 + +Material 3 is a new design system from Google that Flutter versions >= 3.16.0 are using by default. Stream Chat SDK is using Material 2 by default. If you are using an older version of Flutter, you should be fine, but if you are using a newer version of Flutter, you should know that all components that are lower than `StreamChat` widget will only use Material 2. + +If you are using Material 3 in your app, keep in mind that any widget under StreamChat will use Material 2 by default. You can change it by providing useMaterial3: true to StreamChat widget. + +```dart +StreamChat( + client: client, + useMaterial3: true, + child: child, +) +``` + +> [!WARNING] +> If you set `useMaterial3` to `true`, all components that are lower than `StreamChat` widget will use Material 3 which is **not supported** by our widgets yet. + ### A closer look at StreamChatThemeData Looking at the constructor for `StreamChatThemeData`, we can see the full list of properties and widgets available for customization. diff --git a/packages/stream_chat_flutter/lib/src/bottom_sheets/stream_channel_info_bottom_sheet.dart b/packages/stream_chat_flutter/lib/src/bottom_sheets/stream_channel_info_bottom_sheet.dart index ea25f7bcb..1aef00d15 100644 --- a/packages/stream_chat_flutter/lib/src/bottom_sheets/stream_channel_info_bottom_sheet.dart +++ b/packages/stream_chat_flutter/lib/src/bottom_sheets/stream_channel_info_bottom_sheet.dart @@ -321,7 +321,7 @@ Future showChannelInfoModalBottomSheet({ /// sheet. /// * [Scaffold.of], for information about how to obtain the [BuildContext]. /// * -PersistentBottomSheetController showChannelInfoBottomSheet({ +PersistentBottomSheetController showChannelInfoBottomSheet({ required BuildContext context, required Channel channel, Color? backgroundColor, @@ -336,7 +336,7 @@ PersistentBottomSheetController showChannelInfoBottomSheet({ VoidCallback? onDeleteConversationTap, VoidCallback? onCancelTap, }) => - showBottomSheet( + showBottomSheet( context: context, backgroundColor: backgroundColor, elevation: elevation, diff --git a/packages/stream_chat_flutter/lib/src/stream_chat.dart b/packages/stream_chat_flutter/lib/src/stream_chat.dart index 6b0d0e609..fc4cdad0e 100644 --- a/packages/stream_chat_flutter/lib/src/stream_chat.dart +++ b/packages/stream_chat_flutter/lib/src/stream_chat.dart @@ -39,6 +39,7 @@ class StreamChat extends StatefulWidget { this.onBackgroundEventReceived, this.backgroundKeepAlive = const Duration(minutes: 1), this.connectivityStream, + this.useMaterial3 = false, }); /// Client to do chat operations with @@ -67,6 +68,10 @@ class StreamChat extends StatefulWidget { @visibleForTesting final Stream? connectivityStream; + /// Whether to use material 3 or not (default is false) + /// See our [docs](https://getstream.io/chat/docs/sdk/flutter/stream_chat_flutter/stream_chat_and_theming) + final bool useMaterial3; + @override StreamChatState createState() => StreamChatState(); @@ -107,40 +112,45 @@ class StreamChatState extends State { @override Widget build(BuildContext context) { final theme = _getTheme(context, widget.streamChatThemeData); - return Portal( - child: StreamChatConfiguration( - data: streamChatConfigData, - child: StreamChatTheme( - data: theme, - child: Builder( - builder: (context) { - final materialTheme = Theme.of(context); - final streamTheme = StreamChatTheme.of(context); - return Theme( - data: materialTheme.copyWith( - primaryIconTheme: streamTheme.primaryIconTheme, - colorScheme: materialTheme.colorScheme.copyWith( - secondary: streamTheme.colorTheme.accentPrimary, + return Theme( + data: Theme.of(context).copyWith( + useMaterial3: widget.useMaterial3, + ), + child: Portal( + child: StreamChatConfiguration( + data: streamChatConfigData, + child: StreamChatTheme( + data: theme, + child: Builder( + builder: (context) { + final materialTheme = Theme.of(context); + final streamTheme = StreamChatTheme.of(context); + return Theme( + data: materialTheme.copyWith( + primaryIconTheme: streamTheme.primaryIconTheme, + colorScheme: materialTheme.colorScheme.copyWith( + secondary: streamTheme.colorTheme.accentPrimary, + ), ), - ), - child: StreamChatCore( - client: client, - onBackgroundEventReceived: widget.onBackgroundEventReceived, - backgroundKeepAlive: widget.backgroundKeepAlive, - connectivityStream: widget.connectivityStream, - child: Builder( - builder: (context) { - StreamChatClient.additionalHeaders = { - 'X-Stream-Client': - '${StreamChatClient.defaultUserAgent}-' - 'ui-${StreamChatClient.packageVersion}', - }; - return widget.child ?? const Offstage(); - }, + child: StreamChatCore( + client: client, + onBackgroundEventReceived: widget.onBackgroundEventReceived, + backgroundKeepAlive: widget.backgroundKeepAlive, + connectivityStream: widget.connectivityStream, + child: Builder( + builder: (context) { + StreamChatClient.additionalHeaders = { + 'X-Stream-Client': + '${StreamChatClient.defaultUserAgent}-' + 'ui-${StreamChatClient.packageVersion}', + }; + return widget.child ?? const Offstage(); + }, + ), ), - ), - ); - }, + ); + }, + ), ), ), ), diff --git a/packages/stream_chat_flutter/test/src/avatars/gradient_avatar_test.dart b/packages/stream_chat_flutter/test/src/avatars/gradient_avatar_test.dart index 04ae7e419..8c4e0cf6f 100644 --- a/packages/stream_chat_flutter/test/src/avatars/gradient_avatar_test.dart +++ b/packages/stream_chat_flutter/test/src/avatars/gradient_avatar_test.dart @@ -4,6 +4,7 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -42,8 +43,8 @@ void main() { 'golden test for the name "demo user"', (WidgetTester tester) async { await tester.pumpWidget( - const MaterialApp( - home: Scaffold( + MaterialAppWrapper( + home: const Scaffold( body: Center( child: SizedBox( width: 100, @@ -64,8 +65,8 @@ void main() { 'golden test for the name "demo"', (WidgetTester tester) async { await tester.pumpWidget( - const MaterialApp( - home: Scaffold( + MaterialAppWrapper( + home: const Scaffold( body: Center( child: SizedBox( width: 100, @@ -85,8 +86,8 @@ void main() { 'control special character test', (WidgetTester tester) async { await tester.pumpWidget( - const MaterialApp( - home: Scaffold( + MaterialAppWrapper( + home: const Scaffold( body: Center( child: SizedBox( width: 100, @@ -109,8 +110,8 @@ void main() { 'control special character test 2', (WidgetTester tester) async { await tester.pumpWidget( - const MaterialApp( - home: Scaffold( + MaterialAppWrapper( + home: const Scaffold( body: Center( child: SizedBox( width: 100, diff --git a/packages/stream_chat_flutter/test/src/avatars/group_avatar_test.dart b/packages/stream_chat_flutter/test/src/avatars/group_avatar_test.dart index eec8326d4..9082f6a43 100644 --- a/packages/stream_chat_flutter/test/src/avatars/group_avatar_test.dart +++ b/packages/stream_chat_flutter/test/src/avatars/group_avatar_test.dart @@ -5,6 +5,7 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -95,7 +96,7 @@ void main() { 'golden test for the group with "user123" and "user456"', (WidgetTester tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChat( client: client, streamChatThemeData: StreamChatThemeData.light(), diff --git a/packages/stream_chat_flutter/test/src/avatars/user_avatar_test.dart b/packages/stream_chat_flutter/test/src/avatars/user_avatar_test.dart index 6f036a273..026ae8fba 100644 --- a/packages/stream_chat_flutter/test/src/avatars/user_avatar_test.dart +++ b/packages/stream_chat_flutter/test/src/avatars/user_avatar_test.dart @@ -4,6 +4,7 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -49,7 +50,7 @@ void main() { (WidgetTester tester) async { when(() => user.online).thenReturn(true); await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( builder: (context, child) { return StreamChatConfiguration( data: StreamChatConfigurationData(), @@ -82,7 +83,7 @@ void main() { (WidgetTester tester) async { when(() => user.online).thenReturn(false); await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( builder: (context, child) { return StreamChatConfiguration( data: StreamChatConfigurationData(), diff --git a/packages/stream_chat_flutter/test/src/bottom_sheets/attachment_modal_sheet_test.dart b/packages/stream_chat_flutter/test/src/bottom_sheets/attachment_modal_sheet_test.dart index 3f969b67d..8eb7b01b4 100644 --- a/packages/stream_chat_flutter/test/src/bottom_sheets/attachment_modal_sheet_test.dart +++ b/packages/stream_chat_flutter/test/src/bottom_sheets/attachment_modal_sheet_test.dart @@ -3,6 +3,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; + void main() { group('AttachmentModalSheet tests', () { testWidgets('Appears on tap', (tester) async { @@ -117,7 +119,7 @@ void main() { 'golden test for AttachmentModalSheet', (WidgetTester tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: Scaffold( body: Builder(builder: (context) { return Center( diff --git a/packages/stream_chat_flutter/test/src/bottom_sheets/edit_message_sheet_test.dart b/packages/stream_chat_flutter/test/src/bottom_sheets/edit_message_sheet_test.dart index 48ccde03a..247bb5acd 100644 --- a/packages/stream_chat_flutter/test/src/bottom_sheets/edit_message_sheet_test.dart +++ b/packages/stream_chat_flutter/test/src/bottom_sheets/edit_message_sheet_test.dart @@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -71,7 +72,7 @@ void main() { 'golden test for EditMessageSheet', (WidgetTester tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( builder: (context, child) => StreamChat( client: MockClient(), child: child, diff --git a/packages/stream_chat_flutter/test/src/bottom_sheets/error_alert_sheet_test.dart b/packages/stream_chat_flutter/test/src/bottom_sheets/error_alert_sheet_test.dart index cc4618178..ffb5f1958 100644 --- a/packages/stream_chat_flutter/test/src/bottom_sheets/error_alert_sheet_test.dart +++ b/packages/stream_chat_flutter/test/src/bottom_sheets/error_alert_sheet_test.dart @@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -77,7 +78,7 @@ void main() { 'golden test for ErrorAlertSheet', (WidgetTester tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( builder: (context, child) => StreamChat( client: MockClient(), child: child, diff --git a/packages/stream_chat_flutter/test/src/channel/channel_header_test.dart b/packages/stream_chat_flutter/test/src/channel/channel_header_test.dart index c3b79509f..2e2f2e6d7 100644 --- a/packages/stream_chat_flutter/test/src/channel/channel_header_test.dart +++ b/packages/stream_chat_flutter/test/src/channel/channel_header_test.dart @@ -3,6 +3,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -273,7 +274,7 @@ void main() { .thenAnswer((i) => Stream.value(1)); await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChat( client: client, child: StreamChannel( diff --git a/packages/stream_chat_flutter/test/src/context_menu_items/download_menu_item_test.dart b/packages/stream_chat_flutter/test/src/context_menu_items/download_menu_item_test.dart index 599bee115..1d63472ce 100644 --- a/packages/stream_chat_flutter/test/src/context_menu_items/download_menu_item_test.dart +++ b/packages/stream_chat_flutter/test/src/context_menu_items/download_menu_item_test.dart @@ -4,6 +4,7 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/src/context_menu_items/download_menu_item.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -31,7 +32,7 @@ void main() { 'golden test for DownloadMenuItem', (WidgetTester tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( builder: (context, child) => StreamChatTheme( data: StreamChatThemeData.light(), child: child!, diff --git a/packages/stream_chat_flutter/test/src/context_menu_items/stream_chat_context_menu_item_test.dart b/packages/stream_chat_flutter/test/src/context_menu_items/stream_chat_context_menu_item_test.dart index f8b5b28b3..d68295403 100644 --- a/packages/stream_chat_flutter/test/src/context_menu_items/stream_chat_context_menu_item_test.dart +++ b/packages/stream_chat_flutter/test/src/context_menu_items/stream_chat_context_menu_item_test.dart @@ -4,6 +4,7 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/src/context_menu_items/stream_chat_context_menu_item.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -29,7 +30,7 @@ void main() { 'golden test for StreamChatContextMenuItem', (WidgetTester tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( builder: (context, child) => StreamChatTheme( data: StreamChatThemeData.light(), child: child!, diff --git a/packages/stream_chat_flutter/test/src/dialogs/confirmation_dialog_test.dart b/packages/stream_chat_flutter/test/src/dialogs/confirmation_dialog_test.dart index 4f9120810..58d876083 100644 --- a/packages/stream_chat_flutter/test/src/dialogs/confirmation_dialog_test.dart +++ b/packages/stream_chat_flutter/test/src/dialogs/confirmation_dialog_test.dart @@ -4,6 +4,8 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/src/dialogs/confirmation_dialog.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; + void main() { testWidgets('ChannelInfoDialog shows info and members', (tester) async { await tester.pumpWidget( @@ -38,7 +40,7 @@ void main() { testGoldens('golden test for ConfirmationDialog', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: Scaffold( body: Builder( builder: (context) { diff --git a/packages/stream_chat_flutter/test/src/dialogs/delete_message_dialog_test.dart b/packages/stream_chat_flutter/test/src/dialogs/delete_message_dialog_test.dart index 7dbe2c327..faa351ceb 100644 --- a/packages/stream_chat_flutter/test/src/dialogs/delete_message_dialog_test.dart +++ b/packages/stream_chat_flutter/test/src/dialogs/delete_message_dialog_test.dart @@ -4,6 +4,8 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/src/dialogs/delete_message_dialog.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; + void main() { testWidgets('DeleteMessageDialog', (tester) async { await tester.pumpWidget( @@ -30,7 +32,7 @@ void main() { testGoldens('golden test for DeleteMessageDialog', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: Scaffold( body: Builder( builder: (context) { diff --git a/packages/stream_chat_flutter/test/src/dialogs/message_dialog_test.dart b/packages/stream_chat_flutter/test/src/dialogs/message_dialog_test.dart index 1e2c14901..62861f8c4 100644 --- a/packages/stream_chat_flutter/test/src/dialogs/message_dialog_test.dart +++ b/packages/stream_chat_flutter/test/src/dialogs/message_dialog_test.dart @@ -4,6 +4,8 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/src/dialogs/message_dialog.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; + void main() { testWidgets('MessageDialog shows default info', (tester) async { await tester.pumpWidget( @@ -57,7 +59,7 @@ void main() { testGoldens('golden test for default MessageDialog', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: Scaffold( body: Builder( builder: (context) { @@ -78,7 +80,7 @@ void main() { testGoldens('golden test for custom MessageDialog', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: Scaffold( body: Builder( builder: (context) { @@ -103,7 +105,7 @@ void main() { testGoldens('golden test for custom MessageDialog with no body', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: Scaffold( body: Builder( builder: (context) { diff --git a/packages/stream_chat_flutter/test/src/gallery/gallery_footer_test.dart b/packages/stream_chat_flutter/test/src/gallery/gallery_footer_test.dart index c8b5cc719..29b5ee7f4 100644 --- a/packages/stream_chat_flutter/test/src/gallery/gallery_footer_test.dart +++ b/packages/stream_chat_flutter/test/src/gallery/gallery_footer_test.dart @@ -5,6 +5,7 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -87,7 +88,7 @@ void main() { testGoldens('golden test for GalleryFooter', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChat( client: client, child: StreamChannel( diff --git a/packages/stream_chat_flutter/test/src/gallery/gallery_header_test.dart b/packages/stream_chat_flutter/test/src/gallery/gallery_header_test.dart index bc8a3a7a5..b02eac1d5 100644 --- a/packages/stream_chat_flutter/test/src/gallery/gallery_header_test.dart +++ b/packages/stream_chat_flutter/test/src/gallery/gallery_header_test.dart @@ -5,6 +5,7 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -88,7 +89,7 @@ void main() { testGoldens('golden test for GalleryHeader', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChat( client: client, child: StreamChannel( diff --git a/packages/stream_chat_flutter/test/src/indicators/sending_indicator_test.dart b/packages/stream_chat_flutter/test/src/indicators/sending_indicator_test.dart index dd84aef9f..369d850b5 100644 --- a/packages/stream_chat_flutter/test/src/indicators/sending_indicator_test.dart +++ b/packages/stream_chat_flutter/test/src/indicators/sending_indicator_test.dart @@ -3,6 +3,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; + void main() { testWidgets( 'StreamSendingIndicator shows sizedBox if messsage state is initial', @@ -54,7 +56,7 @@ void main() { 'golden test for StreamSendingIndicator with StreamSvgIcon.checkAll', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: Scaffold( @@ -75,7 +77,7 @@ void main() { testGoldens('golden test for StreamSendingIndicator with StreamSvgIcon.check', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: Scaffold( @@ -96,7 +98,7 @@ void main() { 'golden test for StreamSendingIndicator with Icon(Icons.access_time)', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: Scaffold( diff --git a/packages/stream_chat_flutter/test/src/indicators/upload_progress_indicator_test.dart b/packages/stream_chat_flutter/test/src/indicators/upload_progress_indicator_test.dart index d7e01dc7f..4376b1812 100644 --- a/packages/stream_chat_flutter/test/src/indicators/upload_progress_indicator_test.dart +++ b/packages/stream_chat_flutter/test/src/indicators/upload_progress_indicator_test.dart @@ -3,6 +3,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; + void main() { testWidgets('StreamUploadProgressIndicator at 0% with no background', (tester) async { @@ -100,7 +102,7 @@ void main() { 'golden test for StreamUploadProgressIndicator at 0% with background', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: const Scaffold( @@ -123,7 +125,7 @@ void main() { 'golden test for StreamUploadProgressIndicator at 50% with background', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: const Scaffold( @@ -146,7 +148,7 @@ void main() { 'golden test for StreamUploadProgressIndicator at 100% with background', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: const Scaffold( diff --git a/packages/stream_chat_flutter/test/src/material_app_wrapper.dart b/packages/stream_chat_flutter/test/src/material_app_wrapper.dart new file mode 100644 index 000000000..904b9a080 --- /dev/null +++ b/packages/stream_chat_flutter/test/src/material_app_wrapper.dart @@ -0,0 +1,28 @@ +// ignore_for_file: public_member_api_docs, use_super_parameters + +import 'package:flutter/material.dart'; + +class MaterialAppWrapper extends MaterialApp { + MaterialAppWrapper({ + Key? key, + TargetPlatform platform = TargetPlatform.android, + Iterable>? localizations, + NavigatorObserver? navigatorObserver, + Iterable? localeOverrides, + ThemeData? theme, + TransitionBuilder? builder, + Widget? home, + }) : super( + key: key, + builder: builder, + localizationsDelegates: localizations, + supportedLocales: localeOverrides ?? const [Locale('en')], + theme: theme?.copyWith(platform: platform) ?? + ThemeData(platform: platform, useMaterial3: false), + debugShowCheckedModeBanner: false, + home: home, + navigatorObservers: [ + if (navigatorObserver != null) navigatorObserver, + ], + ); +} diff --git a/packages/stream_chat_flutter/test/src/message_input/attachment_button_test.dart b/packages/stream_chat_flutter/test/src/message_input/attachment_button_test.dart index 195296c99..9f7d9ef1c 100644 --- a/packages/stream_chat_flutter/test/src/message_input/attachment_button_test.dart +++ b/packages/stream_chat_flutter/test/src/message_input/attachment_button_test.dart @@ -4,6 +4,8 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/src/message_input/attachment_button.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; + void main() { testWidgets('SendButton onPressed works', (tester) async { var count = 0; @@ -33,7 +35,7 @@ void main() { testGoldens('golden test for AttachmentButton', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: Scaffold( body: Center( child: AttachmentButton( diff --git a/packages/stream_chat_flutter/test/src/message_input/clear_input_item_test.dart b/packages/stream_chat_flutter/test/src/message_input/clear_input_item_test.dart index a2d1e302d..fa661d75f 100644 --- a/packages/stream_chat_flutter/test/src/message_input/clear_input_item_test.dart +++ b/packages/stream_chat_flutter/test/src/message_input/clear_input_item_test.dart @@ -4,6 +4,8 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/src/message_input/clear_input_item_button.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; + void main() { testWidgets('ClearInputItemButton onPressed works', (tester) async { var count = 0; @@ -33,7 +35,7 @@ void main() { testGoldens('golden test for ClearInputItemButton', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: Scaffold( diff --git a/packages/stream_chat_flutter/test/src/message_input/command_button_test.dart b/packages/stream_chat_flutter/test/src/message_input/command_button_test.dart index 56a1b445e..8a7365ab8 100644 --- a/packages/stream_chat_flutter/test/src/message_input/command_button_test.dart +++ b/packages/stream_chat_flutter/test/src/message_input/command_button_test.dart @@ -3,6 +3,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/src/message_input/command_button.dart'; +import '../material_app_wrapper.dart'; + void main() { testWidgets('CommandButton onPressed works', (tester) async { var count = 0; @@ -72,7 +74,7 @@ void main() { testGoldens('golden test for CommandButton', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: Scaffold( body: Center( child: CommandButton( diff --git a/packages/stream_chat_flutter/test/src/message_input/countdown_button_test.dart b/packages/stream_chat_flutter/test/src/message_input/countdown_button_test.dart index a81092603..e55a36ed4 100644 --- a/packages/stream_chat_flutter/test/src/message_input/countdown_button_test.dart +++ b/packages/stream_chat_flutter/test/src/message_input/countdown_button_test.dart @@ -3,6 +3,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; + void main() { testWidgets('CountdownButton works', (tester) async { await tester.pumpWidget( @@ -23,7 +25,7 @@ void main() { testGoldens('golden test for CountdownButton', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: const Scaffold( diff --git a/packages/stream_chat_flutter/test/src/message_input/dm_checkbox_test.dart b/packages/stream_chat_flutter/test/src/message_input/dm_checkbox_test.dart index f33f97503..32e4b87b7 100644 --- a/packages/stream_chat_flutter/test/src/message_input/dm_checkbox_test.dart +++ b/packages/stream_chat_flutter/test/src/message_input/dm_checkbox_test.dart @@ -4,6 +4,8 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:stream_chat_flutter/src/message_input/dm_checkbox.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; + void main() { testWidgets('DmCheckbox onTap works', (tester) async { var count = 0; @@ -45,7 +47,7 @@ void main() { testGoldens('golden test for checked DmCheckbox with border', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: Scaffold( @@ -77,7 +79,7 @@ void main() { testGoldens('golden test for checked DmCheckbox without border', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: Scaffold( @@ -102,7 +104,7 @@ void main() { testGoldens('golden test for unchecked DmCheckbox with border', (tester) async { await tester.pumpWidget( - MaterialApp( + MaterialAppWrapper( home: StreamChatTheme( data: StreamChatThemeData.light(), child: Scaffold( diff --git a/packages/stream_chat_flutter/test/src/message_widget/deleted_message_test.dart b/packages/stream_chat_flutter/test/src/message_widget/deleted_message_test.dart index c7dbbf728..7af15894a 100644 --- a/packages/stream_chat_flutter/test/src/message_widget/deleted_message_test.dart +++ b/packages/stream_chat_flutter/test/src/message_widget/deleted_message_test.dart @@ -4,7 +4,9 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; +import '../widget_tester_extension.dart'; void main() { testWidgets( @@ -65,20 +67,20 @@ void main() { when(() => clientState.totalUnreadCountStream) .thenAnswer((i) => Stream.value(10)); - final materialTheme = ThemeData.light(); + final materialTheme = ThemeData.light( + useMaterial3: false, + ); final theme = StreamChatThemeData.fromTheme(materialTheme); await tester.pumpWidgetBuilder( - materialAppWrapper( - theme: materialTheme, - )( - StreamChat( - streamChatThemeData: theme, - client: client, - connectivityStream: Stream.value(ConnectivityResult.mobile), - child: StreamChannel( - showLoading: false, - channel: channel, - child: Center( + StreamChat( + streamChatThemeData: theme, + client: client, + connectivityStream: Stream.value(ConnectivityResult.mobile), + child: StreamChannel( + showLoading: false, + channel: channel, + child: Scaffold( + body: Center( child: StreamDeletedMessage( messageTheme: theme.ownMessageTheme, ), @@ -87,6 +89,10 @@ void main() { ), ), surfaceSize: const Size.square(200), + wrapper: (child) => MaterialAppWrapper( + theme: materialTheme, + home: child, + ), ); await screenMatchesGolden(tester, 'deleted_message_light'); @@ -120,28 +126,31 @@ void main() { when(() => clientState.totalUnreadCountStream) .thenAnswer((i) => Stream.value(10)); - final materialTheme = ThemeData.dark(); + final materialTheme = ThemeData.dark( + useMaterial3: false, + ); final theme = StreamChatThemeData.fromTheme(materialTheme); - await tester.pumpWidgetBuilder( - materialAppWrapper( + await tester.pumpWidgetWithSize( + MaterialAppWrapper( theme: materialTheme, - )( - StreamChat( + home: StreamChat( streamChatThemeData: theme, client: client, connectivityStream: Stream.value(ConnectivityResult.mobile), child: StreamChannel( showLoading: false, channel: channel, - child: Center( - child: StreamDeletedMessage( - messageTheme: theme.ownMessageTheme, + child: Scaffold( + body: Center( + child: StreamDeletedMessage( + messageTheme: theme.ownMessageTheme, + ), ), ), ), ), ), - surfaceSize: const Size.square(200), + size: const Size.square(200), ); await screenMatchesGolden(tester, 'deleted_message_dark'); @@ -175,32 +184,35 @@ void main() { when(() => clientState.totalUnreadCountStream) .thenAnswer((i) => Stream.value(10)); - final materialTheme = ThemeData.light(); + final materialTheme = ThemeData.light( + useMaterial3: false, + ); final theme = StreamChatThemeData.fromTheme(materialTheme); - await tester.pumpWidgetBuilder( - materialAppWrapper( + await tester.pumpWidgetWithSize( + MaterialAppWrapper( theme: materialTheme, - )( - StreamChat( + home: StreamChat( streamChatThemeData: theme, client: client, connectivityStream: Stream.value(ConnectivityResult.mobile), child: StreamChannel( showLoading: false, channel: channel, - child: Center( - child: StreamDeletedMessage( - messageTheme: theme.ownMessageTheme, - reverse: true, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), + child: Scaffold( + body: Center( + child: StreamDeletedMessage( + messageTheme: theme.ownMessageTheme, + reverse: true, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + ), ), ), ), ), ), ), - surfaceSize: const Size.square(200), + size: const Size.square(200), ); await screenMatchesGolden(tester, 'deleted_message_custom'); diff --git a/packages/stream_chat_flutter/test/src/message_widget/message_text_test.dart b/packages/stream_chat_flutter/test/src/message_widget/message_text_test.dart index 8d2052213..7a5055bdd 100644 --- a/packages/stream_chat_flutter/test/src/message_widget/message_text_test.dart +++ b/packages/stream_chat_flutter/test/src/message_widget/message_text_test.dart @@ -5,6 +5,7 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; import '../simple_frame.dart'; @@ -216,7 +217,8 @@ and a list: cool.'''; await tester.pumpWidgetBuilder( - materialAppWrapper()(SimpleFrame( + MaterialAppWrapper( + home: SimpleFrame( child: StreamChat( client: client, connectivityStream: Stream.value(ConnectivityResult.wifi), diff --git a/packages/stream_chat_flutter/test/src/misc/reaction_bubble_test.dart b/packages/stream_chat_flutter/test/src/misc/reaction_bubble_test.dart index 7c14912cf..ec0eff9fa 100644 --- a/packages/stream_chat_flutter/test/src/misc/reaction_bubble_test.dart +++ b/packages/stream_chat_flutter/test/src/misc/reaction_bubble_test.dart @@ -5,6 +5,7 @@ import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/src/message_widget/reactions/reaction_bubble.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -13,7 +14,9 @@ void main() { (WidgetTester tester) async { final client = MockClient(); final clientState = MockClientState(); - final themeData = ThemeData.light(); + final themeData = ThemeData.light( + useMaterial3: false, + ); when(() => client.state).thenReturn(clientState); when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id')); @@ -24,21 +27,28 @@ void main() { client: client, streamChatThemeData: theme, connectivityStream: Stream.value(ConnectivityResult.mobile), - child: SizedBox( - child: StreamReactionBubble( - reactions: [ - Reaction( - type: 'like', - user: User(id: 'test'), - ), - ], - borderColor: theme.ownMessageTheme.reactionsBorderColor!, - backgroundColor: theme.ownMessageTheme.reactionsBackgroundColor!, - maskColor: theme.ownMessageTheme.reactionsMaskColor!, + child: Scaffold( + body: Center( + child: StreamReactionBubble( + reactions: [ + Reaction( + type: 'like', + user: User(id: 'test'), + ), + ], + borderColor: theme.ownMessageTheme.reactionsBorderColor!, + backgroundColor: + theme.ownMessageTheme.reactionsBackgroundColor!, + maskColor: theme.ownMessageTheme.reactionsMaskColor!, + ), ), ), ), surfaceSize: const Size(100, 100), + wrapper: (child) => MaterialAppWrapper( + theme: themeData, + home: child, + ), ); await screenMatchesGolden(tester, 'reaction_bubble_like_light'); }, @@ -176,7 +186,9 @@ void main() { (WidgetTester tester) async { final client = MockClient(); final clientState = MockClientState(); - final themeData = ThemeData(); + final themeData = ThemeData( + useMaterial3: false, + ); when(() => client.state).thenReturn(clientState); when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id')); @@ -186,32 +198,38 @@ void main() { client: client, connectivityStream: Stream.value(ConnectivityResult.mobile), streamChatThemeData: StreamChatThemeData.fromTheme(themeData), - child: SizedBox( - child: StreamReactionBubble( - reactions: [ - Reaction( - type: 'like', - user: User(id: 'test'), - ), - Reaction( - type: 'love', - user: User(id: 'user-id'), - ), - Reaction( - type: 'unknown', - user: User(id: 'test'), - ), - ], - borderColor: Colors.red, - backgroundColor: Colors.blue, - maskColor: Colors.green, - reverse: true, - flipTail: true, - tailCirclesSpacing: 4, + child: Scaffold( + body: Center( + child: StreamReactionBubble( + reactions: [ + Reaction( + type: 'like', + user: User(id: 'test'), + ), + Reaction( + type: 'love', + user: User(id: 'user-id'), + ), + Reaction( + type: 'unknown', + user: User(id: 'test'), + ), + ], + borderColor: Colors.red, + backgroundColor: Colors.blue, + maskColor: Colors.green, + reverse: true, + flipTail: true, + tailCirclesSpacing: 4, + ), ), ), ), surfaceSize: const Size(200, 200), + wrapper: (child) => MaterialAppWrapper( + theme: themeData, + home: child, + ), ); await screenMatchesGolden(tester, 'reaction_bubble_2'); diff --git a/packages/stream_chat_flutter/test/src/misc/system_message_test.dart b/packages/stream_chat_flutter/test/src/misc/system_message_test.dart index 8c4026d80..7878ed676 100644 --- a/packages/stream_chat_flutter/test/src/misc/system_message_test.dart +++ b/packages/stream_chat_flutter/test/src/misc/system_message_test.dart @@ -4,6 +4,7 @@ import 'package:golden_toolkit/golden_toolkit.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -88,16 +89,14 @@ void main() { .thenAnswer((i) => Stream.value(10)); await tester.pumpWidgetBuilder( - materialAppWrapper( - theme: ThemeData.light(), - )( - StreamChat( - client: client, - connectivityStream: Stream.value(ConnectivityResult.mobile), - child: StreamChannel( - showLoading: false, - channel: channel, - child: Center( + StreamChat( + client: client, + connectivityStream: Stream.value(ConnectivityResult.mobile), + child: StreamChannel( + showLoading: false, + channel: channel, + child: Scaffold( + body: Center( child: StreamSystemMessage( message: Message( text: 'demo message', @@ -108,6 +107,9 @@ void main() { ), ), surfaceSize: const Size.square(200), + wrapper: (child) => MaterialAppWrapper( + home: child, + ), ); await screenMatchesGolden(tester, 'system_message_light'); @@ -142,16 +144,14 @@ void main() { .thenAnswer((i) => Stream.value(10)); await tester.pumpWidgetBuilder( - materialAppWrapper( - theme: ThemeData.dark(), - )( - StreamChat( - client: client, - connectivityStream: Stream.value(ConnectivityResult.mobile), - child: StreamChannel( - showLoading: false, - channel: channel, - child: Center( + StreamChat( + client: client, + connectivityStream: Stream.value(ConnectivityResult.mobile), + child: StreamChannel( + showLoading: false, + channel: channel, + child: Scaffold( + body: Center( child: StreamSystemMessage( message: Message( text: 'demo message', @@ -162,6 +162,12 @@ void main() { ), ), surfaceSize: const Size.square(200), + wrapper: (child) => MaterialAppWrapper( + theme: ThemeData.dark( + useMaterial3: false, + ), + home: child, + ), ); await screenMatchesGolden(tester, 'system_message_dark'); diff --git a/packages/stream_chat_flutter/test/src/misc/thread_header_test.dart b/packages/stream_chat_flutter/test/src/misc/thread_header_test.dart index 029e9f942..05f6e56b7 100644 --- a/packages/stream_chat_flutter/test/src/misc/thread_header_test.dart +++ b/packages/stream_chat_flutter/test/src/misc/thread_header_test.dart @@ -3,6 +3,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; +import '../material_app_wrapper.dart'; import '../mocks.dart'; void main() { @@ -112,7 +113,7 @@ void main() { ]); var tapped = false; - await tester.pumpWidget(MaterialApp( + await tester.pumpWidget(MaterialAppWrapper( home: StreamChat( client: client, child: StreamChannel( diff --git a/packages/stream_chat_flutter/test/src/widget_tester_extension.dart b/packages/stream_chat_flutter/test/src/widget_tester_extension.dart new file mode 100644 index 000000000..4f557bdbb --- /dev/null +++ b/packages/stream_chat_flutter/test/src/widget_tester_extension.dart @@ -0,0 +1,19 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +extension WidgetTesterExtension on WidgetTester { + Future pumpWidgetWithSize( + Widget widget, { + required Size size, + double textScaleSize = 1.0, + }) async { + await binding.setSurfaceSize(size); + view + ..physicalSize = size + ..devicePixelRatio = 1.0; + platformDispatcher.textScaleFactorTestValue = textScaleSize; + + await pumpWidget(widget); + await pump(); + } +} diff --git a/packages/stream_chat_localizations/test/basics_test.dart b/packages/stream_chat_localizations/test/basics_test.dart index 2c8bb4db9..a05877f43 100644 --- a/packages/stream_chat_localizations/test/basics_test.dart +++ b/packages/stream_chat_localizations/test/basics_test.dart @@ -7,6 +7,9 @@ import 'package:stream_chat_localizations/stream_chat_localizations.dart'; void main() { testWidgets('Nested Localizations', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( + theme: ThemeData( + useMaterial3: false, + ), // Creates the outer Localizations widget. home: ListView( children: [