无法弄清楚这一点 - 特别是 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
在“执行”方法的返回语句中,此类中发生 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
}
}
故障等级:
import 'package:equatable/equatable.dart';
abstract class Failure extends Equatable {
Failure([List properties = const <dynamic>[]]);
}
DailyThought类:
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];
}
回购类:
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();
}