Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/speeedev/ist_validator
A simple package to validate for Flutter.
https://github.com/speeedev/ist_validator
dart flutter validate
Last synced: about 1 month ago
JSON representation
A simple package to validate for Flutter.
- Host: GitHub
- URL: https://github.com/speeedev/ist_validator
- Owner: speeedev
- License: bsd-3-clause
- Created: 2024-10-20T16:58:32.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-11-05T20:50:46.000Z (3 months ago)
- Last Synced: 2024-11-05T21:38:24.553Z (3 months ago)
- Topics: dart, flutter, validate
- Language: Dart
- Homepage: https://pub.dev/packages/ist_validator/
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
A versatile validator package for form validation and general use in Dart and Flutter projects. It provides simple and reusable validation rules that can be used in forms or other input validation scenarios.
## Features
- **Form Validation**: Easy-to-use validation rules for forms, including required fields, email validation, and password confirmation.
- **Custom Validation**: Define your own validation rules with simple callback functions.## Usage
### Basic Example with IstValidator
Here is an example of how to use IstValidator to validate email input in a form:
```dart
bool isValidEmail = IstValidator.validateEmail("example@gmail.com");
print(isValidEmail); // truebool isNotEmpty = IstValidator.validateIsNotEmpty("Hello");
print(isNotEmpty); // truebool isEmpty = IstValidator.validateIsEmpty("");
print(isEmpty) // truebool isValidLength = IstValidator.validateMaxLength("hello", 10);
print(isValidLength); // truebool hasMinLength = IstValidator.validateMinLength("hi", 5);
print(hasMinLength); // falsebool isNumber = IstValidator.validateNumber("123.45");
print(isNumber); // truebool passwordsMatch = IstValidator.confirmPassword("password", "password");
print(passwordsMatch); // truebool isLink = IstValidator.validateLink("https://spee.dev");
print(isLink); // true
```### Basic Example with IstFormValidator
```dart
import 'package:flutter/material.dart';
import 'package:ist_validator/ist_validator.dart';class MyApp extends StatefulWidget {
const MyApp({super.key});@override
State createState() => _MyAppState();
}class _MyAppState extends State {
// Global key to identify the form
final _formKey = GlobalKey();// Controllers to get the values of the text fields
final TextEditingController _nameController = TextEditingController();
final TextEditingController _surnameController = TextEditingController();
final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Ist Form Validator Example',
home: Scaffold(
appBar: AppBar(
title: const Text('Register'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey, // Assign the form key
child: Column(
children: [
// Name TextField
TextFormField(
controller: _nameController,
decoration: const InputDecoration(
labelText: 'Name',
),
keyboardType: TextInputType.emailAddress,
validator: (value) => IstFormValidator.customValidate(
value!,
rules: [
RequiredRule(),
MinLengthRule(3),
MaxLengthRule(15),
],
),
),
const SizedBox(height: 16),
// Surname TextField
TextFormField(
controller: _surnameController,
decoration: const InputDecoration(
labelText: 'Surname',
),
keyboardType: TextInputType.emailAddress,
validator: (value) => IstFormValidator.customValidate(
value!,
rules: [
RequiredRule(),
MinLengthRule(3),
MaxLengthRule(15),
],
),
),
const SizedBox(height: 16),
// Email TextField
TextFormField(
controller: _emailController,
decoration: const InputDecoration(
labelText: 'Email',
),
keyboardType: TextInputType.emailAddress,
validator: (value) => IstFormValidator.customValidate(
value!,
rules: [
RequiredRule(),
EmailFormatRule(),
MinLengthRule(3),
MaxLengthRule(50),
],
),
),
const SizedBox(height: 16),
// Password TextField
TextFormField(
controller: _passwordController,
decoration: const InputDecoration(
labelText: 'Password',
),
obscureText: true,
validator: (value) => IstFormValidator.customValidate(
value!,
rules: [
RequiredRule(),
MinLengthRule(6),
MaxLengthRule(15),
],
),
),
const SizedBox(height: 20),
// Submit Button
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
// If the form is valid, show a snackbar or proceed
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Form is valid!')),
);
}
},
child: const Text('Submit'),
),
],
),
),
),
),
);
}
}
```