drift
drift copied to clipboard
Avoid name clashes in generated code
I am getting this error as I build the generated code:
@override
VerificationContext validateIntegrity(Insertable<Evento> instance,
{bool isInserting = false}) {
final context = VerificationContext();
final data = instance.toColumns(true);
if (data.containsKey('id')) {
context.handle(_idMeta, id.isAcceptableOrUnknown(data['id'], _idMeta));
}
if (data.containsKey('data')) {
context.handle(
_dataMeta, data.isAcceptableOrUnknown(data['data'], _dataMeta));
} else if (isInserting) {
context.missing(_dataMeta);
}
if (data.containsKey('mensagem')) {
context.handle(_mensagemMeta,
mensagem.isAcceptableOrUnknown(data['mensagem'], _mensagemMeta));
} else if (isInserting) {
context.missing(_mensagemMeta);
}
if (data.containsKey('tipo_id')) {
context.handle(_tipoIdMeta,
tipoId.isAcceptableOrUnknown(data['tipo_id'], _tipoIdMeta));
} else if (isInserting) {
context.missing(_tipoIdMeta);
}
return context;
}
Where "data.isAcceptableOrUnknown(data['data'], _dataMeta));" says The method is not defined for the type Map Shows a compiler error.
Using:
moor_flutter:
build_runner:
moor_generator:
Using also other Dependencies.
isAcceptableOrUnknown should be available since moor 3.0.
To get the resolved version of moor, can you check the .dart_tool/package_config.json file? There should be an entry having "name": "moor" and a rootUri like .../.pub-cache/hosted/pub.dartlang.org/moor-<version>.
Most likely, running flutter packages upgrade should fix the problem though.
Looks like it’s a collision with the variable named “data”
Good catch Mike, I overlook these issues all the time. @Beloin At the moment, I'd recommend to rename the data column to something else.
I'll integrate a mechanism into the generator to avoid name clashes for the future.
It worked! Thanks, I wasn't aware of the name conflict.