drift icon indicating copy to clipboard operation
drift copied to clipboard

Avoid name clashes in generated code

Open Beloin opened this issue 5 years ago • 4 comments

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.

Beloin avatar Jun 02 '20 14:06 Beloin

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.

simolus3 avatar Jun 02 '20 18:06 simolus3

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

Mike278 avatar Jun 02 '20 20:06 Mike278

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.

simolus3 avatar Jun 02 '20 20:06 simolus3

It worked! Thanks, I wasn't aware of the name conflict.

Beloin avatar Jun 03 '20 15:06 Beloin