generateGettersAndSetters method
void
generateGettersAndSetters(
- StringBuffer strBuffer,
- FieldInfo field,
- bool onlyModifier,
- bool toggleMethodForBoolValues,
Implementation
void generateGettersAndSetters(StringBuffer strBuffer, FieldInfo field,
bool onlyModifier, bool toggleMethodForBoolValues) {
final name = field.name;
final valueStr = field.valueStr;
final typeFirstUpperCase =
field.type[0].toUpperCase() + field.type.substring(1);
final type = field.isStringList ? "NotifiableStringList" : field.type;
if (onlyModifier) {
strBuffer.writeln('$type? _\$$name;');
} else if (field.isStringList) {
strBuffer.writeln(
"/// **IMPORTANT**: if possible set this to a variable and modify it through the variable!");
}
final prefHelper = onlyModifier ? "_\$$name ?? " : "";
final suffHelper = onlyModifier ? ", (_) => _\$$name = val" : "";
final nameFirstUpperCase = name[0].toUpperCase() + name.substring(1);
final setterName = "set${nameFirstUpperCase}Async";
if (field.isEnum) {
strBuffer.writeln(
'$type get $name => $prefHelper _helper.getEnum(_keys.$name, $type.values, $valueStr);');
strBuffer.writeln(
'Future $setterName($type val) => _helper.setInt(_keys.$name, val.index $suffHelper);');
strBuffer.writeln('set $name($type val) => $setterName(val);');
} else {
strBuffer.writeln(
'$type get $name => $prefHelper _helper.get$typeFirstUpperCase(_keys.$name, $valueStr);');
strBuffer.writeln(
'Future $setterName($type val) => _helper.set$typeFirstUpperCase(_keys.$name, val $suffHelper);');
strBuffer.writeln('set $name($type val) => $setterName(val);');
if (type == "bool" && toggleMethodForBoolValues) {
final nameFirstUpperCase = name[0].toUpperCase() + name.substring(1);
final suffHelper2 = suffHelper.replaceFirst("(_)", "(val)");
strBuffer.writeln(
'$type toggle$nameFirstUpperCase() => _helper.toggleBool(_keys.$name, $valueStr $suffHelper2);');
}
}
strBuffer.writeln();
}