Skip to content

Freezed 3.2.3: Generated mixin getters compressed to single line causing compilation errors #1318

@bobhu2k

Description

@bobhu2k

Bug Description

Freezed 3.2.3 generates mixin code with all getters compressed on a single line, causing the Dart analyzer to fail recognizing these as implementations, resulting in missing abstract member errors.

Steps to Reproduce

  1. Create a simple Freezed model:
import 'package:freezed_annotation/freezed_annotation.dart';

part 'test_model.freezed.dart';
part 'test_model.g.dart';

@freezed
class TestModel with _$TestModel {
  const TestModel._();

  const factory TestModel({
    required String userId,
    required String deviceId,
    required String displayName,
  }) = _TestModel;

  factory TestModel.fromJson(Map<String, dynamic> json) => _$TestModelFromJson(json);
}
  1. Run code generation:
flutter pub run build_runner build --delete-conflicting-outputs
  1. Run analyzer:
flutter analyze

Expected Result

Generated mixin should have each getter on a separate line:

mixin _$TestModel {
  String get userId => throw _privateConstructorUsedError;
  String get deviceId => throw _privateConstructorUsedError;
  String get displayName => throw _privateConstructorUsedError;
  // ...
}

Actual Result

Freezed 3.2.3 compresses all getters on one line:

mixin _$TestModel {
 String get userId; String get deviceId; String get displayName;
  // ...
}

This causes compilation errors:

error • Missing concrete implementations of 'getter mixin _$TestModel on Object.deviceId',
'getter mixin _$TestModel on Object.displayName',
'getter mixin _$TestModel on Object.userId',
and 'mixin _$TestModel on Object.toJson'
• lib/test_model.dart:7:7 • non_abstract_class_inherits_abstract_member

Environment

  • Freezed: 3.2.3
  • freezed_annotation: 3.1.0
  • build_runner: 2.10.2 (also reproduced on 2.7.1)
  • Flutter SDK: 3.27.0
  • Dart SDK: 3.8.0+
  • OS: macOS Darwin 23.2.0

Dependency Versions

dependencies:
  freezed_annotation: 3.1.0

dev_dependencies:
  freezed: 3.2.3
  build_runner: 2.7.1 or 2.10.2
  json_serializable: 6.11.1

Workaround

Downgrading to Freezed 2.5.2 resolves the issue:

dependencies:
  freezed_annotation: 2.4.4
  json_annotation: 4.9.0

dev_dependencies:
  freezed: 2.5.2
  build_runner: 2.4.13
  json_serializable: 6.8.0

Note: Downgrading Freezed to 2.5.2 requires downgrading related dependencies due to source_gen version conflicts.

Verification

This issue reproduces in a clean Flutter project, confirming it's a Freezed 3.2.3 code generation bug, not a usage error.

Impact

This bug affects all @freezed classes with multiple fields using Freezed 3.2.3.


Is this issue already known? Is there a fix plan? We're happy to provide more information or test fixes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions