Flutter 应用程序:无法从方法中 return 类型 "Either<LeftType, RightType>" 的值,因为它具有 return 类型的 "Either<LeftType, RightType>"

Flutter app: Can't return value of type "Either<LeftType, RightType>" from method because it has a return type of "Either<LeftType, RightType>"

无法弄清楚这一点 - 特别是 VSCode 和 Android Studio 中的类型错误告诉我类型是相同的。

错误:

"A value of type 'Either<Failure, DailyThought> (where Failure is defined in ...lib\core\error\failures.dart)' can't be returned from method 'execute' because it has a return type of 'Either<Failure, DailyThought> (where Failure is defined in ...lib\core\error\failures.dart)'." 

版本:

Flutter 1.17.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b041144f83 (8 weeks ago) • 2020-06-04 09:26:11 -0700
Engine • revision ee76268252
Tools • Dart 2.8.4
dartz: ^0.9.1
equatable: ^1.2.3

在“execute”方法的 return 语句的 class 中出现 Dart 分析器错误:

import '.../features/daily_thought/domain/entities/daily_thought.dart';
import '.../features/daily_thought/domain/repositories/daily_thought_repository.dart';    
import '.../core/error/failures.dart';
import 'package:dartz/dartz.dart';

class GetLatestDailyThought {
  final DailyThoughtRepository repository;

  GetLatestDailyThought(this.repository);

  Future<Either<Failure, DailyThought>> execute() async {
    return await repository.getLatestDailyThought();  //ERROR
  }
}

失败class:

import 'package:equatable/equatable.dart';

abstract class Failure extends Equatable {
  Failure([List properties = const <dynamic>[]]);
}

DailyThought class:

import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import 'package:meta/meta.dart';

class DailyThought extends Equatable {
  final int id;
  final String dateOfThought;
  final String textOfThought;

  DailyThought({
    @required this.id,
    @required this.dateOfThought,
    @required this.textOfThought,
  });

  @override
  List<Object> get props => [id, dateOfThought, textOfThought];
}

回购 class:

import 'package:dartz/dartz.dart';
import '.../lib/core/error/failures.dart';
import 'package:pedros_daily_thought_app/features/daily_thought/domain/entities/daily_thought.dart';

abstract class DailyThoughtRepository {
  Future<Either<Failure, DailyThought>> getLatestDailyThought();
}

确定找到根本原因 - 发帖以防其他人遇到这种情况。

这个问题的原因是因为 repo 文件上的 import 语句以某种方式导入“failures.dart”,这与它在“usecase”和有问题的文件上的导入方式不同。

import 'file:///C:/code/.../core/error/failures.dart'

import 'package:../core/error/failures.dart';

对齐这些“包”选项和分析器很高兴