Add 'PC' device to routine

This commit is contained in:
mohammad
2025-05-27 09:54:21 +03:00
parent 64a29681de
commit 50fc5f9562
18 changed files with 1076 additions and 80 deletions

View File

@ -40,6 +40,7 @@ class CustomRoutinesTextbox extends StatefulWidget {
class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
late final TextEditingController _controller;
bool hasError = false;
String? errorMessage;
@ -55,29 +56,63 @@ class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
}
}
bool _isInitialized = false;
@override
void initState() {
super.initState();
int decimalPlaces = getDecimalPlaces(widget.stepIncreaseAmount);
double initialValue;
if (widget.initialValue != null &&
widget.initialValue is num &&
(widget.initialValue as num) == 0) {
initialValue = 0.0;
_initializeController();
}
void _initializeController() {
final decimalPlaces = getDecimalPlaces(widget.stepIncreaseAmount);
final dynamic initialValue = widget.initialValue;
double parsedValue;
if (initialValue is num) {
parsedValue = initialValue.toDouble();
} else if (initialValue is String) {
parsedValue = double.tryParse(initialValue) ?? widget.sliderRange.$1;
} else {
initialValue = double.tryParse(widget.displayedValue) ?? 0.0;
parsedValue = widget.sliderRange.$1;
}
_controller = TextEditingController(
text: initialValue.toStringAsFixed(decimalPlaces),
text: parsedValue.toStringAsFixed(decimalPlaces),
);
_isInitialized = true;
}
@override
void dispose() {
_controller.dispose();
super.dispose();
void didUpdateWidget(CustomRoutinesTextbox oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.initialValue != oldWidget.initialValue && _isInitialized) {
final decimalPlaces = getDecimalPlaces(widget.stepIncreaseAmount);
final dynamic initialValue = widget.initialValue;
double newValue;
if (initialValue is num) {
newValue = initialValue.toDouble();
} else if (initialValue is String) {
newValue = double.tryParse(initialValue) ?? widget.sliderRange.$1;
} else {
newValue = widget.sliderRange.$1;
}
final newValueText = newValue.toStringAsFixed(decimalPlaces);
if (_controller.text != newValueText) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_controller.text = newValueText;
_controller.selection =
TextSelection.collapsed(offset: _controller.text.length);
});
}
}
}
void _validateInput(String value) {
final doubleValue = double.tryParse(value);
if (doubleValue == null) {
@ -121,18 +156,6 @@ class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
}
}
@override
void didUpdateWidget(CustomRoutinesTextbox oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.initialValue != oldWidget.initialValue) {
if (widget.initialValue != null &&
widget.initialValue is num &&
(widget.initialValue as num) == 0) {
int decimalPlaces = getDecimalPlaces(widget.stepIncreaseAmount);
_controller.text = 0.0.toStringAsFixed(decimalPlaces);
}
}
}
void _correctAndUpdateValue(String value) {
final doubleValue = double.tryParse(value) ?? 0.0;
@ -227,9 +250,15 @@ class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
color: ColorsManager.blackColor,
),
keyboardType: TextInputType.number,
inputFormatters: widget.withSpecialChar == true
? [FilteringTextInputFormatter.digitsOnly]
: null,
inputFormatters: [
FilteringTextInputFormatter.allow(
widget.withSpecialChar
? RegExp(r'^-?\d*\.?\d{0,' +
decimalPlaces.toString() +
r'}$')
: RegExp(r'\d+'),
),
],
decoration: const InputDecoration(
border: InputBorder.none,
isDense: true,
@ -268,8 +297,9 @@ class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Wrap(
alignment: WrapAlignment.spaceBetween,
direction: Axis.horizontal,
children: [
Text(
'Min. ${widget.sliderRange.$1.toInt()}${widget.unit}',
@ -279,6 +309,9 @@ class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
fontWeight: FontWeight.w400,
),
),
const SizedBox(
width: 50,
),
Text(
'Max. ${widget.sliderRange.$2.toInt()}${widget.unit}',
style: context.textTheme.bodySmall?.copyWith(