Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with freezed unions? #103

Open
MiniSuperDev opened this issue May 10, 2023 · 4 comments
Open

How to use with freezed unions? #103

MiniSuperDev opened this issue May 10, 2023 · 4 comments

Comments

@MiniSuperDev
Copy link

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
@vasilich6107
Copy link
Contributor

Hi @MiniSuperDev
Could you clarify the usecase for unions in describing form models?

@MiniSuperDev
Copy link
Author

Hi @vasilich6107
At the moment I have a notion type app, in which blocks of different types can be created.
In this case each type of block is a union class.

@MiniSuperDev
Copy link
Author

@vasilich6107 In freezed for example to make json_serializable works with union, each union class should have its own annotations

@vasilich6107
Copy link
Contributor

Hey @MiniSuperDev I probably realized the source of issue
Will try to fix some day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants