validateParameters static method
void
validateParameters({})
Validate the incoming parameters whether they would be valid for a mailto link.
In case the parameters don't pass validation, ArgumentError is thrown.
The Mailto class does not validate its fields neither at instatiation
nor when the toString method is called, so make sure that you either
know that the values are valid and the mailto links work on devices,
or call the validateParameters
function in an assert
call to catch
issues during development.
Implementation
static void validateParameters({
List<String>? to,
List<String>? cc,
List<String>? bcc,
String? subject,
String? body,
}) {
bool isEmptyString(String e) => e.isEmpty;
bool containsLineBreak(String e) => e.contains('\n');
if (to?.any(isEmptyString) == true) {
throw ArgumentError.value(
to,
'to',
'elements in "to" list must not be empty',
);
}
if (to?.any(containsLineBreak) == true) {
throw ArgumentError.value(
to,
'to',
'elements in "to" list must not contain line breaks',
);
}
if (cc?.any(isEmptyString) == true) {
throw ArgumentError.value(
cc,
'cc',
'elements in "cc" list must not be empty. ',
);
}
if (cc?.any(containsLineBreak) == true) {
throw ArgumentError.value(
cc,
'cc',
'elements in "cc" list must not contain line breaks',
);
}
if (bcc?.any(isEmptyString) == true) {
throw ArgumentError.value(
bcc,
'bcc',
'elements in "bcc" list must not be empty. ',
);
}
if (bcc?.any(containsLineBreak) == true) {
throw ArgumentError.value(
bcc,
'bcc',
'elements in "bcc" list must not contain line breaks',
);
}
if (subject?.contains('\n') == true) {
throw ArgumentError.value(
subject,
'subject',
'"subject" must not contain line breaks',
);
}
}