NoSuchMethodError: The getter 'stringValue' was called on null with freezed

I started working again on a project I left for dead some time ago, and I run into this error through my build_runner with freezed :

Log terminal build runner verbose :

[WARNING] freezed:freezed on lib/3_domain/workout/workout.dart:
Error NoSuchMethodError: The getter 'stringValue' was called on null.
Receiver: null
Tried calling: stringValue
> [WARNING] freezed:freezed on lib/3_domain/workout/workout.dart:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1      FreezedGenerator._getConstructorRedirectedName (package:freezed/src/freezed_generator.dart:501:23)
<asynchronous suspension>
#2      FreezedGenerator._parseConstructorsNeedsGeneration (package:freezed/src/freezed_generator.dart:219:11)
<asynchronous suspension>
#3      FreezedGenerator.parseElement (package:freezed/src/freezed_generator.dart:76:41)
<asynchronous suspension>
#4      ParserGenerator.generate (package:freezed/src/parse_generator.dart:36:22)
<asynchronous suspension>
#5      _generate (package:source_gen/src/builder.dart:332:23)
<asynchronous suspension>
#6      Stream.toList.<anonymous closure> (dart:async/stream.dart)
<asynchronous suspension>

My workout freeze class :

import 'package:FitnessAI_MobileApp/3_domain/core/failures.dart';
import 'package:FitnessAI_MobileApp/3_domain/core/value_object.dart';
import 'package:FitnessAI_MobileApp/3_domain/workout/workout_value_objects.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'workout.freezed.dart';

@freezed
abstract class Workout implements _$Workout {
  const Workout._();

  const factory Workout({
    @required UniqueId id,
    @required ExerciseList exerciseList,
    @required WorkoutType workoutType,
    //@required List3<TodoItem> todos,
  }) = _Workout;

  /// Empty constructor of any new note
  factory Workout.empty() => Workout(
        id: UniqueId(),
        exerciseList: ExerciseList.empty(),
        workoutType: WorkoutType.init(),
      );

  Option<ValueFailure<dynamic>> get failureOption {
    Option<ValueFailure<dynamic>> exerciseFailureOption;

    if (exerciseList
        .getOrCrash()
        .map(
          (exercise) => exercise.failureOption,
        )
        .where((o) => o.isSome())
        .toList()
        .isEmpty) {
      exerciseFailureOption = none();
    } else {
      exerciseFailureOption = exerciseList
          .getOrCrash()
          .map(
            (exercise) => exercise.failureOption,
          )
          .where((o) => o.isSome())
          .toList()[0];
    }

    return workoutType.failureOrUnit
        .andThen(
          exerciseFailureOption.fold(
            () => right(unit),
            (f) => left(f),
          ),
        )
        .fold(
          (f) => some(f),
          (_) => none(),
        );
  }
}

My problem is that I cannot pinpoint which method (assumingly stringValue) is called on a null value.

Would you have ideas on how to move forward?

(My flutter doctor :

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.26.0-2.0.pre.86, on Mac OS X 10.15.7 19H15 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.52.1)
[✓] Connected device (1 available)

Thanks for your answers!

Upvotes: 0

Views: 921

Answers (1)

Balaji Venkatraman
Balaji Venkatraman

Reputation: 1337

It seems to be a bug in freezed 0.12.6 since I tried to downgrade to freezed 0.12.5 and it works.

Also, there is an open issue in github https://github.com/rrousselGit/freezed/issues/326

Upvotes: 2

Related Questions