refactor: update text form field model to use dynamic value type, enhance condition evaluator for step index extraction, and improve SDK path formatting

This commit is contained in:
2026-01-07 15:57:01 +03:30
parent 17f8a2d79b
commit f25b8514cd
10 changed files with 568 additions and 1589 deletions

View File

@@ -0,0 +1,61 @@
import 'package:flutter/foundation.dart';
import 'package:rasadyar_core/core.dart';
class ConditionEvaluator {
static bool check(String? condition, RxMap<String, dynamic>? state) {
if (condition == null || condition.isEmpty) return true;
if (state == null) {
return condition.contains('activeStepperIndex == 0');
}
try {
if (condition.contains(' == ')) {
final parts = condition.split(' == ');
if (parts.length != 2) return true;
final key = parts[0].trim();
var expectedValue = parts[1].trim();
// Remove quotes
if ((expectedValue.startsWith("'") && expectedValue.endsWith("'")) ||
(expectedValue.startsWith('"') && expectedValue.endsWith('"'))) {
expectedValue = expectedValue.substring(1, expectedValue.length - 1);
}
final actualValue = state[key];
if (actualValue == null) {
if (key == 'activeStepperIndex' && expectedValue == '0') return true;
return false;
}
// Handle numeric comparison if possible
final expectedInt = int.tryParse(expectedValue);
if (expectedInt != null) {
if (actualValue is int) return actualValue == expectedInt;
if (actualValue is String) return int.tryParse(actualValue) == expectedInt;
}
return actualValue.toString() == expectedValue;
}
return true;
} catch (e) {
debugPrint('Error parsing condition: $e');
return false;
}
}
/// Extracts step index without using expensive RegExp in a loop if possible,
/// or at least centralizes the logic.
static int? extractStepIndex(String? condition) {
if (condition == null || !condition.contains('activeStepperIndex')) return null;
try {
final parts = condition.split(' == ');
if (parts.length == 2 && parts[0].trim() == 'activeStepperIndex') {
return int.tryParse(parts[1].trim());
}
} catch (_) {}
return null;
}
}

View File

@@ -0,0 +1,11 @@
import 'package:rasadyar_chicken/presentation/widget/sdui/model/sdui_widget.dart';
import 'package:rasadyar_chicken/presentation/widget/sdui/widgets/stepper/model/stepper_sdui_model.dart';
extension SDUIModelExtensions on SDUIWidgetModel {
// چک میکند آیا این ویجت استپر است؟
bool get isStepper => this.maybeWhen(stepper: (_, _, _, _) => true, orElse: () => false);
// دیتای استپر را برمی‌گرداند (اگر استپر باشد)
StepperSDUIModel? get stepperData =>
maybeWhen(stepper: (data, _, _, _) => data, orElse: () => null);
}