feat(ui, localization): Move attachment limit exceeded error to translations
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -10,6 +10,9 @@
|
|||||||
- `GalleryHeader`
|
- `GalleryHeader`
|
||||||
- `GalleryFooter`
|
- `GalleryFooter`
|
||||||
- `ThreadHeader`
|
- `ThreadHeader`
|
||||||
|
- Added `MessageInput.attachmentLimit` in order to limit the no. of attachments that can be sent with a single message.
|
||||||
|
- Added `MessageInput.onAttachmentLimitExceed` callback which will be called when the `attachmentLimit` is exceeded.
|
||||||
|
This will override the default error alert behaviour.
|
||||||
|
|
||||||
|
|
||||||
🔄 Changed
|
🔄 Changed
|
||||||
|
|||||||
@@ -304,6 +304,8 @@ abstract class Translations {
|
|||||||
|
|
||||||
/// The label for "Reply to message"
|
/// The label for "Reply to message"
|
||||||
String get replyToMessageLabel;
|
String get replyToMessageLabel;
|
||||||
|
|
||||||
|
String attachmentLimitExceedError(int limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default implementation of Translation strings for the stream chat widgets
|
/// Default implementation of Translation strings for the stream chat widgets
|
||||||
@@ -664,4 +666,8 @@ class DefaultTranslations implements Translations {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get replyToMessageLabel => 'Reply to Message';
|
String get replyToMessageLabel => 'Reply to Message';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String attachmentLimitExceedError(int limit) =>
|
||||||
|
'Attachment limit exceeded, limit: $limit';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,9 +263,12 @@ class MessageInput extends StatefulWidget {
|
|||||||
/// A callback for error reporting
|
/// A callback for error reporting
|
||||||
final ErrorListener? onError;
|
final ErrorListener? onError;
|
||||||
|
|
||||||
|
/// A limit for the no. of attachments that can be sent with a single message.
|
||||||
final int attachmentLimit;
|
final int attachmentLimit;
|
||||||
|
|
||||||
/// A callback for error reporting
|
/// A callback for when the [attachmentLimit] is exceeded.
|
||||||
|
///
|
||||||
|
/// This will override the default error alert behaviour.
|
||||||
final AttachmentLimitExceedListener? onAttachmentLimitExceed;
|
final AttachmentLimitExceedListener? onAttachmentLimitExceed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -1856,17 +1859,18 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
|
|
||||||
/// Adds an attachment to the [_attachments] map
|
/// Adds an attachment to the [_attachments] map
|
||||||
void _addAttachments(Iterable<Attachment> attachments) {
|
void _addAttachments(Iterable<Attachment> attachments) {
|
||||||
|
final limit = widget.attachmentLimit;
|
||||||
final length = _attachments.length + attachments.length;
|
final length = _attachments.length + attachments.length;
|
||||||
if (length > widget.attachmentLimit) {
|
if (length > limit) {
|
||||||
final onAttachmentLimitExceed = widget.onAttachmentLimitExceed;
|
final onAttachmentLimitExceed = widget.onAttachmentLimitExceed;
|
||||||
if (onAttachmentLimitExceed != null) {
|
if (onAttachmentLimitExceed != null) {
|
||||||
return onAttachmentLimitExceed(
|
return onAttachmentLimitExceed(
|
||||||
widget.attachmentLimit,
|
widget.attachmentLimit,
|
||||||
'Attachment Limit crossed ${widget.attachmentLimit}',
|
context.translations.attachmentLimitExceedError(limit),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return _showErrorAlert(
|
return _showErrorAlert(
|
||||||
'Attachment Limit crossed ${widget.attachmentLimit}',
|
context.translations.attachmentLimitExceedError(limit),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (final attachment in attachments) {
|
for (final attachment in attachments) {
|
||||||
|
|||||||
@@ -381,6 +381,10 @@ class NnStreamChatLocalizations extends GlobalStreamChatLocalizations {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get replyToMessageLabel => 'Reply to Message';
|
String get replyToMessageLabel => 'Reply to Message';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String attachmentLimitExceedError(int limit) =>
|
||||||
|
'Attachment limit exceeded, limit: $limit';
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
|
|||||||
@@ -357,4 +357,8 @@ class StreamChatLocalizationsEn extends GlobalStreamChatLocalizations {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get replyToMessageLabel => 'Reply to Message';
|
String get replyToMessageLabel => 'Reply to Message';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String attachmentLimitExceedError(int limit) =>
|
||||||
|
'Attachment limit exceeded, limit: $limit';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -362,4 +362,10 @@ class StreamChatLocalizationsEs extends GlobalStreamChatLocalizations {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get replyToMessageLabel => 'Responder al Mensaje';
|
String get replyToMessageLabel => 'Responder al Mensaje';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String attachmentLimitExceedError(int limit) {
|
||||||
|
// TODO: implement attachmentLimitExceedError
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -361,4 +361,10 @@ class StreamChatLocalizationsFr extends GlobalStreamChatLocalizations {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get replyToMessageLabel => 'Répondre au Message';
|
String get replyToMessageLabel => 'Répondre au Message';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String attachmentLimitExceedError(int limit) {
|
||||||
|
// TODO: implement attachmentLimitExceedError
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -356,4 +356,10 @@ class StreamChatLocalizationsHi extends GlobalStreamChatLocalizations {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get replyToMessageLabel => 'संदेश का जवाब';
|
String get replyToMessageLabel => 'संदेश का जवाब';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String attachmentLimitExceedError(int limit) {
|
||||||
|
// TODO: implement attachmentLimitExceedError
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,4 +358,10 @@ Il file è troppo grande per essere caricato. Il limite è di $limitInMB MB.''';
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get replyToMessageLabel => 'Rispondi al messaggio';
|
String get replyToMessageLabel => 'Rispondi al messaggio';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String attachmentLimitExceedError(int limit) {
|
||||||
|
// TODO: implement attachmentLimitExceedError
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ void main() {
|
|||||||
expect(localizations.ofText, isNotNull);
|
expect(localizations.ofText, isNotNull);
|
||||||
expect(localizations.fileText, isNotNull);
|
expect(localizations.fileText, isNotNull);
|
||||||
expect(localizations.replyToMessageLabel, isNotNull);
|
expect(localizations.replyToMessageLabel, isNotNull);
|
||||||
|
expect(localizations.attachmentLimitExceedError(3), isNotNull);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user