feat(ui): add possibility to limit attachments in MessageInput

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2021-08-11 17:01:50 +05:30
committed by xsahil03x
parent 2317115350
commit 9dba5a61d2
3 changed files with 268 additions and 244 deletions
@@ -106,7 +106,7 @@ class ChannelPage extends StatelessWidget {
Expanded( Expanded(
child: MessageListView(), child: MessageListView(),
), ),
MessageInput(), MessageInput(attachmentLimit: 3),
], ],
), ),
); );
@@ -37,6 +37,16 @@ typedef ErrorListener = void Function(
StackTrace? stackTrace, StackTrace? stackTrace,
); );
/// A callback that can be passed to [MessageInput.onAttachmentLimitExceed].
///
/// This callback should not throw.
///
/// It exists merely for showing custom error, and should not be used otherwise.
typedef AttachmentLimitExceedListener = void Function(
int limit,
String error,
);
/// Builder for attachment thumbnails /// Builder for attachment thumbnails
typedef AttachmentThumbnailBuilder = Widget Function( typedef AttachmentThumbnailBuilder = Widget Function(
BuildContext, BuildContext,
@@ -164,7 +174,13 @@ class MessageInput extends StatefulWidget {
this.compressedVideoQuality = VideoQuality.DefaultQuality, this.compressedVideoQuality = VideoQuality.DefaultQuality,
this.compressedVideoFrameRate = 30, this.compressedVideoFrameRate = 30,
this.onError, this.onError,
}) : super(key: key); this.attachmentLimit = 10,
this.onAttachmentLimitExceed,
}) : assert(
initialMessage == null || editMessage == null,
"Can't provide both `initialMessage` and `editMessage`",
),
super(key: key);
/// Message to edit /// Message to edit
final Message? editMessage; final Message? editMessage;
@@ -247,6 +263,11 @@ class MessageInput extends StatefulWidget {
/// A callback for error reporting /// A callback for error reporting
final ErrorListener? onError; final ErrorListener? onError;
final int attachmentLimit;
/// A callback for error reporting
final AttachmentLimitExceedListener? onAttachmentLimitExceed;
@override @override
MessageInputState createState() => MessageInputState(); MessageInputState createState() => MessageInputState();
@@ -270,7 +291,6 @@ class MessageInputState extends State<MessageInput> {
final _imagePicker = ImagePicker(); final _imagePicker = ImagePicker();
late final FocusNode _focusNode; late final FocusNode _focusNode;
bool _inputEnabled = true; bool _inputEnabled = true;
bool _messageIsPresent = false;
bool _commandEnabled = false; bool _commandEnabled = false;
OverlayEntry? _commandsOverlay, _mentionsOverlay, _emojiOverlay; OverlayEntry? _commandsOverlay, _mentionsOverlay, _emojiOverlay;
late Iterable<String> _emojiNames; late Iterable<String> _emojiNames;
@@ -285,13 +305,15 @@ class MessageInputState extends State<MessageInput> {
KeyboardVisibilityController(); KeyboardVisibilityController();
/// The editing controller passed to the input TextField /// The editing controller passed to the input TextField
late final TextEditingController textEditingController; late final TextEditingController _textEditingController;
late StreamChatThemeData _streamChatTheme; late StreamChatThemeData _streamChatTheme;
late MessageInputThemeData _messageInputTheme; late MessageInputThemeData _messageInputTheme;
bool get _hasQuotedMessage => widget.quotedMessage != null; bool get _hasQuotedMessage => widget.quotedMessage != null;
bool get _messageIsPresent => _textEditingController.text.trim().isNotEmpty;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@@ -303,19 +325,19 @@ class MessageInputState extends State<MessageInput> {
_keyboardListener = _keyboardListener =
_keyboardVisibilityController.onChange.listen((visible) { _keyboardVisibilityController.onChange.listen((visible) {
if (_focusNode.hasFocus) { if (_focusNode.hasFocus) {
_onChanged(context, textEditingController.text); _onChanged(context, _textEditingController.text);
} }
}); });
} }
textEditingController = _textEditingController =
widget.textEditingController ?? TextEditingController(); widget.textEditingController ?? TextEditingController();
if (widget.editMessage != null || widget.initialMessage != null) { if (widget.editMessage != null || widget.initialMessage != null) {
_parseExistingMessage(widget.editMessage ?? widget.initialMessage!); _parseExistingMessage(widget.editMessage ?? widget.initialMessage!);
} }
textEditingController.addListener(() { _textEditingController.addListener(() {
_onChanged(context, textEditingController.text); _onChanged(context, _textEditingController.text);
}); });
_focusNode.addListener(() { _focusNode.addListener(() {
@@ -582,7 +604,7 @@ class MessageInputState extends State<MessageInput> {
maxLines: null, maxLines: null,
onSubmitted: (_) => sendMessage(), onSubmitted: (_) => sendMessage(),
keyboardType: widget.keyboardType, keyboardType: widget.keyboardType,
controller: textEditingController, controller: _textEditingController,
focusNode: _focusNode, focusNode: _focusNode,
style: _messageInputTheme.inputTextStyle, style: _messageInputTheme.inputTextStyle,
autofocus: widget.autofocus, autofocus: widget.autofocus,
@@ -728,7 +750,6 @@ class MessageInputState extends State<MessageInput> {
.catchError((e) {}); .catchError((e) {});
setState(() { setState(() {
_messageIsPresent = s.trim().isNotEmpty;
_actionsShrunk = s.trim().isNotEmpty && _actionsShrunk = s.trim().isNotEmpty &&
((widget.actions?.length ?? 0) + ((widget.actions?.length ?? 0) +
(widget.showCommandsButton ? 1 : 0) + (widget.showCommandsButton ? 1 : 0) +
@@ -764,15 +785,15 @@ class MessageInputState extends State<MessageInput> {
void _checkEmoji(String s, BuildContext context) { void _checkEmoji(String s, BuildContext context) {
if (s.isNotEmpty && if (s.isNotEmpty &&
textEditingController.selection.baseOffset > 0 && _textEditingController.selection.baseOffset > 0 &&
textEditingController.text _textEditingController.text
.substring( .substring(
0, 0,
textEditingController.selection.baseOffset, _textEditingController.selection.baseOffset,
) )
.contains(':')) { .contains(':')) {
final textToSelection = textEditingController.text final textToSelection = _textEditingController.text
.substring(0, textEditingController.value.selection.start); .substring(0, _textEditingController.value.selection.start);
final splits = textToSelection.split(':'); final splits = textToSelection.split(':');
final query = splits[splits.length - 2].toLowerCase(); final query = splits[splits.length - 2].toLowerCase();
final emoji = Emoji.byName(query); final emoji = Emoji.byName(query);
@@ -791,9 +812,9 @@ class MessageInputState extends State<MessageInput> {
void _checkMentions(String s, BuildContext context) { void _checkMentions(String s, BuildContext context) {
if (s.isNotEmpty && if (s.isNotEmpty &&
textEditingController.selection.baseOffset > 0 && _textEditingController.selection.baseOffset > 0 &&
textEditingController.text _textEditingController.text
.substring(0, textEditingController.selection.baseOffset) .substring(0, _textEditingController.selection.baseOffset)
.split(' ') .split(' ')
.last .last
.contains('@')) { .contains('@')) {
@@ -816,8 +837,7 @@ class MessageInputState extends State<MessageInput> {
if (matchedCommandsList.length == 1) { if (matchedCommandsList.length == 1) {
_chosenCommand = matchedCommandsList[0]; _chosenCommand = matchedCommandsList[0];
textEditingController.clear(); _textEditingController.clear();
_messageIsPresent = false;
setState(() { setState(() {
_commandEnabled = true; _commandEnabled = true;
}); });
@@ -833,7 +853,7 @@ class MessageInputState extends State<MessageInput> {
} }
OverlayEntry? _buildCommandsOverlayEntry() { OverlayEntry? _buildCommandsOverlayEntry() {
final text = textEditingController.text.trimLeft(); final text = _textEditingController.text.trimLeft();
final commands = StreamChannel.of(context) final commands = StreamChannel.of(context)
.channel .channel
.config .config
@@ -1037,7 +1057,7 @@ class MessageInputState extends State<MessageInput> {
onPressed: _attachmentContainsFile && _attachments.isNotEmpty onPressed: _attachmentContainsFile && _attachments.isNotEmpty
? null ? null
: () { : () {
pickFile(DefaultAttachmentTypes.image, true); pickFile(DefaultAttachmentTypes.image, camera: true);
}, },
), ),
IconButton( IconButton(
@@ -1048,7 +1068,7 @@ class MessageInputState extends State<MessageInput> {
onPressed: _attachmentContainsFile && _attachments.isNotEmpty onPressed: _attachmentContainsFile && _attachments.isNotEmpty
? null ? null
: () { : () {
pickFile(DefaultAttachmentTypes.video, true); pickFile(DefaultAttachmentTypes.video, camera: true);
}, },
), ),
], ],
@@ -1107,7 +1127,7 @@ class MessageInputState extends State<MessageInput> {
if (_attachments.containsKey(media.id)) { if (_attachments.containsKey(media.id)) {
setState(() => _attachments.remove(media.id)); setState(() => _attachments.remove(media.id));
} else { } else {
_addAttachment(media); _addAssetAttachment(media);
} }
}, },
), ),
@@ -1119,15 +1139,13 @@ class MessageInputState extends State<MessageInput> {
); );
} }
void _addAttachment(AssetEntity medium) async { void _addAssetAttachment(AssetEntity medium) async {
final mediaFile = await medium.originFile.timeout( final mediaFile = await medium.originFile.timeout(
const Duration(seconds: 5), const Duration(seconds: 5),
onTimeout: () => medium.originFile, onTimeout: () => medium.originFile,
); );
if (mediaFile == null) { if (mediaFile == null) return;
return;
}
var file = AttachmentFile( var file = AttachmentFile(
path: mediaFile.path, path: mediaFile.path,
@@ -1166,11 +1184,12 @@ class MessageInputState extends State<MessageInput> {
} }
setState(() { setState(() {
_attachments[medium.id] = Attachment( final attachment = Attachment(
id: medium.id, id: medium.id,
file: file, file: file,
type: medium.type == AssetType.image ? 'image' : 'video', type: medium.type == AssetType.image ? 'image' : 'video',
); );
_addAttachments([attachment]);
}); });
} }
@@ -1251,8 +1270,8 @@ class MessageInputState extends State<MessageInput> {
} }
OverlayEntry? _buildMentionsOverlayEntry() { OverlayEntry? _buildMentionsOverlayEntry() {
final splits = textEditingController.text final splits = _textEditingController.text
.substring(0, textEditingController.value.selection.start) .substring(0, _textEditingController.value.selection.start)
.split('@'); .split('@');
final query = splits.last.toLowerCase(); final query = splits.last.toLowerCase();
@@ -1314,10 +1333,10 @@ class MessageInputState extends State<MessageInput> {
splits[splits.length - 1] = m.user!.name; splits[splits.length - 1] = m.user!.name;
final rejoin = splits.join('@'); final rejoin = splits.join('@');
textEditingController.value = TextEditingValue( _textEditingController.value = TextEditingValue(
text: rejoin + text: rejoin +
textEditingController.text.substring( _textEditingController.text.substring(
textEditingController.selection.start), _textEditingController.selection.start),
selection: TextSelection.collapsed( selection: TextSelection.collapsed(
offset: rejoin.length, offset: rejoin.length,
), ),
@@ -1361,8 +1380,8 @@ class MessageInputState extends State<MessageInput> {
} }
OverlayEntry? _buildEmojiOverlay() { OverlayEntry? _buildEmojiOverlay() {
final splits = textEditingController.text final splits = _textEditingController.text
.substring(0, textEditingController.value.selection.start) .substring(0, _textEditingController.value.selection.start)
.split(':'); .split(':');
final query = splits.last.toLowerCase(); final query = splits.last.toLowerCase();
@@ -1473,10 +1492,10 @@ class MessageInputState extends State<MessageInput> {
void _chooseEmoji(List<String> splits, Emoji emoji) { void _chooseEmoji(List<String> splits, Emoji emoji) {
final rejoin = splits.sublist(0, splits.length - 1).join(':') + emoji.char!; final rejoin = splits.sublist(0, splits.length - 1).join(':') + emoji.char!;
textEditingController.value = TextEditingValue( _textEditingController.value = TextEditingValue(
text: rejoin + text: rejoin +
textEditingController.text _textEditingController.text
.substring(textEditingController.selection.start), .substring(_textEditingController.selection.start),
selection: TextSelection.collapsed( selection: TextSelection.collapsed(
offset: rejoin.length, offset: rejoin.length,
), ),
@@ -1487,11 +1506,10 @@ class MessageInputState extends State<MessageInput> {
} }
void _setCommand(Command c) { void _setCommand(Command c) {
textEditingController.clear(); _textEditingController.clear();
setState(() { setState(() {
_chosenCommand = c; _chosenCommand = c;
_commandEnabled = true; _commandEnabled = true;
_messageIsPresent = false;
}); });
_commandsOverlay?.remove(); _commandsOverlay?.remove();
_commandsOverlay = null; _commandsOverlay = null;
@@ -1682,7 +1700,7 @@ class MessageInputState extends State<MessageInput> {
} }
Widget _buildCommandButton() { Widget _buildCommandButton() {
final s = textEditingController.text.trim(); final s = _textEditingController.text.trim();
return IconButton( return IconButton(
icon: StreamSvgIcon.lightning( icon: StreamSvgIcon.lightning(
@@ -1768,87 +1786,100 @@ class MessageInputState extends State<MessageInput> {
}); });
} else { } else {
showModalBottomSheet( showModalBottomSheet(
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
topLeft: Radius.circular(32), topLeft: Radius.circular(32),
topRight: Radius.circular(32), topRight: Radius.circular(32),
),
), ),
context: context, ),
isScrollControlled: true, context: context,
builder: (_) => Column( isScrollControlled: true,
mainAxisSize: MainAxisSize.min, builder: (_) => Column(
children: <Widget>[ mainAxisSize: MainAxisSize.min,
ListTile( children: <Widget>[
title: Text( ListTile(
context.translations.addAFileLabel, title: Text(
style: const TextStyle( context.translations.addAFileLabel,
fontWeight: FontWeight.bold, style: const TextStyle(
), fontWeight: FontWeight.bold,
), ),
), ),
ListTile( ),
leading: const Icon(Icons.image), ListTile(
title: Text(context.translations.uploadAPhotoLabel), leading: const Icon(Icons.image),
onTap: () { title: Text(context.translations.uploadAPhotoLabel),
pickFile(DefaultAttachmentTypes.image); onTap: () {
Navigator.pop(context); pickFile(DefaultAttachmentTypes.image);
}, Navigator.pop(context);
), },
ListTile( ),
leading: const Icon(Icons.video_library), ListTile(
title: Text(context.translations.uploadAVideoLabel), leading: const Icon(Icons.video_library),
onTap: () { title: Text(context.translations.uploadAVideoLabel),
pickFile(DefaultAttachmentTypes.video); onTap: () {
Navigator.pop(context); pickFile(DefaultAttachmentTypes.video);
}, Navigator.pop(context);
), },
if (!kIsWeb) ),
ListTile( if (!kIsWeb)
leading: const Icon(Icons.camera_alt), ListTile(
title: Text(context.translations.photoFromCameraLabel), leading: const Icon(Icons.camera_alt),
onTap: () { title: Text(context.translations.photoFromCameraLabel),
pickFile(DefaultAttachmentTypes.image, true); onTap: () {
Navigator.pop(context); pickFile(DefaultAttachmentTypes.image, camera: true);
}, Navigator.pop(context);
), },
if (!kIsWeb) ),
ListTile( if (!kIsWeb)
leading: const Icon(Icons.videocam), ListTile(
title: Text(context.translations.videoFromCameraLabel), leading: const Icon(Icons.videocam),
onTap: () { title: Text(context.translations.videoFromCameraLabel),
pickFile(DefaultAttachmentTypes.video, true); onTap: () {
Navigator.pop(context); pickFile(DefaultAttachmentTypes.video, camera: true);
}, Navigator.pop(context);
), },
ListTile( ),
leading: const Icon(Icons.insert_drive_file), ListTile(
title: Text(context.translations.uploadAFileLabel), leading: const Icon(Icons.insert_drive_file),
onTap: () { title: Text(context.translations.uploadAFileLabel),
pickFile(DefaultAttachmentTypes.file); onTap: () {
Navigator.pop(context); pickFile(DefaultAttachmentTypes.file);
}, Navigator.pop(context);
), },
], ),
)); ],
),
);
} }
} }
/// Add an attachment to the sending message /// Adds an attachment to the [_attachments] map
/// Use this to add custom type attachments void _addAttachments(Iterable<Attachment> attachments) {
void addAttachment(Attachment attachment) { final length = _attachments.length + attachments.length;
setState(() { if (length > widget.attachmentLimit) {
_attachments[attachment.id] = attachment.copyWith( final onAttachmentLimitExceed = widget.onAttachmentLimitExceed;
uploadState: attachment.uploadState, if (onAttachmentLimitExceed != null) {
return onAttachmentLimitExceed(
widget.attachmentLimit,
'Attachment Limit crossed ${widget.attachmentLimit}',
);
}
return _showErrorAlert(
'Attachment Limit crossed ${widget.attachmentLimit}',
); );
}); }
for (final attachment in attachments) {
_attachments[attachment.id] = attachment;
}
} }
/// Pick a file from the device /// Pick a file from the device
/// If [camera] is true then the camera will open /// If [camera] is true then the camera will open
// ignore: avoid_positional_boolean_parameters void pickFile(
void pickFile(DefaultAttachmentTypes fileType, [bool camera = false]) async { DefaultAttachmentTypes fileType, {
bool camera = false,
}) async {
setState(() => _inputEnabled = false); setState(() => _inputEnabled = false);
AttachmentFile? file; AttachmentFile? file;
@@ -1947,16 +1978,14 @@ class MessageInputState extends State<MessageInput> {
} }
} }
_attachments[attachment.id] = attachment;
setState(() { setState(() {
_attachments.update( _addAttachments([
attachment.id, attachment.copyWith(
(it) => it.copyWith( file: file,
file: file, extraData: {...attachment.extraData}
extraData: {...it.extraData} ..update('file_size', ((_) => file!.size!)),
..update('file_size', ((_) => file!.size!)), ),
)); ]);
}); });
} }
@@ -2005,7 +2034,7 @@ class MessageInputState extends State<MessageInput> {
/// Sends the current message /// Sends the current message
Future<void> sendMessage() async { Future<void> sendMessage() async {
var text = textEditingController.text.trim(); var text = _textEditingController.text.trim();
if (text.isEmpty && _attachments.isEmpty) { if (text.isEmpty && _attachments.isEmpty) {
return; return;
} }
@@ -2018,12 +2047,11 @@ class MessageInputState extends State<MessageInput> {
final attachments = [..._attachments.values]; final attachments = [..._attachments.values];
textEditingController.clear(); _textEditingController.clear();
_attachments.clear(); _attachments.clear();
widget.onQuotedMessageCleared?.call(); widget.onQuotedMessageCleared?.call();
setState(() { setState(() {
_messageIsPresent = false;
_commandEnabled = false; _commandEnabled = false;
}); });
@@ -2153,7 +2181,8 @@ class MessageInputState extends State<MessageInput> {
child: Text( child: Text(
context.translations.okLabel, context.translations.okLabel,
style: _streamChatTheme.textTheme.bodyBold.copyWith( style: _streamChatTheme.textTheme.bodyBold.copyWith(
color: _streamChatTheme.colorTheme.accentPrimary), color: _streamChatTheme.colorTheme.accentPrimary,
),
), ),
), ),
], ],
@@ -2164,13 +2193,8 @@ class MessageInputState extends State<MessageInput> {
} }
void _parseExistingMessage(Message message) { void _parseExistingMessage(Message message) {
textEditingController.text = message.text!; _textEditingController.text = message.text!;
_messageIsPresent = true; _addAttachments(message.attachments);
for (final attachment in message.attachments) {
_attachments[attachment.id] = attachment.copyWith(
uploadState: attachment.uploadState,
);
}
} }
@override @override
@@ -2196,54 +2220,6 @@ class MessageInputState extends State<MessageInput> {
} }
} }
/// Represents a 2-tuple, or pair.
class Tuple2<T1, T2> {
/// Creates a new tuple value with the specified items.
const Tuple2(this.item1, this.item2);
/// Create a new tuple value with the specified list [items].
factory Tuple2.fromList(List items) {
if (items.length != 2) {
throw ArgumentError('items must have length 2');
}
return Tuple2<T1, T2>(items[0] as T1, items[1] as T2);
}
/// Returns the first item of the tuple
final T1 item1;
/// Returns the second item of the tuple
final T2 item2;
/// Returns a tuple with the first item set to the specified value.
Tuple2<T1, T2> withItem1(T1 v) => Tuple2<T1, T2>(v, item2);
/// Returns a tuple with the second item set to the specified value.
Tuple2<T1, T2> withItem2(T2 v) => Tuple2<T1, T2>(item1, v);
/// Creates a [List] containing the items of this [Tuple2].
///
/// The elements are in item order. The list is variable-length
/// if [growable] is true.
List toList({bool growable = false}) =>
List.from([item1, item2], growable: growable);
@override
String toString() => '[$item1, $item2]';
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Tuple2 &&
runtimeType == other.runtimeType &&
item1 == other.item1 &&
item2 == other.item2;
@override
int get hashCode => item1.hashCode ^ item2.hashCode;
}
class _PickerWidget extends StatefulWidget { class _PickerWidget extends StatefulWidget {
const _PickerWidget({ const _PickerWidget({
Key? key, Key? key,
@@ -2281,74 +2257,74 @@ class _PickerWidgetState extends State<_PickerWidget> {
return const Offstage(); return const Offstage();
} }
return FutureBuilder<bool>( return FutureBuilder<bool>(
future: requestPermission, future: requestPermission,
builder: (context, snapshot) { builder: (context, snapshot) {
if (!snapshot.hasData) { if (!snapshot.hasData) {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
} }
if (snapshot.data!) { if (snapshot.data!) {
if (widget.containsFile) { if (widget.containsFile) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
widget.onAddMoreFilesClick(DefaultAttachmentTypes.file); widget.onAddMoreFilesClick(DefaultAttachmentTypes.file);
}, },
child: Container( child: Container(
constraints: const BoxConstraints.expand(), constraints: const BoxConstraints.expand(),
color: widget.streamChatTheme.colorTheme.inputBg, color: widget.streamChatTheme.colorTheme.inputBg,
alignment: Alignment.center, alignment: Alignment.center,
child: Text(
context.translations.addMoreFilesLabel,
style: TextStyle(
color: widget.streamChatTheme.colorTheme.accentPrimary,
fontWeight: FontWeight.bold,
),
),
),
);
}
return MediaListView(
selectedIds: widget.selectedMedias,
onSelect: widget.onMediaSelected,
);
}
return InkWell(
onTap: () async {
PhotoManager.openSetting();
},
child: Container(
color: widget.streamChatTheme.colorTheme.inputBg,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SvgPicture.asset(
'svgs/icon_picture_empty_state.svg',
package: 'stream_chat_flutter',
height: 140,
color: widget.streamChatTheme.colorTheme.disabled,
),
Text(
context.translations.enablePhotoAndVideoAccessMessage,
style: widget.streamChatTheme.textTheme.body.copyWith(
color: widget.streamChatTheme.colorTheme.textLowEmphasis),
textAlign: TextAlign.center,
),
const SizedBox(height: 6),
Center(
child: Text( child: Text(
context.translations.addMoreFilesLabel, context.translations.allowGalleryAccessMessage,
style: TextStyle( style: widget.streamChatTheme.textTheme.bodyBold.copyWith(
color: widget.streamChatTheme.colorTheme.accentPrimary, color: widget.streamChatTheme.colorTheme.accentPrimary,
fontWeight: FontWeight.bold,
), ),
), ),
), ),
); ],
}
return MediaListView(
selectedIds: widget.selectedMedias,
onSelect: widget.onMediaSelected,
);
}
return InkWell(
onTap: () async {
PhotoManager.openSetting();
},
child: Container(
color: widget.streamChatTheme.colorTheme.inputBg,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SvgPicture.asset(
'svgs/icon_picture_empty_state.svg',
package: 'stream_chat_flutter',
height: 140,
color: widget.streamChatTheme.colorTheme.disabled,
),
Text(
context.translations.enablePhotoAndVideoAccessMessage,
style: widget.streamChatTheme.textTheme.body.copyWith(
color:
widget.streamChatTheme.colorTheme.textLowEmphasis),
textAlign: TextAlign.center,
),
const SizedBox(height: 6),
Center(
child: Text(
context.translations.allowGalleryAccessMessage,
style: widget.streamChatTheme.textTheme.bodyBold.copyWith(
color: widget.streamChatTheme.colorTheme.accentPrimary,
),
),
),
],
),
), ),
); ),
}); );
},
);
} }
} }
@@ -340,3 +340,51 @@ Widget wrapAttachmentWidget(
type: MaterialType.transparency, type: MaterialType.transparency,
child: attachmentWidget, child: attachmentWidget,
); );
/// Represents a 2-tuple, or pair.
class Tuple2<T1, T2> {
/// Creates a new tuple value with the specified items.
const Tuple2(this.item1, this.item2);
/// Create a new tuple value with the specified list [items].
factory Tuple2.fromList(List items) {
if (items.length != 2) {
throw ArgumentError('items must have length 2');
}
return Tuple2<T1, T2>(items[0] as T1, items[1] as T2);
}
/// Returns the first item of the tuple
final T1 item1;
/// Returns the second item of the tuple
final T2 item2;
/// Returns a tuple with the first item set to the specified value.
Tuple2<T1, T2> withItem1(T1 v) => Tuple2<T1, T2>(v, item2);
/// Returns a tuple with the second item set to the specified value.
Tuple2<T1, T2> withItem2(T2 v) => Tuple2<T1, T2>(item1, v);
/// Creates a [List] containing the items of this [Tuple2].
///
/// The elements are in item order. The list is variable-length
/// if [growable] is true.
List toList({bool growable = false}) =>
List.from([item1, item2], growable: growable);
@override
String toString() => '[$item1, $item2]';
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Tuple2 &&
runtimeType == other.runtimeType &&
item1 == other.item1 &&
item2 == other.item2;
@override
int get hashCode => item1.hashCode ^ item2.hashCode;
}