NoSuchMethodError: getter 'stringValue' 在 null 上被调用并冻结

时间:2020-12-20 17:41:15

标签: flutter dart

我重新开始做一个我前段时间死了的项目,我通过我的 build_runner 遇到了这个错误,冻结了:

登录终端构建运行器详细:

[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>

我的锻炼冻结课:

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(),
        );
  }
}

我的问题是我无法确定在空值上调用了哪个方法(假设是 stringValue)。

您对如何前进有想法吗?

(我的颤振医生:

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)

感谢您的回答!

1 个答案:

答案 0 :(得分:2)

这似乎是冻结的 0.12.6 中的一个错误,因为我尝试降级到冻结的 0.12.5 并且它有效。

另外,github中还有一个open issue https://github.com/rrousselGit/freezed/issues/326