Skip to content

Commit 843b4b4

Browse files
authored
fix(ui): fix message input command, attachment button incorrect assertion (#2145)
* fix(ui): fix message input command, attachment button incorrect assertion. * chore: update CHANGELOG.md * chore: fix changelog issue number
1 parent 462a31e commit 843b4b4

File tree

5 files changed

+63
-29
lines changed

5 files changed

+63
-29
lines changed

packages/stream_chat_flutter/CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
## Upcoming
2+
3+
🐞 Fixed
4+
5+
- [[#2118]](https://github.com/GetStream/stream-chat-flutter/issues/2118) Fixed invalid assertions
6+
applied on message input command and attachment button.
7+
18
## 9.6.0
29

3-
- [[#2118]](https://github.com/GetStream/stream-chat-flutter/issues/2118) Fixed message input
10+
🐞 Fixed
11+
12+
- [[#2137]](https://github.com/GetStream/stream-chat-flutter/issues/2137) Fixed message input
413
buttons not being able to customized.
514
- [[#1775]](https://github.com/GetStream/stream-chat-flutter/issues/1775) Fix incorrect message order.
615

packages/stream_chat_flutter/lib/src/message_input/attachment_button.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ class AttachmentButton extends StatelessWidget {
1313
this.color,
1414
this.icon,
1515
this.size = kDefaultMessageInputIconSize,
16-
}) : assert(
17-
(icon == null && color == null) ||
18-
(icon != null && color == null) ||
19-
(icon == null && color != null),
20-
'Either icon or color should be provided');
16+
});
2117

2218
/// The color of the button.
2319
/// Should be set if no [icon] is provided.

packages/stream_chat_flutter/lib/src/message_input/command_button.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ class CommandButton extends StatelessWidget {
1313
this.color,
1414
this.icon,
1515
this.size = kDefaultMessageInputIconSize,
16-
}) : assert(
17-
(icon == null && color == null) ||
18-
(icon != null && color == null) ||
19-
(icon == null && color != null),
20-
'Either icon or color should be provided');
16+
});
2117

2218
/// The color of the button.
2319
/// Should be set if no [icon] is provided.

packages/stream_chat_flutter/test/src/message_input/attachment_button_test.dart

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
77
import '../material_app_wrapper.dart';
88

99
void main() {
10-
testWidgets('SendButton onPressed works', (tester) async {
10+
testWidgets('AttachmentButton onPressed works', (tester) async {
1111
var count = 0;
1212
await tester.pumpWidget(
1313
MaterialApp(
1414
home: Scaffold(
1515
body: Center(
1616
child: AttachmentButton(
17-
color: StreamChatThemeData.light()
18-
.messageInputTheme
19-
.actionButtonIdleColor,
17+
color: Colors.red,
2018
onPressed: () {
2119
count++;
2220
},
@@ -33,6 +31,45 @@ void main() {
3331
expect(count, 1);
3432
});
3533

34+
testWidgets('AttachmentButton should accept icon', (tester) async {
35+
const icon = Icon(Icons.attachment);
36+
await tester.pumpWidget(
37+
MaterialApp(
38+
home: Scaffold(
39+
body: Center(
40+
child: AttachmentButton(
41+
icon: icon,
42+
onPressed: () {},
43+
),
44+
),
45+
),
46+
),
47+
);
48+
49+
expect(find.byIcon(Icons.attachment), findsOneWidget);
50+
});
51+
52+
testWidgets('AttachmentButton should accept color', (tester) async {
53+
await tester.pumpWidget(
54+
MaterialApp(
55+
home: Scaffold(
56+
body: Center(
57+
child: AttachmentButton(
58+
color: Colors.red,
59+
onPressed: () {},
60+
),
61+
),
62+
),
63+
),
64+
);
65+
66+
final buttonFinder = find.byType(AttachmentButton);
67+
expect(buttonFinder, findsOneWidget);
68+
69+
final button = tester.widget<AttachmentButton>(buttonFinder);
70+
expect(button.color, Colors.red);
71+
});
72+
3673
goldenTest(
3774
'golden test for AttachmentButton',
3875
fileName: 'attachment_button_0',

packages/stream_chat_flutter/test/src/message_input/command_button_test.dart

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,28 @@ void main() {
4444
),
4545
);
4646

47-
final iconFound = find.byWidget(icon);
48-
expect(iconFound, findsOneWidget);
47+
expect(find.byIcon(Icons.add), findsOneWidget);
4948
});
5049

51-
testWidgets('CommandButton should not accept both color and icon',
52-
(tester) async {
53-
expect(
54-
() => MaterialApp(
50+
testWidgets('CommandButton should accept color', (tester) async {
51+
await tester.pumpWidget(
52+
MaterialApp(
5553
home: Scaffold(
5654
body: Center(
5755
child: CommandButton(
5856
color: Colors.red,
59-
icon: const Icon(Icons.add),
6057
onPressed: () {},
6158
),
6259
),
6360
),
6461
),
65-
throwsA(
66-
isA<AssertionError>().having(
67-
(e) => e.message,
68-
'message',
69-
'Either icon or color should be provided',
70-
),
71-
),
7262
);
63+
64+
final buttonFinder = find.byType(CommandButton);
65+
expect(buttonFinder, findsOneWidget);
66+
67+
final button = tester.widget<CommandButton>(buttonFinder);
68+
expect(button.color, Colors.red);
7369
});
7470

7571
goldenTest(

0 commit comments

Comments
 (0)