Skip to content

FlutterFlow AI typed SDK generator creates circular struct references causing type inference failures #7226

Description

@bsill-txiq

Can we access your project?

  • I give permission for members of the FlutterFlow team to access and test my project for the sole purpose of investigating this issue.

Current Behavior

The typed SDK generator creates struct definitions with self-referencing fields that cause Dart's type inference to fail
with "circularity found during type inference" errors. These structs cannot be used in the DSL even though they work fine
in the FlutterFlow UI.

Actual Behavior

The generator creates structs with implicit typing that causes Dart's type inference to fail:

lib/flutterflow_project/schemas.dart:614:16: Error: Can't infer the type of 'event': circularity found during type
inference.
Specify the type explicitly.
static final event = ffai.StructHandle(
^^^^^

lib/flutterflow_project/schemas.dart:1169:16: Error: Can't infer the type of 'takeHomeLineItem': circularity found during
type inference.
Specify the type explicitly.
static final takeHomeLineItem = ffai.StructHandle(

Affected Structs

  1. takeHomeLineItem struct (schemas.dart:1169-1178)
    static final takeHomeLineItem = ffai.StructHandle(
    "TakeHomeLineItem",
    <String, ffai.DslType>{
    "amount": ffai.double_,
    "breakdown": ffai.listOf(Structs.takeHomeLineItem), // ⚠️ Self-reference
    "description": ffai.string,
    // ... other fields
    },
    description: ffai.generatedProjectStructDescription,
    );

Problem: The breakdown field references Structs.takeHomeLineItem before the takeHomeLineItem variable is fully
initialized, creating a circular dependency.

  1. event struct (schemas.dart:614+)
    static final event = ffai.StructHandle(
    "Event",
    <String, ffai.DslType>{
    // Contains fields that likely reference back to event or create circular dependency
    // ...
    },
    description: ffai.generatedProjectStructDescription,
    );

Expected Behavior

The typed SDK generator should handle recursive struct definitions by:

  1. Using explicit type annotations to break circularity
  2. Or restructuring the generated code to avoid type inference failures
  3. Allowing the struct to be used in DSL code

Steps to Reproduce

  1. Create a custom data type in FlutterFlow UI with a recursive field (e.g., a breakdown field that is a list of the same
    type)
  2. Run flutterflow ai refresh-context to regenerate typed SDK
  3. Attempt to compile with flutterflow ai test or dart run dsl/edit.dart --dry-run

Reproducible from Blank

  • The steps to reproduce above start from a blank project.

Bug Report Code (Required)

IT4WhfHl8YxgrsNA7rrtbcAwoDsvIjs9aIIzkMN+GAo3G5DvPLYPXPykP1doTcOiTFZYMFv8rGEx7vDIuNmeFOQHAzSBfIBT1LhbEhXKeGKnbLqVBoedPWpPP8ZNDkuV0raJmiQlOsB1dV4C312QFvCUcA3YJIT7PTISQ/L+DNn5s3eqAj+6Xn0Jg1ZSfCvr

Visual documentation

Components Affected

Two components try to use this struct (but with the wrong name):

  1. takeHomeLineItem component
  • File: lib/flutterflow_project/components/take_home_line_item.dart
  • Component key: Container_gck8pvoo
  • Issue: Line 18 tries to use Structs.takeHomeValue (which doesn't exist, should be Structs.takeHomeLineItem)
  • Double problem: Even if the name was correct, the struct itself won't compile due to circular reference
  1. taxLineItem component
  • File: lib/flutterflow_project/components/tax_line_item.dart
  • Component key: Container_oopeqngc
  • Issue: Line 18 tries to use Structs.takeHomeValue (which doesn't exist, should be Structs.takeHomeLineItem)
  • Double problem: Even if the name was correct, the struct itself won't compile due to circular reference

Why This Exists

This is a tree structure - each TakeHomeLineItem can have child items in its breakdown field, creating a hierarchical
breakdown of values. This is a legitimate and common data structure (like a file system or comment thread), but the typed
SDK generator doesn't handle the self-reference correctly.

In FlutterFlow UI: This works fine because the proto/backend handles recursive structures.

In local typed SDK: Fails because of Dart's type inference limitations with circular references.

Environment

- FlutterFlow AI SDK: Latest (as of 2026-06-16)
  - Project ID: sell-side-side-kick-ok52jn
  - Generated SDK location: lib/flutterflow_project/schemas.dart

Additional Information

Root Cause

Dart's type inference cannot resolve the type when:

  1. A variable is declared with final and type inference (no explicit type)
  2. The initializer references the variable being declared (directly or indirectly)

The generated code uses:
static final takeHomeLineItem = ffai.StructHandle(...) // ❌ Implicit type

When the map contains Structs.takeHomeLineItem, this creates circularity.

Suggested Fix

Option 1: Add explicit type annotation
static final ffai.StructHandle takeHomeLineItem = ffai.StructHandle(
"TakeHomeLineItem",
<String, ffai.DslType>{
"breakdown": ffai.listOf(Structs.takeHomeLineItem),
// ...
},
);

Option 2: Use late initialization
static late final takeHomeLineItem = ffai.StructHandle(
"TakeHomeLineItem",
<String, ffai.DslType>{
"breakdown": ffai.listOf(Structs.takeHomeLineItem),
// ...
},
);

Option 3: Two-phase initialization
// Phase 1: Declare all struct handles
static final takeHomeLineItem = ffai.StructHandle("TakeHomeLineItem", {});

// Phase 2: Wire up references (if StructHandle API supports mutation)
// ... set up fields including self-references

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions