1

I'm using the Freezed package to create Objects. I want to disable the copyWith of a nested @Freezed Object. See the following example:

@freezed
class RenewLeaseState with _$RenewLeaseState {
  const factory RenewLeaseState({
    @Default(BlocScreenNavigator()) BlocScreenNavigator navigator,
  }) = _RenewLeaseState;
}

@Freezed(copyWith: false)
class BlocScreenNavigator with _$BlocScreenNavigator {
  const factory BlocScreenNavigator({
    @Default(RenewLeaseScreen.init) RenewLeaseScreen screen,
    @Default(false) bool isPop,
  }) = _BlocScreenNavigator;
}

My build fails since the RenewLeaseState generated object tries to call the copyWith function of BlocScreenNavigator, which is disabled.

lib/renew_lease/cubit/renew_lease_cubit.freezed.dart:56:3: Error: Type '$BlocScreenNavigatorCopyWith' not found.
$BlocScreenNavigatorCopyWith<$Res> get navigator;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/renew_lease/cubit/renew_lease_cubit.freezed.dart:116:3: Error: Type '$BlocScreenNavigatorCopyWith' not found.
$BlocScreenNavigatorCopyWith<$Res> get navigator {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/renew_lease/cubit/renew_lease_cubit.freezed.dart:142:3: Error: Type '$BlocScreenNavigatorCopyWith' not found.
$BlocScreenNavigatorCopyWith<$Res> get navigator;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/renew_lease/cubit/renew_lease_cubit.freezed.dart:117:12: Error: The method '$BlocScreenNavigatorCopyWith' isn't defined for the class '_$RenewLeaseStateCopyWithImpl<$Res>'.

  • '_$RenewLeaseStateCopyWithImpl' is from 'package:tenant_app/renew_lease/cubit/renew_lease_cubit.dart' ('lib/renew_lease/cubit/renew_lease_cubit.dart'). Try correcting the name to the name of an existing method, or defining a method named '$BlocScreenNavigatorCopyWith'. return $BlocScreenNavigatorCopyWith<$Res>(_value.navigator, (value) { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

FAILURE: Build failed with an exception.

I need to keep the nested Object copyWith disabled to force the user to assign its parameters.

Is it a Freezed issue? What is the workaround in that situation?

Update

There is an open issue on GitHub.

genericUser
  • 4,417
  • 1
  • 28
  • 73

0 Answers0