17 lines
423 B
Dart
17 lines
423 B
Dart
import 'package:dartz/dartz.dart';
|
|
import 'package:afterwork/core/errors/failures.dart';
|
|
|
|
class InputConverter {
|
|
Either<Failure, int> stringToUnsignedInteger(String str) {
|
|
try {
|
|
final integer = int.parse(str);
|
|
if (integer < 0) throw const FormatException();
|
|
return Right(integer);
|
|
} catch (e) {
|
|
return Left(InvalidInputFailure());
|
|
}
|
|
}
|
|
}
|
|
|
|
class InvalidInputFailure extends Failure {}
|