flux_validator_dart 2.0.0 copy "flux_validator_dart: ^2.0.0" to clipboard
flux_validator_dart: ^2.0.0 copied to clipboard

A package to validate strings and input data for dart with a variety of validators such as cpf, cnpj, car plate, email, phone number and others.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flux_validator_dart/flux_validator_dart.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final appTitle = 'Form Validation Demo';

    return MaterialApp(
      title: appTitle,
      home: Scaffold(
        appBar: AppBar(
          title: Text(appTitle),
        ),
        body: MyCustomForm(),
      ),
    );
  }
}

// Create a Form widget.
class MyCustomForm extends StatefulWidget {
  @override
  MyCustomFormState createState() {
    return MyCustomFormState();
  }
}

// Create a corresponding State class.
// This class holds data related to the form.
class MyCustomFormState extends State<MyCustomForm> {
  // Create a global key that uniquely identifies the Form widget
  // and allows validation of the form.
  //
  // Note: This is a GlobalKey<FormState>,
  // not a GlobalKey<MyCustomFormState>.
  final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    // Build a Form widget using the _formKey created above.
    return Form(
      key: _formKey,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          TextFormField(
              decoration: InputDecoration(
                labelText: 'Email',
              ),
              validator: (value) {
                if (Validator.email(value))
                  return 'Please input a valid email.';
                return null;
              }),
          TextFormField(
              decoration: InputDecoration(
                labelText: 'Cnpj',
              ),
              validator: (value) {
                if (Validator.cnpj(value)) return 'Please input a valid Cnpj.';
                return null;
              }),
          TextFormField(
              decoration: InputDecoration(
                labelText: 'Mercosul Car Plate',
              ),
              validator: (value) {
                if (Validator.carPlate(value))
                  return 'Please input a valid Car Plate.';
                return null;
              }),
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 16.0),
            child: MaterialButton(
              onPressed: () {
                // Validate returns true if the form is valid, or false
                // otherwise.
                if (_formKey.currentState.validate()) {
                  // If the form is valid, display a Snackbar.
                  ScaffoldMessenger.of(context)
                      .showSnackBar(SnackBar(content: Text('Processing Data')));
                }
              },
              child: Text('Submit'),
            ),
          ),
        ],
      ),
    );
  }
}
22
likes
110
pub points
84%
popularity

Publisher

unverified uploader

A package to validate strings and input data for dart with a variety of validators such as cpf, cnpj, car plate, email, phone number and others.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-2-Clause (LICENSE)

More

Packages that depend on flux_validator_dart