addGetters method
void
addGetters()
Implementation
void addGetters() {
for (PropertyAccessorElement m in element.accessors) {
if (m.name[0] == '_' || !m.isGetter) {
continue;
}
buffer.writeln('');
final static = m.isStatic ? 'static ' : '';
final conditional = m.returnType.toString().contains('?') ? '' : '?';
buffer.writeln(' $static${m.returnType}$conditional _${m.name};');
buffer.writeln(' // ignore: non_constant_identifier_names');
buffer.writeln(' ${static}set ${_getName(m)}(${m.returnType} value) {');
buffer.writeln(' _${m.name} = value;');
buffer.writeln(' }');
if (singleton == null && !m.isStatic) {
buffer.writeln(' @override');
buffer.writeln(' // ignore: unnecessary_overrides');
}
final parent = m.isStatic ? element.name : 'super';
buffer.writeln(' $static$m => _${m.name} ?? $parent.${m.name};');
buffer.writeln('');
}
}