feat: add step 5 page and update active stepper logic in poultry farm inspection

doc: some utils in core
This commit is contained in:
2025-11-22 14:12:21 +03:30
parent a47263d98e
commit 6be57e058c
20 changed files with 168 additions and 51 deletions

View File

@@ -2,12 +2,16 @@ import 'package:intl/intl.dart';
import 'package:persian_datetime_picker/persian_datetime_picker.dart';
extension XDateTime2 on DateTime {
get formattedJalaliDate {
/// Convert the date time to a Jalali date.
/// Example: DateTime(2025, 1, 1) -> '1404/01/01'
String get formattedJalaliDate {
final jalaliDate = Jalali.fromDateTime(this);
return "${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}";
}
get formattedYHMS {
/// Convert the date time to a YHMS date.
/// Example: DateTime(2025, 1, 1) -> '2025-01-01 00:00:00'
String get formattedYHMS {
return DateFormat('yyyy-MM-dd HH:mm:ss').format(this);
}
}

View File

@@ -1,14 +1,17 @@
import 'package:intl/intl.dart';
extension XNumExtension on num? {
/// Convert the number to a string with comma separator.
/// Example: 1000 -> '۱,۰۰۰'
String get separatedByCommaFa {
final formatter = NumberFormat('#,###', 'fa_IR');
return this == null ? '':formatter.format(this);
return this == null ? '' : formatter.format(this);
}
/// Convert the number to a string with comma separator.
/// Example: 1000 -> '1,000'
String get separatedByComma {
final formatter = NumberFormat('#,###', 'en_US');
return this == null ? '':formatter.format(this);
return this == null ? '' : formatter.format(this);
}
}

View File

@@ -2,49 +2,92 @@ import 'package:intl/intl.dart';
import 'package:persian_datetime_picker/persian_datetime_picker.dart';
extension XString on String? {
/// Convert the string to a number with comma separator.
/// Example: '1000' -> '1,000'
/// Example: '1000000' -> '1,000,000'
/// Example: '1000000000' -> '1,000,000,000'
String get separatedByComma {
final formatter = NumberFormat('#,###');
final number = num.tryParse(this ?? '');
return number != null ? formatter.format(number) : (this ?? '');
}
/// Clear the comma from the string.
/// Example: '1,000' -> '1000'
/// Example: '1,000,000' -> '1000000'
/// Example: '1,000,000,000' -> '1000000000'
String get clearComma {
return (this ?? '').replaceAll(RegExp(r'\D'), '');
}
/// Add the count extension to the string.
/// Example: '1' -> '1 قطعه'
/// Example: '10' -> '10 قطعه'
/// Example: '100' -> '100 قطعه'
String get addCountEXT {
return '$this قطعه';
}
/// Add the day extension to the string.
/// Example: '1' -> '1 روزه'
/// Example: '10' -> '10 روزه'
/// Example: '100' -> '100 روزه'
String get addDayEXT {
return '$thisروزه';
}
/// Add the kg extension to the string.
/// Example: '1' -> '1 کیلوگرم'
/// Example: '10' -> '10 کیلوگرم'
/// Example: '100' -> '100 کیلوگرم'
String get addKgFa {
return '${this ?? 0}کیلوگرم ';
}
/// Add the kg extension to the string.
/// Example: '1' -> '1 کیلوگرم'
/// Example: '10' -> '10 کیلوگرم'
/// Example: '100' -> '100 کیلوگرم'
String get addKgFaWithParentheses {
return '${this ?? 0} (کیلوگرم)';
}
/// Add the kg extension to the string.
/// Example: '1' -> '1 KG'
/// Example: '10' -> '10 KG'
/// Example: '100' -> '100 KG'
String get addKg {
return '$this KG';
}
/// Add the real extension to the string.
/// Example: '1' -> '1 ریال'
/// Example: '10' -> '10 ریال'
/// Example: '100' -> '100 ریال'
String get addReal {
return ' $this ریال';
}
/// Convert the string to a DateTime.
/// Example: '2025-01-01' -> DateTime(2025, 1, 1)
/// Example: '2025-01-01 12:00:00' -> DateTime(2025, 1, 1, 12, 0, 0)
DateTime get toDateTime => DateTime.parse(this ?? '');
/// Convert the string to a Jalali date.
/// Example: '2025/01/01' -> '1404-01-01'
/// Example: '2025-01-01' -> '1404-01-01'
/// Example: '2025-01-01 12:00:00' -> '1404-01-01 12:00:00'
String get formattedJalaliDate {
String tmp = (this != null && this!.contains("/")) ? this!.replaceAll("/", "-") : (this ?? "");
String tmp = (this != null && this!.contains("/"))
? this!.replaceAll("/", "-")
: (this ?? "");
final dateTime = DateTime.parse(tmp);
final jalaliDate = Jalali.fromDateTime(dateTime);
return "${jalaliDate.year}/${jalaliDate.month.toString().padLeft(2, '0')}/${jalaliDate.day.toString().padLeft(2, '0')}";
}
/// Convert the string to a Jalali date and time.
/// Example: '2025-01-01 12:00:00' -> Jalali(year: 1404, month: 1, day: 1, hour: 12, minute: 0, second: 0)
String get formattedJalaliDateYHMS {
final dateTime = DateTime.parse(this ?? '');
final jalaliDate = Jalali.fromDateTime(dateTime);
@@ -55,15 +98,35 @@ extension XString on String? {
return DateFormat('yyyy-MM-dd HH:mm:ss').format(toDateTime);
}
/// Convert the string to a Jalali date.
/// Example: '2025-01-01' -> Jalali(year: 1404, month: 1, day: 1)
/// Example: '2025-01-01 12:00:00' -> Jalali(year: 1404, month: 1, day: 1, hour: 12, minute: 0, second: 0)
Jalali get toJalali {
final dateTime = DateTime.parse(this ?? '');
return Jalali.fromDateTime(dateTime);
}
/// Get the version number from the string.
/// Example: '1.0.0' -> 100
/// Example: '1.0.0.0' -> 1000
int get versionNumber => int.parse(this?.replaceAll(".", '') ?? '0');
/// Check if the string is a valid version number.
/// Example: '۹' -> true
/// Example: '۱۲۳۴۵۶۷۸۹۰' -> true
/// Example: '1234567890' -> false
bool get isDifferentDigits {
final regex = RegExp(r'[۰-۹٠-٩]');
return regex.hasMatch(this ?? '');
}
/// Normalize the string to remove extra spaces and convert to lowercase.
/// Example: " Hello World " -> "hello world"
/// Example: "Hello World" -> "hello world"
/// Example: "hello world" -> "hello world"
/// Example: "HELLO WORLD" -> "hello world"
/// Example: "Hello World" -> "hello world"
/// Example: "Hello World" -> "hello world"
String? get normalize =>
this?.toLowerCase().trim().replaceAll(RegExp(r'\s+'), ' ');
}