diff --git a/.github/workflows/base.yaml b/.github/workflows/base.yaml index 34f674d3..3267345c 100644 --- a/.github/workflows/base.yaml +++ b/.github/workflows/base.yaml @@ -1,12 +1,12 @@ -name: Base +name: CI & CD on: workflow_dispatch: - + push: branches: [main] tags: - - '[0-9]+.[0-9]+.[0-9]+*' + - "[0-9]+.[0-9]+.[0-9]+*" pull_request: branches: [main] @@ -18,10 +18,14 @@ concurrency: jobs: build: + name: Build package & run tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 # Use shallow clone for faster checkout - name: Check broken links uses: JustinBeckwith/linkinator-action@v1 @@ -32,13 +36,15 @@ jobs: uses: kuhnroyal/flutter-fvm-config-action@v2 id: fvm-config-action with: - path: '.fvmrc' - flavor: 'stable' + path: ".fvmrc" + flavor: "stable" - - uses: subosito/flutter-action@v2 + - name: Set up Flutter + uses: subosito/flutter-action@v2 with: flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }} channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }} + architecture: x64 cache: true - name: Install dependencies @@ -48,9 +54,8 @@ jobs: run: flutter gen-l10n - name: Run l10n on example - run: | - cd example - flutter gen-l10n + run: flutter gen-l10n + working-directory: example - name: Format code run: dart format --set-exit-if-changed $(find . -name "*.dart" ! \( -wholename "./lib/localization/intl/*" -or -wholename "./example/lib/localization/intl/*" \)) @@ -59,16 +64,11 @@ jobs: run: dart analyze - name: Run tests - run: flutter test --coverage + run: flutter test --no-pub --coverage - name: Check publish warnings run: dart pub publish --dry-run - - name: Build example - run: | - cd example - flutter build appbundle --debug - - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 env: @@ -78,23 +78,74 @@ jobs: flags: unittests name: form_builder_validators + example: + name: Build example app + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 # Use shallow clone for faster checkout + + - name: Get Flutter version by FVM + uses: kuhnroyal/flutter-fvm-config-action@v2 + id: fvm-config-action + with: + path: ".fvmrc" + flavor: "stable" + + - name: Set up Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }} + channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }} + architecture: x64 + cache: true + + - name: Install dependencies + run: dart pub get + + - name: Run l10n + run: flutter gen-l10n + + - name: Run l10n on example + run: flutter gen-l10n + working-directory: example + + - name: Build example + run: flutter build appbundle --debug + working-directory: example + deployment: if: ${{ github.ref_type == 'tag' }} - needs: build + needs: [build, example] name: Deploy package permissions: id-token: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 # Use shallow clone for faster checkout + + - name: Set up Dart + uses: dart-lang/setup-dart@v1 - - uses: dart-lang/setup-dart@v1 + - name: Get Flutter version by FVM + uses: kuhnroyal/flutter-fvm-config-action@v2 + id: fvm-config-action + with: + path: ".fvmrc" + flavor: "stable" - - name: Flutter action + - name: Set up Flutter uses: subosito/flutter-action@v2 with: - channel: 'stable' - # use the build-in cache from Subosito + flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }} + channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }} + architecture: x64 cache: true - name: Install dependencies @@ -105,4 +156,3 @@ jobs: - name: Publish package run: dart pub publish -v -f - diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aca38ff..64ff661d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 11.0.1 + +- Align between validator input types with other validators + ## 11.0.0 - Split up validators into smaller pieces diff --git a/lib/l10n/intl_ar.arb b/lib/l10n/intl_ar.arb index 143ae8e5..0db04f6e 100644 --- a/lib/l10n/intl_ar.arb +++ b/lib/l10n/intl_ar.arb @@ -84,5 +84,7 @@ "dunsErrorText": "يجب أن تكون القيمة رقم DUNS صالح.", "licensePlateErrorText": "يجب أن تكون القيمة لوحة ترخيص صالحة.", "vinErrorText": "يجب أن تكون القيمة رقم VIN صالح.", - "languageCodeErrorText": "يجب أن تكون القيمة رمز لغة صالح." + "languageCodeErrorText": "يجب أن تكون القيمة رمز لغة صالح.", + "floatErrorText": "يجب أن تكون القيمة رقم عشري صالح.", + "hexadecimalErrorText": "يجب أن تكون القيمة رقم سداسي عشري صالح." } \ No newline at end of file diff --git a/lib/l10n/intl_bg.arb b/lib/l10n/intl_bg.arb index f66768f9..dfa0b669 100644 --- a/lib/l10n/intl_bg.arb +++ b/lib/l10n/intl_bg.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Стойността трябва да бъде валиден DUNS номер.", "licensePlateErrorText": "Стойността трябва да бъде валиден регистрационен номер.", "vinErrorText": "Стойността трябва да бъде валиден VIN.", - "languageCodeErrorText": "Стойността трябва да бъде валиден езиков код." + "languageCodeErrorText": "Стойността трябва да бъде валиден езиков код.", + "floatErrorText": "Стойността трябва да бъде валидно число с плаваща запетая.", + "hexadecimalErrorText": "Стойността трябва да бъде валиден шестнадесетичен номер." } \ No newline at end of file diff --git a/lib/l10n/intl_bn.arb b/lib/l10n/intl_bn.arb index 3263c403..617db002 100644 --- a/lib/l10n/intl_bn.arb +++ b/lib/l10n/intl_bn.arb @@ -84,5 +84,7 @@ "dunsErrorText": "মানটি একটি বৈধ DUNS নম্বর হতে হবে।", "licensePlateErrorText": "মানটি একটি বৈধ লাইসেন্স প্লেট হতে হবে।", "vinErrorText": "মানটি একটি বৈধ VIN হতে হবে।", - "languageCodeErrorText": "মানটি একটি বৈধ ভাষা কোড হতে হবে।" + "languageCodeErrorText": "মানটি একটি বৈধ ভাষা কোড হতে হবে।", + "floatErrorText": "মান একটি বৈধ ভাসমান বিন্দু সংখ্যা হতে হবে।", + "hexadecimalErrorText": "মান একটি বৈধ হেক্সাডেসিমাল সংখ্যা হতে হবে।" } \ No newline at end of file diff --git a/lib/l10n/intl_bs.arb b/lib/l10n/intl_bs.arb index 5d4d4f36..4ca3a8ce 100644 --- a/lib/l10n/intl_bs.arb +++ b/lib/l10n/intl_bs.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Vrijednost mora biti ispravan DUNS broj.", "licensePlateErrorText": "Vrijednost mora biti ispravna registarska tablica.", "vinErrorText": "Vrijednost mora biti ispravan VIN.", - "languageCodeErrorText": "Vrijednost mora biti ispravan kod jezika." + "languageCodeErrorText": "Vrijednost mora biti ispravan kod jezika.", + "floatErrorText": "Vrijednost mora biti ispravan broj s pomičnim zarezom.", + "hexadecimalErrorText": "Vrijednost mora biti ispravan heksadecimalni broj." } \ No newline at end of file diff --git a/lib/l10n/intl_ca.arb b/lib/l10n/intl_ca.arb index 0c38a6cf..a173dba7 100644 --- a/lib/l10n/intl_ca.arb +++ b/lib/l10n/intl_ca.arb @@ -84,5 +84,7 @@ "dunsErrorText": "El valor ha de ser un número DUNS vàlid.", "licensePlateErrorText": "El valor ha de ser una matrícula vàlida.", "vinErrorText": "El valor ha de ser un VIN vàlid.", - "languageCodeErrorText": "El valor ha de ser un codi de llengua vàlid." + "languageCodeErrorText": "El valor ha de ser un codi de llengua vàlid.", + "floatErrorText": "El valor ha de ser un nombre de coma flotant vàlid.", + "hexadecimalErrorText": "El valor ha de ser un nombre hexadecimal vàlid." } \ No newline at end of file diff --git a/lib/l10n/intl_cs.arb b/lib/l10n/intl_cs.arb index 01f1bed1..d748d5d0 100644 --- a/lib/l10n/intl_cs.arb +++ b/lib/l10n/intl_cs.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Hodnota musí být platné číslo DUNS.", "licensePlateErrorText": "Hodnota musí být platná poznávací značka.", "vinErrorText": "Hodnota musí být platný VIN.", - "languageCodeErrorText": "Hodnota musí být platný kód jazyka." + "languageCodeErrorText": "Hodnota musí být platný kód jazyka.", + "floatErrorText": "Hodnota musí být platné desetinné číslo.", + "hexadecimalErrorText": "Hodnota musí být platné šestnáctkové číslo." } \ No newline at end of file diff --git a/lib/l10n/intl_da.arb b/lib/l10n/intl_da.arb index 7fc1ba34..7749fdd7 100644 --- a/lib/l10n/intl_da.arb +++ b/lib/l10n/intl_da.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Værdien skal være et gyldigt DUNS-nummer.", "licensePlateErrorText": "Værdien skal være en gyldig nummerplade.", "vinErrorText": "Værdien skal være en gyldig VIN.", - "languageCodeErrorText": "Værdien skal være en gyldig sprogkode." + "languageCodeErrorText": "Værdien skal være en gyldig sprogkode.", + "floatErrorText": "Værdien skal være et gyldigt flydende punkt nummer.", + "hexadecimalErrorText": "Værdien skal være et gyldigt hexadecimalt nummer." } \ No newline at end of file diff --git a/lib/l10n/intl_de.arb b/lib/l10n/intl_de.arb index 65b72c26..76b4b4dd 100644 --- a/lib/l10n/intl_de.arb +++ b/lib/l10n/intl_de.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Der Wert muss eine gültige DUNS-Nummer sein.", "licensePlateErrorText": "Der Wert muss ein gültiges Nummernschild sein.", "vinErrorText": "Der Wert muss eine gültige Fahrzeug-Identifizierungsnummer (VIN) sein.", - "languageCodeErrorText": "Der Wert muss ein gültiger Sprachcode sein." + "languageCodeErrorText": "Der Wert muss ein gültiger Sprachcode sein.", + "floatErrorText": "Der Wert muss eine gültige Fließkommazahl sein.", + "hexadecimalErrorText": "Der Wert muss eine gültige hexadezimale Zahl sein." } \ No newline at end of file diff --git a/lib/l10n/intl_el.arb b/lib/l10n/intl_el.arb index ce0cd4cf..6d134dca 100644 --- a/lib/l10n/intl_el.arb +++ b/lib/l10n/intl_el.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Η τιμή πρέπει να είναι ένας έγκυρος αριθμός DUNS.", "licensePlateErrorText": "Η τιμή πρέπει να είναι μια έγκυρη πινακίδα κυκλοφορίας.", "vinErrorText": "Η τιμή πρέπει να είναι ένας έγκυρος αριθμός VIN.", - "languageCodeErrorText": "Η τιμή πρέπει να είναι ένας έγκυρος κωδικός γλώσσας." + "languageCodeErrorText": "Η τιμή πρέπει να είναι ένας έγκυρος κωδικός γλώσσας.", + "floatErrorText": "Η τιμή πρέπει να είναι έγκυρος δεκαδικός αριθμός κινητής υποδιαστολής.", + "hexadecimalErrorText": "Η τιμή πρέπει να είναι έγκυρος δεκαεξαδικός αριθμός." } \ No newline at end of file diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 883f7f5d..af5e7a0f 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -280,5 +280,7 @@ "dunsErrorText": "Value must be a valid DUNS number.", "licensePlateErrorText": "Value must be a valid license plate.", "vinErrorText": "Value must be a valid VIN.", - "languageCodeErrorText": "Value must be a valid language code." + "languageCodeErrorText": "Value must be a valid language code.", + "floatErrorText": "Value must be a valid floating point number.", + "hexadecimalErrorText": "Value must be a valid hexadecimal number." } diff --git a/lib/l10n/intl_es.arb b/lib/l10n/intl_es.arb index bafb6366..42abb12a 100644 --- a/lib/l10n/intl_es.arb +++ b/lib/l10n/intl_es.arb @@ -84,5 +84,7 @@ "dunsErrorText": "El valor debe ser un número DUNS válido.", "licensePlateErrorText": "El valor debe ser una placa de matrícula válida.", "vinErrorText": "El valor debe ser un VIN válido.", - "languageCodeErrorText": "El valor debe ser un código de idioma válido." + "languageCodeErrorText": "El valor debe ser un código de idioma válido.", + "floatErrorText": "El valor debe ser un número de punto flotante válido.", + "hexadecimalErrorText": "El valor debe ser un número hexadecimal válido." } \ No newline at end of file diff --git a/lib/l10n/intl_et.arb b/lib/l10n/intl_et.arb index 7bda2706..a59b5345 100644 --- a/lib/l10n/intl_et.arb +++ b/lib/l10n/intl_et.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Väärtus peab olema kehtiv DUNS number.", "licensePlateErrorText": "Väärtus peab olema kehtiv numbrimärk.", "vinErrorText": "Väärtus peab olema kehtiv VIN.", - "languageCodeErrorText": "Väärtus peab olema kehtiv keelekood." + "languageCodeErrorText": "Väärtus peab olema kehtiv keelekood.", + "floatErrorText": "Väärtus peab olema kehtiv ujukomaarv.", + "hexadecimalErrorText": "Väärtus peab olema kehtiv kuueteistkümnendkohtade süsteemi arv." } \ No newline at end of file diff --git a/lib/l10n/intl_fa.arb b/lib/l10n/intl_fa.arb index cbf0b69d..b18340ef 100644 --- a/lib/l10n/intl_fa.arb +++ b/lib/l10n/intl_fa.arb @@ -84,5 +84,7 @@ "dunsErrorText": "مقدار باید یک شماره DUNS معتبر باشد.", "licensePlateErrorText": "مقدار باید یک شماره پلاک معتبر باشد.", "vinErrorText": "مقدار باید یک شماره VIN معتبر باشد.", - "languageCodeErrorText": "مقدار باید یک کد زبان معتبر باشد." + "languageCodeErrorText": "مقدار باید یک کد زبان معتبر باشد.", + "floatErrorText": "مقدار باید یک عدد اعشاری معتبر باشد.", + "hexadecimalErrorText": "مقدار باید یک عدد هگزادسیمال معتبر باشد." } \ No newline at end of file diff --git a/lib/l10n/intl_fi.arb b/lib/l10n/intl_fi.arb index 5d4eb0cb..21597268 100644 --- a/lib/l10n/intl_fi.arb +++ b/lib/l10n/intl_fi.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Arvon on oltava kelvollinen DUNS-numero.", "licensePlateErrorText": "Arvon on oltava kelvollinen rekisterinumero.", "vinErrorText": "Arvon on oltava kelvollinen VIN.", - "languageCodeErrorText": "Arvon on oltava kelvollinen kielikoodi." + "languageCodeErrorText": "Arvon on oltava kelvollinen kielikoodi.", + "floatErrorText": "Arvon on oltava kelvollinen liukuluku.", + "hexadecimalErrorText": "Arvon on oltava kelvollinen heksadesimaaliluku." } \ No newline at end of file diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 6a33c81c..5d7b99c1 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -84,5 +84,7 @@ "dunsErrorText": "La valeur doit être un numéro DUNS valide.", "licensePlateErrorText": "La valeur doit être une plaque d'immatriculation valide.", "vinErrorText": "La valeur doit être un numéro VIN valide.", - "languageCodeErrorText": "La valeur doit être un code de langue valide." + "languageCodeErrorText": "La valeur doit être un code de langue valide.", + "floatErrorText": "La valeur doit être un nombre à virgule flottante valide.", + "hexadecimalErrorText": "La valeur doit être un nombre hexadécimal valide." } \ No newline at end of file diff --git a/lib/l10n/intl_he.arb b/lib/l10n/intl_he.arb index 28c6bd04..1e5b3cab 100644 --- a/lib/l10n/intl_he.arb +++ b/lib/l10n/intl_he.arb @@ -84,5 +84,7 @@ "dunsErrorText": "הערך חייב להיות מספר DUNS חוקי.", "licensePlateErrorText": "הערך חייב להיות מספר רכב חוקי.", "vinErrorText": "הערך חייב להיות מספר VIN חוקי.", - "languageCodeErrorText": "הערך חייב להיות קוד שפה חוקי." + "languageCodeErrorText": "הערך חייב להיות קוד שפה חוקי.", + "floatErrorText": "הערך חייב להיות מספר נקודה צפה חוקי.", + "hexadecimalErrorText": "הערך חייב להיות מספר הקסדצימלי חוקי." } \ No newline at end of file diff --git a/lib/l10n/intl_hi.arb b/lib/l10n/intl_hi.arb index c2db8789..a370361d 100644 --- a/lib/l10n/intl_hi.arb +++ b/lib/l10n/intl_hi.arb @@ -84,5 +84,7 @@ "dunsErrorText": "मान मान्य DUNS नंबर होना चाहिए।", "licensePlateErrorText": "मान मान्य लाइसेंस प्लेट होना चाहिए।", "vinErrorText": "मान मान्य VIN होना चाहिए।", - "languageCodeErrorText": "मान मान्य भाषा कोड होना चाहिए।" + "languageCodeErrorText": "मान मान्य भाषा कोड होना चाहिए।", + "floatErrorText": "मान्य फ़्लोटिंग पॉइंट नंबर होना चाहिए।", + "hexadecimalErrorText": "मान्य हेक्साडेसिमल नंबर होना चाहिए।" } \ No newline at end of file diff --git a/lib/l10n/intl_hr.arb b/lib/l10n/intl_hr.arb index 9ee7345e..73d88f0a 100644 --- a/lib/l10n/intl_hr.arb +++ b/lib/l10n/intl_hr.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Vrijednost mora biti važeći DUNS broj.", "licensePlateErrorText": "Vrijednost mora biti važeća registarska oznaka.", "vinErrorText": "Vrijednost mora biti važeći VIN.", - "languageCodeErrorText": "Vrijednost mora biti važeći jezični kod." + "languageCodeErrorText": "Vrijednost mora biti važeći jezični kod.", + "floatErrorText": "Vrijednost mora biti valjani broj s pomičnim zarezom.", + "hexadecimalErrorText": "Vrijednost mora biti valjani heksadecimalni broj." } \ No newline at end of file diff --git a/lib/l10n/intl_hu.arb b/lib/l10n/intl_hu.arb index 672dd344..1f658910 100644 --- a/lib/l10n/intl_hu.arb +++ b/lib/l10n/intl_hu.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Az értéknek egy érvényes DUNS számnak kell lennie.", "licensePlateErrorText": "Az értéknek egy érvényes rendszámnak kell lennie.", "vinErrorText": "Az értéknek egy érvényes járműazonosító számnak kell lennie.", - "languageCodeErrorText": "Az értéknek egy érvényes nyelvkódnak kell lennie." + "languageCodeErrorText": "Az értéknek egy érvényes nyelvkódnak kell lennie.", + "floatErrorText": "Az értéknek érvényes lebegőpontos számnak kell lennie.", + "hexadecimalErrorText": "Az értéknek érvényes hexadecimális számnak kell lennie." } \ No newline at end of file diff --git a/lib/l10n/intl_id.arb b/lib/l10n/intl_id.arb index 9cfa2c03..3b28acc5 100644 --- a/lib/l10n/intl_id.arb +++ b/lib/l10n/intl_id.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Nilai harus berupa nomor DUNS yang valid.", "licensePlateErrorText": "Nilai harus berupa pelat nomor yang valid.", "vinErrorText": "Nilai harus berupa VIN yang valid.", - "languageCodeErrorText": "Nilai harus berupa kode bahasa yang valid." + "languageCodeErrorText": "Nilai harus berupa kode bahasa yang valid.", + "floatErrorText": "Nilai harus berupa angka floating point yang valid.", + "hexadecimalErrorText": "Nilai harus berupa angka heksadesimal yang valid." } \ No newline at end of file diff --git a/lib/l10n/intl_it.arb b/lib/l10n/intl_it.arb index 1e1b1732..028696f8 100644 --- a/lib/l10n/intl_it.arb +++ b/lib/l10n/intl_it.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Il valore deve essere un numero DUNS valido.", "licensePlateErrorText": "Il valore deve essere una targa valida.", "vinErrorText": "Il valore deve essere un VIN valido.", - "languageCodeErrorText": "Il valore deve essere un codice lingua valido." + "languageCodeErrorText": "Il valore deve essere un codice lingua valido.", + "floatErrorText": "Il valore deve essere un numero in virgola mobile valido.", + "hexadecimalErrorText": "Il valore deve essere un numero esadecimale valido." } \ No newline at end of file diff --git a/lib/l10n/intl_ja.arb b/lib/l10n/intl_ja.arb index 2a4fe4cb..ac200051 100644 --- a/lib/l10n/intl_ja.arb +++ b/lib/l10n/intl_ja.arb @@ -84,5 +84,7 @@ "dunsErrorText": "値は有効なDUNS番号でなければなりません。", "licensePlateErrorText": "値は有効なナンバープレートでなければなりません。", "vinErrorText": "値は有効なVINでなければなりません。", - "languageCodeErrorText": "値は有効な言語コードでなければなりません。" + "languageCodeErrorText": "値は有効な言語コードでなければなりません。", + "floatErrorText": "値は有効な浮動小数点数でなければなりません。", + "hexadecimalErrorText": "値は有効な16進数でなければなりません。" } \ No newline at end of file diff --git a/lib/l10n/intl_km.arb b/lib/l10n/intl_km.arb index 1df8c22b..3175ec8c 100644 --- a/lib/l10n/intl_km.arb +++ b/lib/l10n/intl_km.arb @@ -84,5 +84,7 @@ "dunsErrorText": "តម្លៃត្រូវតែជាលេខ DUNS ដែលត្រឹមត្រូវ។", "licensePlateErrorText": "តម្លៃត្រូវតែជាបណ្ណកាតសម្លេង។", "vinErrorText": "តម្លៃត្រូវតែជាលេខ VIN ដែលត្រឹមត្រូវ។", - "languageCodeErrorText": "តម្លៃត្រូវតែជាកូដភាសាដែលត្រឹមត្រូវ។" + "languageCodeErrorText": "តម្លៃត្រូវតែជាកូដភាសាដែលត្រឹមត្រូវ។", + "floatErrorText": "តម្លៃត្រូវតែជាចំនួនទសភាគត្រឹមត្រូវ។", + "hexadecimalErrorText": "តម្លៃត្រូវតែជាលេខសិប្បកម្មត្រឹមត្រូវ។" } \ No newline at end of file diff --git a/lib/l10n/intl_ko.arb b/lib/l10n/intl_ko.arb index 23aefb11..1efefd4e 100644 --- a/lib/l10n/intl_ko.arb +++ b/lib/l10n/intl_ko.arb @@ -84,5 +84,7 @@ "dunsErrorText": "값은 유효한 DUNS 번호이어야 합니다.", "licensePlateErrorText": "값은 유효한 번호판이어야 합니다.", "vinErrorText": "값은 유효한 VIN이어야 합니다.", - "languageCodeErrorText": "값은 유효한 언어 코드이어야 합니다." + "languageCodeErrorText": "값은 유효한 언어 코드이어야 합니다.", + "floatErrorText": "값은 유효한 부동 소수점 수여야 합니다.", + "hexadecimalErrorText": "값은 유효한 16진수여야 합니다." } \ No newline at end of file diff --git a/lib/l10n/intl_ku.arb b/lib/l10n/intl_ku.arb index 6e5277e1..caf8f557 100644 --- a/lib/l10n/intl_ku.arb +++ b/lib/l10n/intl_ku.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Nirxî divê yekem hejmarê DUNS derbasdar be.", "licensePlateErrorText": "Nirxî divê yekem pelka prezantiyê ya derbasdar be.", "vinErrorText": "Nirxî divê yekem hejmarê VIN derbasdar be.", - "languageCodeErrorText": "Nirxî divê yekem kodê zimanê derbasdar be." + "languageCodeErrorText": "Nirxî divê yekem kodê zimanê derbasdar be.", + "floatErrorText": "Gerrdê hewce ye ku zêdeya rast bibe.", + "hexadecimalErrorText": "Gerrdê hewce ye ku hexa de rast bibe." } \ No newline at end of file diff --git a/lib/l10n/intl_lo.arb b/lib/l10n/intl_lo.arb index 653c1e57..049194ca 100644 --- a/lib/l10n/intl_lo.arb +++ b/lib/l10n/intl_lo.arb @@ -84,5 +84,7 @@ "dunsErrorText": "ຄ່າຕ້ອງເປັນໝາຍເລກ DUNS ທີ່ຖືກຕ້ອງ.", "licensePlateErrorText": "ຄ່າຕ້ອງເປັນໝາຍເລກປ້າຍທີ່ຖືກຕ້ອງ.", "vinErrorText": "ຄ່າຕ້ອງເປັນ VIN ທີ່ຖືກຕ້ອງ.", - "languageCodeErrorText": "ຄ່າຕ້ອງເປັນໄລຄໂລດພາສາທີ່ຖືກຕ້ອງ." + "languageCodeErrorText": "ຄ່າຕ້ອງເປັນໄລຄໂລດພາສາທີ່ຖືກຕ້ອງ.", + "floatErrorText": "ຄ່າຕ້ອງເປັນໂຕເລກ float ທີ່ຖືກຕ້ອງ.", + "hexadecimalErrorText": "ຄ່າຕ້ອງເປັນໂຕເລກເຮັກຊະເດສິມທີ່ຖືກຕ້ອງ." } \ No newline at end of file diff --git a/lib/l10n/intl_mn.arb b/lib/l10n/intl_mn.arb index 956166bf..c9e3722a 100644 --- a/lib/l10n/intl_mn.arb +++ b/lib/l10n/intl_mn.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Утга нь хүчин төгөлдөр DUNS дугаар байх ёстой.", "licensePlateErrorText": "Утга нь хүчин төгөлдөр тээврийн хэрэгслийн дугаар байх ёстой.", "vinErrorText": "Утга нь хүчин төгөлдөр VIN байх ёстой.", - "languageCodeErrorText": "Утга нь хүчин төгөлдөр хэлний код байх ёстой." + "languageCodeErrorText": "Утга нь хүчин төгөлдөр хэлний код байх ёстой.", + "floatErrorText": "Утга нь буцаж ирдэг зөв хөвөгч цэгийн тоо байх ёстой.", + "hexadecimalErrorText": "Утга нь буцаж ирдэг зөв арван зургаатын тоо байх ёстой." } \ No newline at end of file diff --git a/lib/l10n/intl_ms.arb b/lib/l10n/intl_ms.arb index b6dec4de..3698711d 100644 --- a/lib/l10n/intl_ms.arb +++ b/lib/l10n/intl_ms.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Nilai mesti nombor DUNS yang sah.", "licensePlateErrorText": "Nilai mesti nombor plat lesen yang sah.", "vinErrorText": "Nilai mesti nombor VIN yang sah.", - "languageCodeErrorText": "Nilai mesti kod bahasa yang sah." + "languageCodeErrorText": "Nilai mesti kod bahasa yang sah.", + "floatErrorText": "Nilai mesti nombor terapung sah.", + "hexadecimalErrorText": "Nilai mesti nombor heksadesimal sah." } \ No newline at end of file diff --git a/lib/l10n/intl_ne.arb b/lib/l10n/intl_ne.arb index e4ba3a7b..7582a947 100644 --- a/lib/l10n/intl_ne.arb +++ b/lib/l10n/intl_ne.arb @@ -84,5 +84,7 @@ "dunsErrorText": "मान मान्य DUNS नम्बर हुनुपर्छ।", "licensePlateErrorText": "मान मान्य नम्बर प्लेट हुनुपर्छ।", "vinErrorText": "मान मान्य VIN हुनुपर्छ।", - "languageCodeErrorText": "मान मान्य भाषाको कोड हुनुपर्छ।" + "languageCodeErrorText": "मान मान्य भाषाको कोड हुनुपर्छ।", + "floatErrorText": "मान्यता प्राप्त फ्लोटिङ पोइन्ट नम्बर हुनुपर्छ।", + "hexadecimalErrorText": "मान्यता प्राप्त हेक्साडेसिमल नम्बर हुनुपर्छ।" } \ No newline at end of file diff --git a/lib/l10n/intl_nl.arb b/lib/l10n/intl_nl.arb index fc89deac..36a2cc8f 100644 --- a/lib/l10n/intl_nl.arb +++ b/lib/l10n/intl_nl.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Waarde moet een geldig DUNS-nummer zijn.", "licensePlateErrorText": "Waarde moet een geldige kentekenplaat zijn.", "vinErrorText": "Waarde moet een geldig VIN zijn.", - "languageCodeErrorText": "Waarde moet een geldige taalcode zijn." + "languageCodeErrorText": "Waarde moet een geldige taalcode zijn.", + "floatErrorText": "Waarde moet een geldig drijvend-komma getal zijn.", + "hexadecimalErrorText": "Waarde moet een geldig hexadecimaal getal zijn." } \ No newline at end of file diff --git a/lib/l10n/intl_no.arb b/lib/l10n/intl_no.arb index 7b075166..5d7506bb 100644 --- a/lib/l10n/intl_no.arb +++ b/lib/l10n/intl_no.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Verdien må være et gyldig DUNS-nummer.", "licensePlateErrorText": "Verdien må være et gyldig registreringsnummer.", "vinErrorText": "Verdien må være et gyldig VIN.", - "languageCodeErrorText": "Verdien må være en gyldig språkkode." + "languageCodeErrorText": "Verdien må være en gyldig språkkode.", + "floatErrorText": "Verdien må være et gyldig flyttall.", + "hexadecimalErrorText": "Verdien må være et gyldig heksadesimalt tall." } \ No newline at end of file diff --git a/lib/l10n/intl_pl.arb b/lib/l10n/intl_pl.arb index 5542444e..8b5cc2d7 100644 --- a/lib/l10n/intl_pl.arb +++ b/lib/l10n/intl_pl.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Wartość musi być prawidłowym numerem DUNS.", "licensePlateErrorText": "Wartość musi być prawidłowym numerem tablicy rejestracyjnej.", "vinErrorText": "Wartość musi być prawidłowym numerem VIN.", - "languageCodeErrorText": "Wartość musi być prawidłowym kodem języka." + "languageCodeErrorText": "Wartość musi być prawidłowym kodem języka.", + "floatErrorText": "Wartość musi być prawidłową liczbą zmiennoprzecinkową.", + "hexadecimalErrorText": "Wartość musi być prawidłową liczbą szesnastkową." } \ No newline at end of file diff --git a/lib/l10n/intl_pt.arb b/lib/l10n/intl_pt.arb index e96524b2..11a1c6c2 100644 --- a/lib/l10n/intl_pt.arb +++ b/lib/l10n/intl_pt.arb @@ -84,5 +84,7 @@ "dunsErrorText": "O valor deve ser um número DUNS válido.", "licensePlateErrorText": "O valor deve ser uma placa de licença válida.", "vinErrorText": "O valor deve ser um VIN válido.", - "languageCodeErrorText": "O valor deve ser um código de idioma válido." + "languageCodeErrorText": "O valor deve ser um código de idioma válido.", + "floatErrorText": "O valor deve ser um número de ponto flutuante válido.", + "hexadecimalErrorText": "O valor deve ser um número hexadecimal válido." } \ No newline at end of file diff --git a/lib/l10n/intl_ro.arb b/lib/l10n/intl_ro.arb index 23a932bb..659d09eb 100644 --- a/lib/l10n/intl_ro.arb +++ b/lib/l10n/intl_ro.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Valoarea trebuie să fie un număr DUNS valid.", "licensePlateErrorText": "Valoarea trebuie să fie un număr de înmatriculare valid.", "vinErrorText": "Valoarea trebuie să fie un VIN valid.", - "languageCodeErrorText": "Valoarea trebuie să fie un cod de limbă valid." + "languageCodeErrorText": "Valoarea trebuie să fie un cod de limbă valid.", + "floatErrorText": "Valoarea trebuie să fie un număr zecimal valid.", + "hexadecimalErrorText": "Valoarea trebuie să fie un număr hexadecimal valid." } \ No newline at end of file diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index ea24a1e2..015ce131 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Значение должно быть действительным номером DUNS.", "licensePlateErrorText": "Значение должно быть действительным номером номерного знака.", "vinErrorText": "Значение должно быть действительным VIN.", - "languageCodeErrorText": "Значение должно быть действительным кодом языка." + "languageCodeErrorText": "Значение должно быть действительным кодом языка.", + "floatErrorText": "Значение должно быть допустимым числом с плавающей запятой.", + "hexadecimalErrorText": "Значение должно быть допустимым шестнадцатеричным числом." } \ No newline at end of file diff --git a/lib/l10n/intl_sk.arb b/lib/l10n/intl_sk.arb index 8bddc119..cdb33c15 100644 --- a/lib/l10n/intl_sk.arb +++ b/lib/l10n/intl_sk.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Hodnota musí byť platné číslo DUNS.", "licensePlateErrorText": "Hodnota musí byť platné číslo evidenčnej značky vozidla.", "vinErrorText": "Hodnota musí byť platné číslo VIN.", - "languageCodeErrorText": "Hodnota musí byť platný kód jazyka." + "languageCodeErrorText": "Hodnota musí byť platný kód jazyka.", + "floatErrorText": "Hodnota musí byť platné desatinné číslo.", + "hexadecimalErrorText": "Hodnota musí byť platné hexadecimálne číslo." } \ No newline at end of file diff --git a/lib/l10n/intl_sl.arb b/lib/l10n/intl_sl.arb index 5092bdff..6e06a7d4 100644 --- a/lib/l10n/intl_sl.arb +++ b/lib/l10n/intl_sl.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Vrednost mora biti veljavna DUNS številka.", "licensePlateErrorText": "Vrednost mora biti veljavna registrska tablica.", "vinErrorText": "Vrednost mora biti veljavna identifikacijska številka vozila (VIN).", - "languageCodeErrorText": "Vrednost mora biti veljavna koda jezika." + "languageCodeErrorText": "Vrednost mora biti veljavna koda jezika.", + "floatErrorText": "Vrednost mora biti veljavno število s plavajočo vejico.", + "hexadecimalErrorText": "Vrednost mora biti veljavno šestnajstiško število." } \ No newline at end of file diff --git a/lib/l10n/intl_sq.arb b/lib/l10n/intl_sq.arb index 34fbcfd3..b9d7a2cf 100644 --- a/lib/l10n/intl_sq.arb +++ b/lib/l10n/intl_sq.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Vlera duhet të jetë një numër DUNS i vlefshëm.", "licensePlateErrorText": "Vlera duhet të jetë një targë makine e vlefshme.", "vinErrorText": "Vlera duhet të jetë një VIN i vlefshëm.", - "languageCodeErrorText": "Vlera duhet të jetë një kod gjuhe i vlefshëm." -} \ No newline at end of file + "languageCodeErrorText": "Vlera duhet të jetë një kod gjuhe i vlefshëm.", + "floatErrorText": "Vlera duhet të jetë një numër i vlefshëm me pikë lundruese.", + "hexadecimalErrorText": "Vlera duhet të jetë një numër i vlefshëm heksadecimal." +} diff --git a/lib/l10n/intl_sv.arb b/lib/l10n/intl_sv.arb index df88b0ec..abfb0a3d 100644 --- a/lib/l10n/intl_sv.arb +++ b/lib/l10n/intl_sv.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Värdet måste vara ett giltigt DUNS-nummer.", "licensePlateErrorText": "Värdet måste vara en giltig registreringsskylt.", "vinErrorText": "Värdet måste vara ett giltigt VIN.", - "languageCodeErrorText": "Värdet måste vara en giltig språkkod." + "languageCodeErrorText": "Värdet måste vara en giltig språkkod.", + "floatErrorText": "Värdet måste vara ett giltigt flyttal.", + "hexadecimalErrorText": "Värdet måste vara ett giltigt hexadecimaltal." } \ No newline at end of file diff --git a/lib/l10n/intl_sw.arb b/lib/l10n/intl_sw.arb index c0cc5732..5dcf203e 100644 --- a/lib/l10n/intl_sw.arb +++ b/lib/l10n/intl_sw.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Thamani lazima iwe nambari halali ya DUNS.", "licensePlateErrorText": "Thamani lazima iwe nambari sahihi ya leseni.", "vinErrorText": "Thamani lazima iwe VIN halali.", - "languageCodeErrorText": "Thamani lazima iwe msimbo halali wa lugha." + "languageCodeErrorText": "Thamani lazima iwe msimbo halali wa lugha.", + "floatErrorText": "Thamani lazima iwe nambari sahihi ya nukta mvutano.", + "hexadecimalErrorText": "Thamani lazima iwe nambari sahihi ya hekshadesimali." } \ No newline at end of file diff --git a/lib/l10n/intl_ta.arb b/lib/l10n/intl_ta.arb index 0683f49b..71176758 100644 --- a/lib/l10n/intl_ta.arb +++ b/lib/l10n/intl_ta.arb @@ -84,5 +84,7 @@ "dunsErrorText": "மதிப்பு ஒரு செல்லுபடியான DUNS எணாக இருக்க வேண்டும்.", "licensePlateErrorText": "மதிப்பு ஒரு செல்லுபடியான பதிவு தகடு (license plate) எணாக இருக்க வேண்டும்.", "vinErrorText": "மதிப்பு ஒரு செல்லுபடியான வாகன அடையாள எணாக (VIN) இருக்க வேண்டும்.", - "languageCodeErrorText": "மதிப்பு ஒரு செல்லுபடியான மொழி குறியீடாக இருக்க வேண்டும்." + "languageCodeErrorText": "மதிப்பு ஒரு செல்லுபடியான மொழி குறியீடாக இருக்க வேண்டும்.", + "floatErrorText": "மதிப்பு சரியான மிதக்கும் புள்ளி எண் ஆக இருக்க வேண்டும்.", + "hexadecimalErrorText": "மதிப்பு சரியான ஹெக்சாடெசிமல் எண் ஆக இருக்க வேண்டும்." } \ No newline at end of file diff --git a/lib/l10n/intl_th.arb b/lib/l10n/intl_th.arb index 6779beb9..410eadfa 100644 --- a/lib/l10n/intl_th.arb +++ b/lib/l10n/intl_th.arb @@ -84,5 +84,7 @@ "dunsErrorText": "ค่าต้องเป็นเลข DUNS ที่ถูกต้อง", "licensePlateErrorText": "ค่าต้องเป็นเลขทะเบียนรถที่ถูกต้อง", "vinErrorText": "ค่าต้องเป็นหมายเลข VIN ที่ถูกต้อง", - "languageCodeErrorText": "ค่าต้องเป็นรหัสภาษาที่ถูกต้อง" + "languageCodeErrorText": "ค่าต้องเป็นรหัสภาษาที่ถูกต้อง", + "floatErrorText": "ค่าต้องเป็นตัวเลขทศนิยมที่ถูกต้อง", + "hexadecimalErrorText": "ค่าต้องเป็นเลขฐานสิบหกที่ถูกต้อง" } \ No newline at end of file diff --git a/lib/l10n/intl_tr.arb b/lib/l10n/intl_tr.arb index 81cf5987..d163ce6a 100644 --- a/lib/l10n/intl_tr.arb +++ b/lib/l10n/intl_tr.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Değer geçerli bir DUNS numarası olmalıdır.", "licensePlateErrorText": "Değer geçerli bir plaka olmalıdır.", "vinErrorText": "Değer geçerli bir VIN numarası olmalıdır.", - "languageCodeErrorText": "Değer geçerli bir dil kodu olmalıdır." + "languageCodeErrorText": "Değer geçerli bir dil kodu olmalıdır.", + "floatErrorText": "Değer geçerli bir noktalı sayı olmalıdır.", + "hexadecimalErrorText": "Değer geçerli bir onaltılık sayı olmalıdır." } \ No newline at end of file diff --git a/lib/l10n/intl_uk.arb b/lib/l10n/intl_uk.arb index 9647a1b0..d7149043 100644 --- a/lib/l10n/intl_uk.arb +++ b/lib/l10n/intl_uk.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Значення повинно бути дійсним номером DUNS.", "licensePlateErrorText": "Значення повинно бути дійсним номерним знаком автомобіля.", "vinErrorText": "Значення повинно бути дійсним VIN.", - "languageCodeErrorText": "Значення повинно бути дійсним кодом мови." + "languageCodeErrorText": "Значення повинно бути дійсним кодом мови.", + "floatErrorText": "Значення повинно бути дійсним числом з плаваючою комою.", + "hexadecimalErrorText": "Значення повинно бути дійсним шістнадцятковим числом." } \ No newline at end of file diff --git a/lib/l10n/intl_vi.arb b/lib/l10n/intl_vi.arb index 0016fbaa..b82dd2f4 100644 --- a/lib/l10n/intl_vi.arb +++ b/lib/l10n/intl_vi.arb @@ -84,5 +84,7 @@ "dunsErrorText": "Giá trị phải là số DUNS hợp lệ.", "licensePlateErrorText": "Giá trị phải là biển số xe hợp lệ.", "vinErrorText": "Giá trị phải là số VIN hợp lệ.", - "languageCodeErrorText": "Giá trị phải là mã ngôn ngữ hợp lệ." + "languageCodeErrorText": "Giá trị phải là mã ngôn ngữ hợp lệ.", + "floatErrorText": "Giá trị phải là một số dấu phẩy động hợp lệ.", + "hexadecimalErrorText": "Giá trị phải là một số thập lục phân hợp lệ." } \ No newline at end of file diff --git a/lib/l10n/intl_zh.arb b/lib/l10n/intl_zh.arb index cbd7b385..1f433690 100644 --- a/lib/l10n/intl_zh.arb +++ b/lib/l10n/intl_zh.arb @@ -84,5 +84,7 @@ "dunsErrorText": "值必须是有效的DUNS编号。", "licensePlateErrorText": "值必须是有效的车牌号。", "vinErrorText": "值必须是有效的车辆识别码(VIN)。", - "languageCodeErrorText": "值必须是有效的语言代码。" + "languageCodeErrorText": "值必须是有效的语言代码。", + "floatErrorText": "值必须是有效的浮点数。", + "hexadecimalErrorText": "值必须是有效的十六进制数。" } \ No newline at end of file diff --git a/lib/l10n/intl_zh_Hant.arb b/lib/l10n/intl_zh_Hant.arb index 507c1730..8f76cdf9 100644 --- a/lib/l10n/intl_zh_Hant.arb +++ b/lib/l10n/intl_zh_Hant.arb @@ -84,5 +84,7 @@ "dunsErrorText": "值必須是一個有效的DUNS號碼。", "licensePlateErrorText": "值必須是一個有效的車牌號碼。", "vinErrorText": "值必須是一個有效的車輛識別號。", - "languageCodeErrorText": "值必須是一個有效的語言代碼。" + "languageCodeErrorText": "值必須是一個有效的語言代碼。", + "floatErrorText": "數值必須為有效的浮點數。", + "hexadecimalErrorText": "數值必須為有效的十六進位數字。" } \ No newline at end of file diff --git a/lib/src/form_builder_validators.dart b/lib/src/form_builder_validators.dart index baf43992..452d3b14 100644 --- a/lib/src/form_builder_validators.dart +++ b/lib/src/form_builder_validators.dart @@ -1155,13 +1155,13 @@ class FormBuilderValidators { /// or equal to. /// - [errorText] The error message when the value is not in the range. /// - [checkNullOrEmpty] Whether to check for null or empty values. - static FormFieldValidator between( + static FormFieldValidator between( num min, num max, { String? errorText, bool checkNullOrEmpty = true, }) => - BetweenValidator( + BetweenValidator( min, max, errorText: errorText, @@ -1182,6 +1182,36 @@ class FormBuilderValidators { checkNullOrEmpty: checkNullOrEmpty, ).validate; + /// [FormFieldValidator] that requires the field's value to be a valid float. + /// + /// ## Parameters: + /// - [errorText] The error message when the float is invalid. + /// - [checkNullOrEmpty] Whether to check for null or empty values. + /// {@macro float_template} + static FormFieldValidator float({ + String? errorText, + bool checkNullOrEmpty = true, + }) => + FloatValidator( + errorText: errorText, + checkNullOrEmpty: checkNullOrEmpty, + ).validate; + + /// [FormFieldValidator] that requires the field's value to be a valid hexadecimal. + /// + /// ## Parameters: + /// - [errorText] The error message when the hexadecimal is invalid. + /// - [checkNullOrEmpty] Whether to check for null or empty values. + /// {@macro hexadecimal_template} + static FormFieldValidator hexadecimal({ + String? errorText, + bool checkNullOrEmpty = true, + }) => + HexadecimalValidator( + errorText: errorText, + checkNullOrEmpty: checkNullOrEmpty, + ).validate; + /// [FormFieldValidator] that requires the value to be a valid integer. /// /// ## Parameters: diff --git a/lib/src/numeric/between_validator.dart b/lib/src/numeric/between_validator.dart index 7ca0a11d..358a6a06 100644 --- a/lib/src/numeric/between_validator.dart +++ b/lib/src/numeric/between_validator.dart @@ -14,7 +14,7 @@ import '../base_validator.dart'; /// - [checkNullOrEmpty] Whether to check if the value is null or empty. /// /// {@endtemplate} -class BetweenValidator extends BaseValidator { +class BetweenValidator extends BaseValidator { /// Constructor for the between validator. const BetweenValidator( this.min, @@ -37,9 +37,18 @@ class BetweenValidator extends BaseValidator { FormBuilderLocalizations.current.betweenErrorText(min, max); @override - String? validateValue(num valueCandidate) { - final num value = valueCandidate; - if (value < min || value > max) { + String? validateValue(T valueCandidate) { + final num? value; + + if (valueCandidate is String) { + value = num.tryParse(valueCandidate); + } else if (valueCandidate is num) { + value = valueCandidate; + } else { + return errorText; + } + + if (value == null || (value < min || value > max)) { return errorText; } diff --git a/lib/src/numeric/float_validator.dart b/lib/src/numeric/float_validator.dart new file mode 100644 index 00000000..9a1387de --- /dev/null +++ b/lib/src/numeric/float_validator.dart @@ -0,0 +1,49 @@ +import '../../localization/l10n.dart'; +import '../base_validator.dart'; + +/// {@template float_validator_template} +/// [FloatValidator] extends [BaseValidator] to validate if a value is a float and does not exceed a maximum value. +/// +/// This validator checks if the value is a float number or a string that can be parsed into a float number and ensures it does not exceed the maximum value. +/// +/// ## Parameters: +/// +/// - [errorText] The error message returned if the validation fails. +/// - [checkNullOrEmpty] Whether to check if the value is null or empty. +/// - [maxValue] The maximum allowed value for the float. Default is 1.0. +/// +/// {@endtemplate} +class FloatValidator extends BaseValidator { + /// Constructor for the float validator. + const FloatValidator({ + /// {@macro base_validator_error_text} + super.errorText, + + /// {@macro base_validator_null_check} + super.checkNullOrEmpty, + }); + + @override + String get translatedErrorText => + FormBuilderLocalizations.current.floatErrorText; + + @override + String? validateValue(T valueCandidate) { + final double? value; + if (valueCandidate is String) { + value = double.tryParse(valueCandidate); + } else if (valueCandidate is double) { + value = valueCandidate; + } else if (valueCandidate is num) { + value = valueCandidate.toDouble(); + } else { + return errorText; + } + + if (value == null) { + return errorText; + } + + return null; + } +} diff --git a/lib/src/numeric/hexadecimal_validator.dart b/lib/src/numeric/hexadecimal_validator.dart new file mode 100644 index 00000000..3c133948 --- /dev/null +++ b/lib/src/numeric/hexadecimal_validator.dart @@ -0,0 +1,52 @@ +import '../../localization/l10n.dart'; +import '../base_validator.dart'; + +/// {@template hexadecimal_validator_template} +/// [HexadecimalValidator] extends [BaseValidator] to validate if a value is a hexadecimal string. +/// +/// This validator checks if the value is a valid hexadecimal string using a regular expression. +/// +/// ## Parameters: +/// +/// - [errorText] The error message returned if the validation fails. +/// - [regex] The regular expression used to validate the hexadecimal string. +/// +/// {@macro hexadecimal_regex_template} +/// {@endtemplate} +class HexadecimalValidator extends BaseValidator { + /// Constructor for the hexadecimal validator. + HexadecimalValidator({ + /// {@macro hexadecimal_regex_template} + RegExp? regex, + + /// {@macro base_validator_error_text} + super.errorText, + + /// {@macro base_validator_null_check} + super.checkNullOrEmpty, + }) : regex = regex ?? _hexadecimalRegex; + + @override + String get translatedErrorText => + FormBuilderLocalizations.current.hexadecimalErrorText; + + /// The regular expression used to validate the hexadecimal string. + final RegExp regex; + + /// {@template hexadecimal_regex_template} + /// The default regex matches a hexadecimal string. + /// + /// - It allows digits and letters from A-F (both lowercase and uppercase). + /// - It supports optional prefixes "0x" or "0X". + /// + /// Examples: 1A3F, a1b2c3, 0x4faDA5 + /// {@endtemplate} + static final RegExp _hexadecimalRegex = RegExp( + r'^(0[xX])?[0-9a-fA-F]+$', + ); + + @override + String? validateValue(String valueCandidate) { + return regex.hasMatch(valueCandidate) ? null : errorText; + } +} diff --git a/lib/src/numeric/numeric.dart b/lib/src/numeric/numeric.dart index a218926e..37222b70 100644 --- a/lib/src/numeric/numeric.dart +++ b/lib/src/numeric/numeric.dart @@ -1,5 +1,7 @@ export 'between_validator.dart'; export 'even_number_validator.dart'; +export 'float_validator.dart'; +export 'hexadecimal_validator.dart'; export 'integer_validator.dart'; export 'max_validator.dart'; export 'min_validator.dart'; diff --git a/test/src/numeric/between_validator_test.dart b/test/src/numeric/between_validator_test.dart index 2caa6fd0..0cbb532c 100644 --- a/test/src/numeric/between_validator_test.dart +++ b/test/src/numeric/between_validator_test.dart @@ -7,171 +7,369 @@ void main() { final String customErrorMessage = faker.lorem.sentence(); group('BetweenValidator -', () { - test('should return null if the value is exactly at the minimum boundary', - () { - // Arrange - const num min = 5; - const num max = 10; - const BetweenValidator validator = BetweenValidator(min, max); - const num value = 5; - - // Act - final String? result = validator.validate(value); - - // Assert - expect(result, isNull); + group('bool', () { + test('should return errorText when type is invalid', () { + // Arrange + const num min = 5; + const num max = 10; + final BetweenValidator validator = + BetweenValidator(min, max, errorText: customErrorMessage); + const bool value = true; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, equals(customErrorMessage)); + }); }); - test('should return null if the value is exactly at the maximum boundary', - () { - // Arrange - const num min = 5; - const num max = 10; - const BetweenValidator validator = BetweenValidator(min, max); - const num value = 10; + group('num', () { + test('should return null if the value is exactly at the minimum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = BetweenValidator(min, max); + const num value = 5; - // Act - final String? result = validator.validate(value); + // Act + final String? result = validator.validate(value); - // Assert - expect(result, isNull); - }); + // Assert + expect(result, isNull); + }); - test('should return null if the value is within the range', () { - // Arrange - const num min = 5; - const num max = 10; - const BetweenValidator validator = BetweenValidator(min, max); - const num value = 7; + test('should return null if the value is exactly at the maximum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = BetweenValidator(min, max); + const num value = 10; - // Act - final String? result = validator.validate(value); + // Act + final String? result = validator.validate(value); - // Assert - expect(result, isNull); - }); + // Assert + expect(result, isNull); + }); - test( - 'should return the default error message if the value is below the minimum boundary', - () { - // Arrange - const num min = 5; - const num max = 10; - const BetweenValidator validator = BetweenValidator(min, max); - const num value = 4; - - // Act - final String? result = validator.validate(value); - - // Assert - expect(result, isNotNull); - expect( - result, - equals( - FormBuilderLocalizations.current.betweenErrorText(min, max), - ), - ); - }); + test('should return null if the value is within the range', () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = BetweenValidator(min, max); + const num value = 7; - test( - 'should return the default error message if the value is above the maximum boundary', - () { - // Arrange - const num min = 5; - const num max = 10; - const BetweenValidator validator = BetweenValidator(min, max); - const num value = 11; - - // Act - final String? result = validator.validate(value); - - // Assert - expect(result, isNotNull); - expect( - result, - equals( - FormBuilderLocalizations.current.betweenErrorText(min, max), - ), - ); - }); + // Act + final String? result = validator.validate(value); - test( - 'should return the custom error message if the value is below the minimum boundary', - () { - // Arrange - const num min = 5; - const num max = 10; - final BetweenValidator validator = BetweenValidator( - min, - max, - errorText: customErrorMessage, - ); - const num value = 4; - - // Act - final String? result = validator.validate(value); - - // Assert - expect(result, equals(customErrorMessage)); - }); + // Assert + expect(result, isNull); + }); - test( - 'should return the custom error message if the value is above the maximum boundary', - () { - // Arrange - const num min = 5; - const num max = 10; - final BetweenValidator validator = BetweenValidator( - min, - max, - errorText: customErrorMessage, - ); - const num value = 11; - - // Act - final String? result = validator.validate(value); - - // Assert - expect(result, equals(customErrorMessage)); - }); + test( + 'should return the default error message if the value is below the minimum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = BetweenValidator(min, max); + const num value = 4; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNotNull); + expect( + result, + equals( + FormBuilderLocalizations.current.betweenErrorText(min, max), + ), + ); + }); + + test( + 'should return the default error message if the value is above the maximum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = BetweenValidator(min, max); + const num value = 11; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNotNull); + expect( + result, + equals( + FormBuilderLocalizations.current.betweenErrorText(min, max), + ), + ); + }); - test('should return null when the value is null and null check is disabled', - () { - // Arrange - const num min = 5; - const num max = 10; - const BetweenValidator validator = BetweenValidator( - min, - max, - checkNullOrEmpty: false, - ); - const num? value = null; - - // Act - final String? result = validator.validate(value); - - // Assert - expect(result, isNull); + test( + 'should return the custom error message if the value is below the minimum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + final BetweenValidator validator = BetweenValidator( + min, + max, + errorText: customErrorMessage, + ); + const num value = 4; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, equals(customErrorMessage)); + }); + + test( + 'should return the custom error message if the value is above the maximum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + final BetweenValidator validator = BetweenValidator( + min, + max, + errorText: customErrorMessage, + ); + const num value = 11; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, equals(customErrorMessage)); + }); + + test( + 'should return null when the value is null and null check is disabled', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = BetweenValidator( + min, + max, + checkNullOrEmpty: false, + ); + const num? value = null; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNull); + }); + + test('should return the default error message when the value is null', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = BetweenValidator(min, max); + const num? value = null; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNotNull); + expect( + result, + equals( + FormBuilderLocalizations.current.betweenErrorText(min, max), + ), + ); + }); }); - test('should return the default error message when the value is null', () { - // Arrange - const num min = 5; - const num max = 10; - const BetweenValidator validator = BetweenValidator(min, max); - const num? value = null; - - // Act - final String? result = validator.validate(value); - - // Assert - expect(result, isNotNull); - expect( - result, - equals( - FormBuilderLocalizations.current.betweenErrorText(min, max), - ), - ); + group('String', () { + test('should return null if the value is exactly at the minimum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = + BetweenValidator(min, max); + const String value = '5'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNull); + }); + + test('should return null if the value is exactly at the maximum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = + BetweenValidator(min, max); + const String value = '10'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNull); + }); + + test('should return null if the value is within the range', () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = + BetweenValidator(min, max); + const String value = '7'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNull); + }); + + test( + 'should return the default error message if the value is below the minimum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = + BetweenValidator(min, max); + const String value = '4'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNotNull); + expect( + result, + equals( + FormBuilderLocalizations.current.betweenErrorText(min, max), + ), + ); + }); + + test( + 'should return the default error message if the value is above the maximum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = + BetweenValidator(min, max); + const String value = '11'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNotNull); + expect( + result, + equals( + FormBuilderLocalizations.current.betweenErrorText(min, max), + ), + ); + }); + + test( + 'should return the custom error message if the value is below the minimum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + final BetweenValidator validator = BetweenValidator( + min, + max, + errorText: customErrorMessage, + ); + const String value = '4'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, equals(customErrorMessage)); + }); + + test( + 'should return the custom error message if the value is above the maximum boundary', + () { + // Arrange + const num min = 5; + const num max = 10; + final BetweenValidator validator = BetweenValidator( + min, + max, + errorText: customErrorMessage, + ); + const String value = '11'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, equals(customErrorMessage)); + }); + + test( + 'should return null when the value is null and null check is disabled', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = BetweenValidator( + min, + max, + checkNullOrEmpty: false, + ); + const String? value = null; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNull); + }); + + test('should return the default error message when the value is null', + () { + // Arrange + const num min = 5; + const num max = 10; + const BetweenValidator validator = + BetweenValidator(min, max); + const String? value = null; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNotNull); + expect( + result, + equals( + FormBuilderLocalizations.current.betweenErrorText(min, max), + ), + ); + }); }); }); } diff --git a/test/src/numeric/float_validator_test.dart b/test/src/numeric/float_validator_test.dart new file mode 100644 index 00000000..cb68534e --- /dev/null +++ b/test/src/numeric/float_validator_test.dart @@ -0,0 +1,194 @@ +import 'package:faker_dart/faker_dart.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:form_builder_validators/form_builder_validators.dart'; + +void main() { + final Faker faker = Faker.instance; + final String customErrorMessage = faker.lorem.sentence(); + + group('FloatValidator -', () { + group('String', () { + test('should return null if the value is a valid float string', () { + // Arrange + const FloatValidator validator = FloatValidator(); + const String value = '0.99'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNull); + }); + + test('should return error if the value is not a valid float string', () { + // Arrange + const FloatValidator validator = FloatValidator(); + const String value = 'abc'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNotNull); + expect( + result, + equals( + FormBuilderLocalizations.current.floatErrorText, + ), + ); + }); + + test( + 'should return custom error message if the value is not a valid float string', + () { + // Arrange + final FloatValidator validator = + FloatValidator(errorText: customErrorMessage); + const String value = 'abc'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, equals(customErrorMessage)); + }); + }); + + group('num', () { + test('should return null if the value is a valid float', () { + // Arrange + const FloatValidator validator = FloatValidator(); + const num value = 0.99; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNull); + }); + + test('should return null if the value is a valid int', () { + // Arrange + const FloatValidator validator = FloatValidator(); + const int value = 5; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNull); + }); + + test('should return error if the value is not a valid float', () { + // Arrange + const FloatValidator validator = FloatValidator(); + const String value = 'abc'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNotNull); + expect( + result, + equals( + FormBuilderLocalizations.current.floatErrorText, + ), + ); + }); + + test( + 'should return custom error message if the value is not a valid float', + () { + // Arrange + final FloatValidator validator = + FloatValidator(errorText: customErrorMessage); + const String value = 'abc'; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, equals(customErrorMessage)); + }); + }); + + test('should return null when the value is null and null check is disabled', + () { + // Arrange + const FloatValidator validator = + FloatValidator(checkNullOrEmpty: false); + const String? value = null; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNull); + }); + + test('should return the default error message when the value is null', () { + // Arrange + const FloatValidator validator = FloatValidator(); + const String? value = null; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNotNull); + expect( + result, + equals( + validator.errorText, + ), + ); + }); + + test( + 'should return null when the value is an empty string and null check is disabled', + () { + // Arrange + const FloatValidator validator = + FloatValidator(checkNullOrEmpty: false); + const String value = ''; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNull); + }); + + test( + 'should return the default error message when the value is an empty string', + () { + // Arrange + const FloatValidator validator = FloatValidator(); + const String value = ''; + + // Act + final String? result = validator.validate(value); + + // Assert + expect(result, isNotNull); + expect( + result, + equals( + validator.errorText, + ), + ); + }); + + test('should return the default error message for invalid value types', () { + // Arrange + const FloatValidator validator = FloatValidator(); + + // Act & Assert + expect( + validator.validate(false), + equals(validator.errorText), + ); + }); + }); +} diff --git a/test/src/numeric/hexadecimal_validator_test.dart b/test/src/numeric/hexadecimal_validator_test.dart new file mode 100644 index 00000000..a075882f --- /dev/null +++ b/test/src/numeric/hexadecimal_validator_test.dart @@ -0,0 +1,166 @@ +import 'package:faker_dart/faker_dart.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:form_builder_validators/form_builder_validators.dart'; + +void main() { + final Faker faker = Faker.instance; + final String customErrorMessage = faker.lorem.sentence(); + + group('HexadecimalValidator -', () { + test('should return null if the value is a valid hexadecimal string', () { + // Arrange + final HexadecimalValidator validator = + HexadecimalValidator(errorText: customErrorMessage); + const String validHex = '1A3F'; + + // Act + final String? result = validator.validate(validHex); + + // Assert + expect(result, isNull); + }); + + test( + 'should return null if the value is a valid generated hexadecimal string', + () { + // Arrange + final HexadecimalValidator validator = + HexadecimalValidator(errorText: customErrorMessage); + final String validHex = faker.datatype.hexaDecimal(); + + // Act + final String? result = validator.validate(validHex); + + // Assert + expect(result, isNull); + }); + + test( + 'should return the error text if the value is not a valid hexadecimal string', + () { + // Arrange + final HexadecimalValidator validator = + HexadecimalValidator(errorText: customErrorMessage); + const String invalidHex = 'XYZ123'; + + // Act + final String? result = validator.validate(invalidHex); + + // Assert + expect(result, customErrorMessage); + }); + + test('should return the error text if the value is empty', () { + // Arrange + final HexadecimalValidator validator = + HexadecimalValidator(errorText: customErrorMessage); + const String emptyHex = ''; + + // Act + final String? result = validator.validate(emptyHex); + + // Assert + expect(result, customErrorMessage); + }); + + test('should return the error text if the value is null', () { + // Arrange + final HexadecimalValidator validator = + HexadecimalValidator(errorText: customErrorMessage); + const String? nullHex = null; + + // Act + final String? result = validator.validate(nullHex); + + // Assert + expect(result, customErrorMessage); + }); + + test('should return the error text if the value is whitespace', () { + // Arrange + final HexadecimalValidator validator = + HexadecimalValidator(errorText: customErrorMessage); + const String whitespaceHex = ' '; + + // Act + final String? result = validator.validate(whitespaceHex); + + // Assert + expect(result, customErrorMessage); + }); + + test( + 'should return the default error text if the value is invalid and no custom error message is provided', + () { + // Arrange + final HexadecimalValidator validator = HexadecimalValidator(); + const String invalidHex = 'XYZ123'; + + // Act + final String? result = validator.validate(invalidHex); + + // Assert + expect(result, FormBuilderLocalizations.current.hexadecimalErrorText); + }); + + test('should return null if the value is valid according to a custom regex', + () { + // Arrange + final RegExp customRegex = RegExp(r'^[0-9a-f]+$'); + final HexadecimalValidator validator = HexadecimalValidator( + regex: customRegex, errorText: customErrorMessage); + const String validHex = '1a3f'; + + // Act + final String? result = validator.validate(validHex); + + // Assert + expect(result, isNull); + }); + + test( + 'should return the custom error text if the value is invalid according to a custom regex', + () { + // Arrange + final RegExp customRegex = RegExp(r'^[0-9a-f]+$'); + final HexadecimalValidator validator = HexadecimalValidator( + regex: customRegex, errorText: customErrorMessage); + const String invalidHex = '1A3F'; + + // Act + final String? result = validator.validate(invalidHex); + + // Assert + expect(result, customErrorMessage); + }); + + test('should return null when the value is null and null check is disabled', + () { + // Arrange + final HexadecimalValidator validator = + HexadecimalValidator(checkNullOrEmpty: false); + const String? nullHex = null; + + // Act + final String? result = validator.validate(nullHex); + + // Assert + expect(result, isNull); + }); + + test( + 'should return null when the value is empty and null check is disabled', + () { + // Arrange + final HexadecimalValidator validator = + HexadecimalValidator(checkNullOrEmpty: false); + const String emptyHex = ''; + + // Act + final String? result = validator.validate(emptyHex); + + // Assert + expect(result, isNull); + }); + }); +}