Skip to content

Commit 7073571

Browse files
authored
fix(ui): be lenient when calling nullable onThreadTap method (#1854)
1 parent 35d338e commit 7073571

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

packages/stream_chat_flutter/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
🐞 Fixed
99
- Removed double focus on `StreamMessageInput` when `focusNode` is provided for web and desktop.
10+
- Optionally call `onThreadTap` in `BottomRow` to avoid `Null check operator used on a null value`
11+
1012

1113
## 7.0.1
1214

packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class BottomRow extends StatelessWidget {
169169
final channel = StreamChannel.of(context);
170170
message = await channel.getMessage(message.parentId!);
171171
}
172-
return onThreadTap!(message);
172+
return onThreadTap?.call(message);
173173
} catch (e, stk) {
174174
debugPrint('Error while fetching message: $e, $stk');
175175
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:mocktail/mocktail.dart';
4+
import 'package:stream_chat_flutter/src/message_widget/bottom_row.dart';
5+
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
6+
7+
import '../mocks.dart';
8+
9+
void main() {
10+
late Channel channel;
11+
late ChannelClientState channelClientState;
12+
13+
setUp(() {
14+
channel = MockChannel();
15+
when(() => channel.on(any(), any(), any(), any()))
16+
.thenAnswer((_) => const Stream.empty());
17+
channelClientState = MockChannelState();
18+
when(() => channel.state).thenReturn(channelClientState);
19+
when(() => channelClientState.messages).thenReturn([
20+
Message(
21+
id: 'parentId',
22+
)
23+
]);
24+
});
25+
26+
setUpAll(() {
27+
registerFallbackValue(Message());
28+
});
29+
30+
testWidgets('BottomRow', (tester) async {
31+
final theme = StreamChatThemeData.light();
32+
final onThreadTap = MockVoidSingleParamCallback<Message>();
33+
34+
await tester.pumpWidget(
35+
MaterialApp(
36+
home: Scaffold(
37+
body: Center(
38+
child: StreamChannel(
39+
channel: channel,
40+
child: BottomRow(
41+
message: Message(
42+
parentId: 'parentId',
43+
),
44+
isDeleted: false,
45+
showThreadReplyIndicator: false,
46+
showUsername: false,
47+
showInChannel: true,
48+
showTimeStamp: false,
49+
reverse: false,
50+
showSendingIndicator: false,
51+
hasUrlAttachments: false,
52+
isGiphy: false,
53+
isOnlyEmoji: false,
54+
messageTheme: theme.otherMessageTheme,
55+
streamChatTheme: theme,
56+
hasNonUrlAttachments: false,
57+
streamChat: StreamChatState(),
58+
onThreadTap: onThreadTap,
59+
),
60+
),
61+
),
62+
),
63+
),
64+
);
65+
66+
await tester.tap(find.byType(GestureDetector));
67+
await tester.pumpAndSettle();
68+
69+
verify(() => onThreadTap.call(any()));
70+
});
71+
}

packages/stream_chat_flutter/test/src/mocks.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class MockVoidCallback extends Mock {
4646
void call();
4747
}
4848

49+
class MockVoidSingleParamCallback<T> extends Mock {
50+
void call(T param);
51+
}
52+
4953
class MockAttachmentHandler extends Mock implements StreamAttachmentHandler {}
5054

5155
class MockMember extends Mock implements Member {}

0 commit comments

Comments
 (0)