add reaction_bubble_test
This commit is contained in:
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -142,7 +142,7 @@ class StreamChatThemeData {
|
||||
Widget Function(BuildContext, Channel) defaultChannelImage,
|
||||
Widget Function(BuildContext, User) defaultUserImage,
|
||||
IconThemeData primaryIconTheme,
|
||||
List<ReactionIcon> reactionAssets,
|
||||
List<ReactionIcon> 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
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user