I assume that Dart doesn't allow for both named and optional positional parameters. Am I correct in assuming this? Is there a way that I can create this function without having to use a named parameter for the second string?
Here is my function:
void log(Object? s,{ int priority = 1,LogType logType = LogType.misc,bool on = true}){
if (priority >= lowestDisplayedPriority && (activeLogs.contains(logType)) && on){
print('='+s.toString());
}
}
I want to turn the function into the following:
void log(Object? s,[Object? s2 = ''],{ int priority = 1,LogType logType = LogType.misc,bool on = true}){
if (priority >= lowestDisplayedPriority && (activeLogs.contains(logType)) && on){
print('='+s.toString());
if(s2 != ''){
print('='+s2.toString());
}
}
}
I get an error which says "Expected to find ')'."
My desired function's usage would be something like this:
log(A,B, priority : 2) or log(A, priority : 2)
log(A,B), how is it to know ifBis ans2or apriority?log(A,B, priority : 2)orlog(A, priority : 2)(A, B),Bis positional and not named and therefore would bes2. Unlike Python, parameters are positional or named, never both. Arguments for named parameters must always be named.