Skip to content

[firebase_data_connect]: generated Dart SDK fails to compile for nullable Int64 BigInt fields #18231

@mafreud

Description

@mafreud

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

firebase_data_connect / Data Connect generated Dart SDK

Which platforms are affected?

Flutter / Dart

Description

The Data Connect Dart SDK generator emits code that fails to compile when a nullable Int64 / PostgreSQL bigint field is included in generated result models.

The generated model has nullable public fields:

final BigInt? installationId;
final BigInt? checkRunId;

but toJson() calls a non-nullable serializer after a null check:

if (installationId != null) {
  json['installationId'] = bigIntToJson(installationId);
}
if (checkRunId != null) {
  json['checkRunId'] = bigIntToJson(checkRunId);
}

The generated helper expects a non-nullable BigInt:

String bigIntToJson(BigInt value) {
  return value.toString();
}

This does not compile because Dart does not promote public fields/getters from BigInt? to BigInt inside the null check.

A generated workaround that compiles is either:

json['installationId'] = bigIntToJson(installationId!);

or making the helper nullable-aware:

String? bigIntToJson(BigInt? value) {
  return value?.toString();
}

Reproducing the issue

Generate a Flutter Data Connect SDK for a schema/query that returns nullable bigint / Int64 fields, for example fields like:

installationId: Int64
checkRunId: Int64

Then run flutter analyze or build the Flutter app.

Expected behavior

The generated Dart SDK should compile without manual edits.

Actual behavior

The generated code fails to compile with errors like:

lib/generated/dataconnect/get_build_job.dart:181:45: Error: The argument type 'BigInt?' can't be assigned to the parameter type 'BigInt'.
 - 'BigInt' is from 'dart:core'.
      json['installationId'] = bigIntToJson(installationId);
                                            ^
lib/generated/dataconnect/get_build_job.dart:34:17: Context: 'installationId' refers to a public property so it couldn't be promoted.
See http://dart.dev/go/non-promo-public-field
  final BigInt? installationId;
                ^
lib/generated/dataconnect/get_build_job.dart:187:41: Error: The argument type 'BigInt?' can't be assigned to the parameter type 'BigInt'.
 - 'BigInt' is from 'dart:core'.
      json['checkRunId'] = bigIntToJson(checkRunId);
                                        ^
lib/generated/dataconnect/get_build_job.dart:36:17: Context: 'checkRunId' refers to a public property so it couldn't be promoted.
See http://dart.dev/go/non-promo-public-field
  final BigInt? checkRunId;
                ^

The same error appears in other generated files that include the same nullable BigInt fields.

Workaround

After SDK generation, manually change the generated helper from:

String bigIntToJson(BigInt value) {
  return value.toString();
}

to:

String? bigIntToJson(BigInt? value) {
  return value?.toString();
}

Firebase Core version

Not sure / not relevant to generator output.

Flutter Version

Flutter 3.41.x

Relevant Log Output

flutter analyze
# fails with BigInt? cannot be assigned to BigInt in generated Data Connect files

Flutter dependencies

The issue is in generated source code. The generated SDK imports package:firebase_data_connect/firebase_data_connect.dart.

Additional context and comments

This looks like a Dart generator nullability issue rather than a runtime Data Connect issue. The null check is not enough because the generated fields are public properties and therefore are not promoted by Dart.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions