-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathephemeral_message.dart
More file actions
58 lines (51 loc) · 1.78 KB
/
Copy pathephemeral_message.dart
File metadata and controls
58 lines (51 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/src/message_widget/giphy_ephemeral_message.dart';
import 'package:stream_chat_flutter/src/misc/empty_widget.dart';
import 'package:stream_chat_flutter/src/utils/typedefs.dart';
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
/// {@template streamEphemeralMessage}
/// Shows an ephemeral message in a [StreamMessageWidget].
/// {@endtemplate}
class StreamEphemeralMessage extends StatelessWidget {
/// {@macro streamEphemeralMessage}
const StreamEphemeralMessage({
super.key,
required this.message,
this.onMessageTap,
});
/// The underlying [Message] object which this widget represents.
final Message message;
/// The action to perform when tapping on the message.
final OnMessageTap? onMessageTap;
@override
Widget build(BuildContext context) {
final streamChannel = StreamChannel.of(context);
// If the message is a giphy command, we will show the giphy ephemeral
// message instead.
final isGiphy = message.command == 'giphy';
if (isGiphy) {
return Material(
type: MaterialType.transparency,
child: InkWell(
onTap: switch (onMessageTap) {
final onTap? => () => onTap(message),
_ => null,
},
child: GiphyEphemeralMessage(
message: message,
onActionPressed: (name, value) {
streamChannel.channel.sendAction(
message,
{name: value},
);
},
),
),
);
}
// Assert if the message is not handled.
assert(true, 'Ephemeral message not handled, Please add a handler');
// Show nothing if we don't know how to handle the message.
return const Empty();
}
}