'Null' is not a subtype of type 'Future<Either<Failure, NumberTrivia>>'


I am implementing the flutter project in TDD Clean Architecture by following this video: https://www.youtube.com/watch?v=lPkWX8xFthE&t=1s

my code:

class MockNumberTriviaRepository extends Mock
    implements NumberTriviaRepository {}

void main() {
  late MockNumberTriviaRepository mockNumberTriviaRepository;
  late GetConcreteNumberTrivia usecase;

  setUp(() {
    mockNumberTriviaRepository = MockNumberTriviaRepository();
    usecase = GetConcreteNumberTrivia(mockNumberTriviaRepository);

  final tNumber = 1;
  final tNumberTrivia = NumberTrivia(text: 'test', number: 1);

    'should get trivia for the number from the repository',
    () async {
      when( mockNumberTriviaRepository.getConcreteNumberTrivia(1)).thenAnswer((_) async {
        return Right(tNumberTrivia);

      final result = await usecase.execute(number: 10);

      expect(result, Right(tNumberTrivia));

when running the test it always comes results as

package:number_trivia/features/number_trivia/domain/repositories/number_trivia_repository.dart 7:41  MockNumberTriviaRepository.getConcreteNumberTrivia
test\features\number_trivia\domain\usecases\get_concrete_number_trivia_test.dart 27:40               main.<fn>
test\features\number_trivia\domain\usecases\get_concrete_number_trivia_test.dart 25:5                main.<fn>

type 'Null' is not a subtype of type 'Future<Either<Failure, NumberTrivia>>'

it shows an error here:

abstract class NumberTriviaRepository{
  Future<Either<Failure, NumberTrivia>> getConcreteNumberTrivia(int number);
class GetConcreteNumberTrivia {
 final NumberTriviaRepository repository;


 Future<Either<Failure, NumberTrivia>> execute({required int number}) async {
   return await repository.getConcreteNumberTrivia(number);

Please give me some solution to move forward.


Here is the ResoCoder TDD Course null-safety version.

ResoCoder TDD Course (Null-safety)

Let me know if it helps.

Answered By – Thomas Viana

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *