有可能有人可以向我解释这里发生了什么。我对颤振和飞镖编程完全陌生,我已经在 youtube 上开始了一个使用 DDD 架构的视频教程,但我猜该教程没有使用该null safety
功能附带的新版本颤振,并猜测这可能是测试的原因没有通过。我只是按照教程中的方式进行操作,唯一的区别是类名以及颤振和飞镖版本。
测试输出
The argument type 'Null' can't be assigned to the parameter type 'AccountType Function()'.
代码
import 'package:dartz/dartz.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:matcher/matcher.dart' as matcher;
void main() {
group('AccountType', () {
test('Should return Failure when the value is empty', () {
// arrange
var accountType = AccountType.create('')
.fold((err) => err, (accountType) => accountType);
// assert
expect(accountType, matcher.TypeMatcher<Failure>());
});
test('Should create accountType when value is not empty', () {
// arrange
String str = 'sender';
AccountType accountType = AccountType.create(str).getOrElse(null); <--- Here where the test fails.
// assert
expect(accountType.value, 'sender');
});
});
}
class AccountType extends Equatable {
final String? value;
AccountType._(this.value);
static Either<Failure, AccountType> create(String? value) {
if (value!.isEmpty) {
return Left(Failure('Account type can not be empty'));
} else {
return Right(AccountType._(value));
}
}
@override
List<Object?> get props => [value];
}
class Failure {
final String? message;
Failure(this.message);
}