0

I'm trying to do some tests on my project in clean architecture using Dartz:

My entity class:

// ignore_for_file: public_member_api_docs, sort_constructors_first

class User {
  final String fullname;
  final String email;
  final String password;
  final String cpf;
  final int phone;
  final String city;
  final String objectId;
  final String token;
  final String responsibility;
  User({
    required this.fullname,
    required this.email,
    required this.password,
    required this.cpf,
    required this.phone,
    required this.city,
    required this.objectId,
    required this.token,
    required this.responsibility,
  })
}

My UserCase class:

abstract class SingIn {
  Future<Either<Exception, User>> call(
      {required String email, required String password});
}

class SingInImpl implements SingIn {
  @override
  Future<Either<Exception, User>> call(
      {required String email, required String password}) async {}
}

My Test class:

void main() {
  final signIn = SingInImpl();
  test('Deve retornar um Usuario', () async {
    final result =
        await signIn.call(email: 'xxxxxxx@xxxx.com', password: 'xxxxx');

    expect(result, isA<Right>());
    expect(result.getOrElse(() => null), isA<User>());
  });
}

My User case class gives me the following error:

The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr<Either<Exception, User>>', is a potentially non-nullable type.
Try adding either a return or a throw statement at the end.dartbody_might_complete_normally.

And my Test class:

The return type 'Null' isn't a 'User', as required by the closure's context.

My User case class causes the following error:

The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr<Either<Exception, User>>', is a potentially non-nullable type.

Try adding either a return or a throw statement at the end.dartbody_might_complete_normally

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Null safety in dartz was added after the original design. I suggest you use fpdart instead, which was developed *after* null safety, and is far better documented and still being actively developed. – Randal Schwartz Feb 03 '23 at 20:07

0 Answers0