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

freezed cannot recognize the type which is generated by freezed. #1101

Closed
Jaew00Shin opened this issue Jul 3, 2024 · 1 comment
Closed
Assignees
Labels
bug Something isn't working needs triage

Comments

@Jaew00Shin
Copy link

Jaew00Shin commented Jul 3, 2024

Describe the bug

import 'package:freezed_annotation/freezed_annotation.dart';

part 'voucher.freezed.dart';

@freezed
class Voucher with _$Voucher {
  const factory Voucher({
    @Default(0) int voucherId,
    @Default('') String name,
    @Default('') String thumbUrl,
    @Default(0) int value,
    @Default('') String brand,
  }) = _Voucher;

  const factory Voucher.stock({
    @Default(0) int voucherId,
    @Default('') String name,
    @Default('') String thumbUrl,
    @Default(0) int value,
    @Default('') String brand,
    @Default('') String link,
  }) = VoucherStock;
}

typedef VoucherList = List<Voucher>;
typedef VoucherStockList = List<VoucherStock>;

voucher.dart

part of 'my_voucher_cubit.dart';

@freezed
class MyVoucherState with _$MyVoucherState {
  const factory MyVoucherState.initial() = MyVoucherInitial;

  const factory MyVoucherState.success({
    @Default([]) VoucherStockList vouchers,
  }) = MyVoucherSuccess;

  const factory MyVoucherState.failure() = MyVoucherFailure;
}

my_voucher_state.dart

lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:84:19: Error: Type 'InvalidType' not found.
  $Res call({List<InvalidType> vouchers});
                  ^^^^^^^^^^^
lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:112:44: Error: Type 'InvalidType' not found.
  const _$MyVoucherSuccessImpl({final List<InvalidType> vouchers = const []})
                                           ^^^^^^^^^^^
lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:115:14: Error: Type 'InvalidType' not found.
  final List<InvalidType> _vouchers;
             ^^^^^^^^^^^
lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:118:8: Error: Type 'InvalidType' not found.
  List<InvalidType> get vouchers {
       ^^^^^^^^^^^
lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:150:46: Error: Type 'InvalidType' not found.
  const factory MyVoucherSuccess({final List<InvalidType> vouchers}) =
                                             ^^^^^^^^^^^
lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:153:8: Error: Type 'InvalidType' not found.
  List<InvalidType> get vouchers;
       ^^^^^^^^^^^
lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:84:19: Error: 'InvalidType' isn't a type.
  $Res call({List<InvalidType> vouchers});
                  ^^^^^^^^^^^
lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:104:23: Error: 'InvalidType' isn't a type.
              as List<InvalidType>,
                      ^^^^^^^^^^^
lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:112:44: Error: 'InvalidType' isn't a type.
  const _$MyVoucherSuccessImpl({final List<InvalidType> vouchers = const []})
                                           ^^^^^^^^^^^
lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:115:14: Error: 'InvalidType' isn't a type.
  final List<InvalidType> _vouchers;
             ^^^^^^^^^^^
lib/src/presentation/pages/my/voucher/cubits/my_voucher_cubit.freezed.dart:150:46: Error: 'InvalidType' isn't a type.
  const factory MyVoucherSuccess({final List<InvalidType> vouchers}) =
                                             ^^^^^^^^^^^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

This is my error log.

/// @nodoc
abstract class _$$MyVoucherSuccessImplCopyWith<$Res> {
  factory _$$MyVoucherSuccessImplCopyWith(_$MyVoucherSuccessImpl value,
          $Res Function(_$MyVoucherSuccessImpl) then) =
      __$$MyVoucherSuccessImplCopyWithImpl<$Res>;
  @useResult
  $Res call({List<InvalidType> vouchers});
}

This is part of my_voucher_cubit.freezed.dart

freezed_annotation: ^2.4.1
freezed: ^2.5.2

I'm using this version.

Expected behavior
I hope freezed to recognize the type which is generated by freezed.
my_voucher_cubit.freezed.dart file should recognize VoucherStock class.

@Jaew00Shin Jaew00Shin added bug Something isn't working needs triage labels Jul 3, 2024
@Jaew00Shin Jaew00Shin changed the title freezed generates InvalidType freezed cannot recognize the type which is generated by freezed. Jul 3, 2024
@rrousselGit
Copy link
Owner

Yes, this is a known issue and won't be fixed before macros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants