flutter-tdd-clean-architecture-course icon indicating copy to clipboard operation
flutter-tdd-clean-architecture-course copied to clipboard

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

Open nazrinharris opened this issue 4 years ago • 4 comments

I just changed a few things here and there and I encountered this weird problem and solution.

Full details here :- https://stackoverflow.com/questions/67443531/flutter-using-async-in-testing-produces-an-error-but-using-async-made-it-work

nazrinharris avatar May 08 '21 02:05 nazrinharris

If you're using Flutter 2:

  • Upgrade dartz to ns prerelease: 0.10.0-nullsafety.2
  • And replace mockito with mocktail.

robsonsilv4 avatar May 11 '21 18:05 robsonsilv4

I found the solution, which is suprising easy and I'm stupid. I havent tried using mocktail yet but using mockito is still perfectly fine as well. I just didnt generate Mock classes as stated in the mockito docs to support null safety. I also explained in the stackoverflow posts

nazrinharris avatar May 15 '21 00:05 nazrinharris

This problem is about the Mockito version (not null safety). Upgrade your version to ^5.0.0. More about Mockito and null safety you can read here (Mockito - NULL_SAFETY_README)

You can try mocktail as well, the example below.

  when(() => mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber))
    .thenAnswer((_) async => Right(tNumberTrivia));

    final result = await usecase.execute(number: tNumber);
    expect(result, equal(Right(tNumberTrivia)));
    verify(() => mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber));
    verifyNoMoreInteractions(mockNumberTriviaRepository);

nanjadev avatar May 30 '21 04:05 nanjadev

The problem related with null-safety. I faced the same problem and later on I fixed. You can check it

erncncbk avatar Sep 14 '21 14:09 erncncbk