feat: add CopyFunc to provider generator; add local solution provider; update dde data table style.

This commit is contained in:
2021-10-08 18:29:06 +08:00
parent e819ba46e0
commit 094d74b746
12 changed files with 272 additions and 115 deletions
+3 -1
View File
@@ -1,5 +1,7 @@
class ProviderModel {
const ProviderModel();
const ProviderModel({this.copyable = false});
final bool copyable;
}
class ProviderModelProp {
+12
View File
@@ -37,6 +37,7 @@ class ProviderGenerator extends GeneratorForAnnotation<ProviderModel> {
_genImports(className, needImports),
_genClassDefine(element.displayName),
_genNamedConstructors(element.constructors, element.displayName),
_genCopyFunc(element.displayName, fields, annotation.read('copyable').boolValue),
_genSetPropsFunc(fields),
].whereNotNull();
}
@@ -71,6 +72,17 @@ String? _genNamedConstructors(List<ConstructorElement> constructors, String disp
return _constructors.length > 0 ? _constructors.join('\n') : null;
}
String? _genCopyFunc(String displayName, List<AnnotationField> fields, bool copyable) {
if (!copyable) return null;
return '''
void copyFrom(${displayName} other) {
bool changed = false;
${fields.map((f) => 'if (other.${f.name}.diff(this.${f.name})) {this.${f.name} = other.${f.name}; changed = true; }').join('\n')}
if (changed) notifyListeners();
}
''';
}
String _genSetPropsFunc(List<AnnotationField> fields) => '''
void setProps({
${fields.map((f) => '${f.type.endsWith('?') ? '' : 'required '}${f.type} ${f.name},').join('\n')}