搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.0

the_validator

一個簡單易用的 Flutter 驗證套件,可用於驗證表單欄位、字串與值

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
183
喜歡數
25
Pub 分數
130

安裝套件

flutter pub add the_validator

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

驗證器是一個輕量級的Flutter套件,專為簡單且高效地進行表單欄位、字串與數值驗證而設計。它提供一個乾淨直覺的API,可驗證電子郵件、密碼及自訂條件等輸入內容。適合尋求快速整合而無需複雜設定的開發者,支援Android、iOS、Web、macOS、Windows與Linux等多個平台。此套件透過在表單輸入時提供即時回饋,提升使用者體驗。其極簡的設計讓它容易應用於任何需要基本或進階驗證邏輯的Flutter專案中。

適用情境

  • 表單輸入驗證
  • 電子郵件和密碼檢查
  • 自定驗證規則
  • 即時用戶反饋
  • 使用者表單中的資料完整性
  • 跨平台驗證

主要特色

  • 簡單 API
  • 支援多種驗證類型
  • 即時驗證
  • 跨平台相容性
  • 可擴充的驗證規則
  • 輕量且快速

適合對象

  • 初學者 Flutter 開發者
  • 需要快速驗證的專案
  • 行動與Web應用程式
  • 表單密集型應用
  • 具有嚴格資料輸入需求的應用程式
  • 偏好最小依賴的開發者

使用建議

  • 僅限基本驗證需求
  • 無內建國際化支援
  • 需要手動處理錯誤訊息
  • 不適合高度複雜的驗證工作流程
  • 依賴外部 GitHub 倉庫
  • 基本範例以外的文件很少

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

The Validator

A simple & lightweight form and data validation package for flutter

How to use

The Validator can be used directly on a TextFormField validator parameter TextFormField(validator: FieldValidator.email())

The Validator can also be used as a stand alone validator Validatror.isPassword('SecretPass', shouldContainCapitalLetter: true)

Sample Usage (FieldValidator)

TextFormField( 
    controller: _emailController,
    validator: FieldValidator.email(),
    decoration: InputDecoration(labelText: "Email"),
    ),
                
 TextFormField( 
    controller: _passwordController,
        validator: FieldValidator.password(
        minLength: 8,
        shouldContainNumber: true,
        shouldContainCapitalLetter: true,
        shouldContainSmallLetter: true,
        shouldContainSpecialChars: true,
        errorMessage: "Password must match the required format",
        isNumberNotPresent: () { return "Password must contain number"; },
        isSpecialCharsNotPresent: () { return "Password must contain special characters"; },
        isCapitalLetterNotPresent: () { return "Password must contain capital letters"; }
        ),
        decoration: InputDecoration(labelText: "Email"),
    ),

To validate confirm password field

  // To validate confirm password field
  TextFormField(
      controller: _confirmPasswordController,
      obscureText: true,
      validator: FieldValidator.equalTo(_passwordController, message: "Password Mismatch"),
      decoration: InputDecoration(labelText: "Confirm Password"),
  )

Then make a call to formState .validate() to perform the validations on the textfields


RaisedButton(
  onPressed: () {
    // validate() inputed data
    if (_formKey.currentState.validate()) {

          _scaffoldKey.currentState
          .showSnackBar(SnackBar(content: Text("Yay! we got it right!")));
                      
    }
  },
  child: Text("Submit"),                  
)

Sample Usage 2 (Validator)

var password = 'Secret'
var confirmPassword = 'secret'
if (Validator.isPassword(password, shouldContainCapitalLetter: true)) {
  if (Validator.isEqualTo(password, confirmPassword)) {
    print("Go ahead & grant access")
  } else {
    print("Password mis match")
  }
}

Error messages

By default The Validator will give you a nice default error based on the the type of validation you specify for field or an input. But you can also override the default message

Default Error Messages

FieldValidator.alphaNumeric() will output Field must contain both alphabets and numbers

User Defined Error Message

FieldValidator.alphaNumeric(message: 'Your username must contain both numbers & alphabets')

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。