Application propre sans erreurs. Bonne base sur laquelle repartir de zero en cas de soucis majeurs.
This commit is contained in:
16
lib/core/utils/input_converter.dart
Normal file
16
lib/core/utils/input_converter.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
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 {}
|
||||
Reference in New Issue
Block a user