0

After upgrading my Flutter, Freezed appears to generate files that have errors in them for my Bloc/Cubit files.

Pubspec.yaml has all the latest versions for the packages.

part of 'test_cubit.dart';

@freezed
abstract class TestState with _$TestState {
  const factory TestState.initial() = _Initial;
  const factory TestState.loaded(String someValue) = _Loaded;
}

Would be generated as (only excerpt where error occurs)

/// @nodoc
class _$TestStateTearOff {
  const _$TestStateTearOff();

_Initial initial() {
  return const  _Initial();
}
_Loaded loaded( String* someValue) {
  return  _Loaded(someValue,);
}

}

Image of the errors

enter image description here

When I delete the * it all works just fine. Can anyone shed some light on this please?

Pieter
  • 2,188
  • 20
  • 27

1 Answers1

1

This was answered on GitHub in the end. The issue was identified after running a check to ensure the the application was fully migrated to null-safety.

$ dart pub upgrade --null-safety
null-safety compatible versions do not exist for:
 - build_runner

When running flutter pub run build_runner build it yielded an error

Error: Cannot run with sound null safety, because the following dependencies don't support null safety:

 - package:build_runner_core
 - package:build_runner
 - package:build_config
 - package:build_daemon
 - package:code_builder

After editing the pubspec.yaml and setting a higher environment it worked. This was not automatically done as part of the upgrade (or new applications).

environment:
  sdk: ">=2.12.0-0 <3.0.0"
Pieter
  • 2,188
  • 20
  • 27
  • Ahh... Weird. I never had to run that command. I just changed my sdk version and it worked for me. – rkdupr0n Apr 03 '21 at 11:30
  • 1
    @rkdupr0n I missed updating my SDK in the yaml file (I presumed it was changed as part of the upgrade) and those commands pointed at what was causing the issue. – Pieter Apr 03 '21 at 14:58