-1

无法弄清楚这一点 - 特别是 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();
}
4

1 回答 1

0

好的,找到了根本原因 - 以防万一发生在其他人身上。

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

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

对比

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

将这两个“包”选项对齐,分析器很高兴

于 2020-07-28T13:11:55.033 回答