Skip to content

How to use with freezed unions? #103

@MiniSuperDev

Description

@MiniSuperDev

Hello,, when use freezed it generate only private classes and also expect other type in the model, for example instead of Union1 it expect _$Union1

Thank you

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:reactive_forms_annotations/reactive_forms_annotations.dart';

part 'freezed_union.freezed.dart';
part 'freezed_union.g.dart';
part 'freezed_union.gform.dart';

@freezed
class FreezedUnion with _$FreezedUnion {
  @ReactiveFormAnnotation()
  const factory FreezedUnion.union1({
    @FormControlAnnotation() required String text,
  }) = Union1;

  @ReactiveFormAnnotation()
  const factory FreezedUnion.union2({
    @FormControlAnnotation() required int number,
  }) = Union2;

  factory FreezedUnion.fromJson(Map<String, dynamic> json) =>
      _$FreezedUnionFromJson(json);
}

void main() {
  final form = _$Union1FormBuilder( // It should be public
    model: _$Union1(text: 'foo'), // It should be Union1
    builder: (_, __, ___) {
      return Container();
    },
  );
}
  reactive_forms_generator: ^1.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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