Moor: Avoid name clashes in generated code

Created on 2 Jun 2020  ·  4Comments  ·  Source: simolus3/moor

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.

enhancement generator

Most helpful comment

Looks like it’s a collision with the variable named “data”

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

apoleo88 picture apoleo88  ·  3Comments

omidraha picture omidraha  ·  3Comments

VadimOsovsky picture VadimOsovsky  ·  3Comments

felixjunghans picture felixjunghans  ·  4Comments

Ltei picture Ltei  ·  3Comments