feat: create task with advanced options (#157)

This commit is contained in:
Levi authored and GitHub committed 2023-07-19 22:52:51 +08:00
1 parent eb79dd5ac5
commit 7376e85895
22 files changed
+357 -136

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
import 'package:flutter/services.dart';
/// A [TextInputFormatter] that restricts input to a numerical range between [min] and [max].
class NumericalRangeFormatter extends TextInputFormatter {
final int min;
final int max;
NumericalRangeFormatter({required this.min, required this.max});
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
if (newValue.text.isEmpty) {
return newValue;
}
var intVal = int.tryParse(newValue.text);
if (intVal == null) {
return oldValue;
}
if (intVal < min) {
return newValue.copyWith(text: min.toString());
} else if (intVal > max) {
return oldValue.copyWith(text: max.toString());
} else {
return newValue;
}
}
}