diff --git a/lib/src/reaction_bubble.dart b/lib/src/reaction_bubble.dart index 7c36cdf3..0d37d87f 100644 --- a/lib/src/reaction_bubble.dart +++ b/lib/src/reaction_bubble.dart @@ -21,7 +21,7 @@ class ReactionBubble extends StatelessWidget { @override Widget build(BuildContext context) { - final reactionAssets = StreamChatTheme.of(context).reactionIcons; + final reactionIcons = StreamChatTheme.of(context).reactionIcons; return Transform( transform: Matrix4.rotationY(reverse ? pi : 0), alignment: Alignment.center, @@ -42,11 +42,11 @@ class ReactionBubble extends StatelessWidget { child: Wrap( children: [ ...reactions.map((reaction) { - final reactionAsset = reactionAssets.firstWhere( - (reactionAsset) => reactionAsset.type == reaction.type, + final reactionIcon = reactionIcons.firstWhere( + (r) => r.type == reaction.type, orElse: () => null, ); - if (reactionAsset == null) { + if (reactionIcon == null) { return Text( '?', style: TextStyle( @@ -56,7 +56,7 @@ class ReactionBubble extends StatelessWidget { } return Icon( - reactionAsset.iconData, + reactionIcon.iconData, size: 16, color: StreamChatTheme.of(context).accentColor, ); diff --git a/lib/src/reaction_picker.dart b/lib/src/reaction_picker.dart index ddeb6ad5..4f6cdf91 100644 --- a/lib/src/reaction_picker.dart +++ b/lib/src/reaction_picker.dart @@ -1,5 +1,3 @@ -import 'dart:math'; - import 'package:flutter/material.dart'; import 'package:stream_chat_flutter/src/reaction_bubble.dart'; @@ -25,7 +23,7 @@ class ReactionPicker extends StatelessWidget { @override Widget build(BuildContext context) { - final reactionAssets = StreamChatTheme.of(context).reactionIcons; + final reactionIcons = StreamChatTheme.of(context).reactionIcons; return Stack( fit: StackFit.passthrough, children: [ @@ -39,7 +37,7 @@ class ReactionPicker extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, - children: reactionAssets.map((reactionIcon) { + children: reactionIcons.map((reactionIcon) { final ownReactionIndex = message.ownReactions?.indexWhere( (reaction) => reaction.type == reactionIcon.type) ?? -1; diff --git a/lib/src/stream_chat_theme.dart b/lib/src/stream_chat_theme.dart index 56f71a93..84271ec0 100644 --- a/lib/src/stream_chat_theme.dart +++ b/lib/src/stream_chat_theme.dart @@ -142,7 +142,7 @@ class StreamChatThemeData { Widget Function(BuildContext, Channel) defaultChannelImage, Widget Function(BuildContext, User) defaultUserImage, IconThemeData primaryIconTheme, - List reactionAssets, + List reactionIcons, }) => StreamChatThemeData( primaryColor: primaryColor ?? this.primaryColor, @@ -211,7 +211,7 @@ class StreamChatThemeData { this.otherMessageTheme.avatarTheme, ) ?? this.otherMessageTheme, - reactionIcons: reactionAssets ?? this.reactionIcons, + reactionIcons: reactionIcons ?? this.reactionIcons, ); /// Get the default Stream Chat theme diff --git a/test/src/reaction_bubble_test.dart b/test/src/reaction_bubble_test.dart new file mode 100644 index 00000000..dc0381de --- /dev/null +++ b/test/src/reaction_bubble_test.dart @@ -0,0 +1,87 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:stream_chat_flutter/src/reaction_bubble.dart'; +import 'package:stream_chat_flutter/stream_chat_flutter.dart'; + +void main() { + testWidgets( + 'it should show no reactions', + (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: StreamChatTheme( + data: StreamChatThemeData(), + child: Container( + child: ReactionBubble( + reactions: [], + borderColor: Colors.black, + backgroundColor: Colors.white, + ), + ), + ), + ), + ); + + expect(find.byIcon(StreamIcons.thumbs_up_reaction), findsNothing); + }, + ); + + testWidgets( + 'it should show a thumb up', + (WidgetTester tester) async { + final themeData = ThemeData(); + await tester.pumpWidget( + MaterialApp( + theme: themeData, + home: StreamChatTheme( + data: StreamChatThemeData.getDefaultTheme(themeData), + child: Container( + child: ReactionBubble( + reactions: [ + Reaction( + type: 'thumbs_up', + ), + ], + borderColor: Colors.black, + backgroundColor: Colors.white, + ), + ), + ), + ), + ); + + expect(find.byIcon(StreamIcons.thumbs_up_reaction), findsOneWidget); + }, + ); + testWidgets( + 'it should show two reactions', + (WidgetTester tester) async { + final themeData = ThemeData(); + await tester.pumpWidget( + MaterialApp( + theme: themeData, + home: StreamChatTheme( + data: StreamChatThemeData.getDefaultTheme(themeData), + child: Container( + child: ReactionBubble( + reactions: [ + Reaction( + type: 'thumbs_up', + ), + Reaction( + type: 'love', + ), + ], + borderColor: Colors.black, + backgroundColor: Colors.white, + ), + ), + ), + ), + ); + + expect(find.byIcon(StreamIcons.thumbs_up_reaction), findsOneWidget); + expect(find.byIcon(StreamIcons.love_reaction), findsOneWidget); + }, + ); +}