Add TLS trick config options
This commit is contained in:
45
lib/core/model/range.dart
Normal file
45
lib/core/model/range.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'range.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class RangeWithOptionalCeil with _$RangeWithOptionalCeil {
|
||||
const RangeWithOptionalCeil._();
|
||||
|
||||
const factory RangeWithOptionalCeil({
|
||||
required int min,
|
||||
int? max,
|
||||
}) = _RangeWithOptionalCeil;
|
||||
|
||||
String format() => "$min${max != null ? "-$max" : ""}";
|
||||
|
||||
factory RangeWithOptionalCeil.fromString(String input) =>
|
||||
switch (input.split("-")) {
|
||||
[final String min] => RangeWithOptionalCeil(min: int.parse(min)),
|
||||
[final String min, final String max] => RangeWithOptionalCeil(
|
||||
min: int.parse(min),
|
||||
max: int.parse(max),
|
||||
),
|
||||
_ => throw Exception("Invalid range: $input"),
|
||||
};
|
||||
|
||||
static RangeWithOptionalCeil? tryParse(String input) {
|
||||
try {
|
||||
return RangeWithOptionalCeil.fromString(input);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RangeWithOptionalCeilJsonConverter
|
||||
implements JsonConverter<RangeWithOptionalCeil, String> {
|
||||
const RangeWithOptionalCeilJsonConverter();
|
||||
|
||||
@override
|
||||
RangeWithOptionalCeil fromJson(String json) =>
|
||||
RangeWithOptionalCeil.fromString(json);
|
||||
|
||||
@override
|
||||
String toJson(RangeWithOptionalCeil object) => object.format();
|
||||
}
|
||||
Reference in New Issue
Block a user