auto_validating_text_field 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 69

auto_validating_text_field #

A Flutter package which validates text field dynamically as soon as value changes. You can give list of validators as shown below in example to dynamically validate according to the validators.

Usage #

To use this package, add

auto_validating_text_field :

as a dependency in your pubspec.yaml file.

Example #

AutoValidatingTextFormField(
  decoration: InputDecoration(
  hintText: "Full Name",
  ),
  focusNode: _fullNameFocusNode,
  controller: _fullNameController,
  validators: [
    Validators.required(),
    Validators.pattern("^[a-zA-Z ]*\$",
      errorText: "Full Name cannot contains special characters."),
  ]
);

Please see the example app of this package for a full example in https://github.com/rmsh03dhj/auto_validating_text_field/tree/master/example/lib.

[0.0.1] - 2020-05-23 #

Initial Open Source release

[0.0.2] - 2020-05-23 #

Adding example

[0.1.0] - 2020-05-31 #

First stable release

[0.1.1] - 2020-05-31 #

Updating rx dart package

[0.1.2] - 2020-06-14 #

Updating logic to consider the empty value once user deletes the content

[0.1.3] - 2020-06-21 #

Supporting older version of rxDart as well.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:auto_validating_text_field/auto_validating_text_field.dart';
import 'Validators.dart';
import 'sign_up_dto.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: SignUpScreen(),
    );
  }
}

class SignUpScreen extends StatefulWidget {
  @override
  _SignUpScreen createState() => _SignUpScreen();
}

class _SignUpScreen extends State<SignUpScreen> {
  TextEditingController _fullNameController = TextEditingController();
  TextEditingController _phoneNoController = TextEditingController();
  TextEditingController _emailAddressController = TextEditingController();
  TextEditingController _passwordController = TextEditingController();
  TextEditingController _confirmPasswordController = TextEditingController();

  FocusNode _fullNameFocusNode = FocusNode();
  FocusNode _phoneNumberFocusNode = FocusNode();
  FocusNode _emailAddressFocusNode = FocusNode();
  FocusNode _passwordFocusNode = FocusNode();
  FocusNode _confirmPasswordFocusNode = FocusNode();

  final _formKey = GlobalKey<FormState>();
  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

  SignUpDto signUpDetails;
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      body: SingleChildScrollView(
        child: Form(
          key: _formKey,
          child: Column(
            children: <Widget>[
              Container(
                height: 30,
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Center(
                  child: Text(
                    "Sign Up",
                    style: TextStyle(
                      fontSize: 30,
                    ),
                  ),
                ),
              ),
              SizedBox(height: 50),
              Container(
                width: 250,
                child: AutoValidatingTextFormField(
                  decoration: InputDecoration(
                    hintText: "Full Name",
                  ),
                  focusNode: _fullNameFocusNode,
                  controller: _fullNameController,
                  keyboardType: TextInputType.text,
                  textCapitalization: TextCapitalization.words,
                  validators: [
                    Validators.required(),
                    Validators.pattern("^[a-zA-Z ]*\$",
                        errorText:
                        "Full Name cannot contains special characters."),
                  ],
                  onFieldSubmitted: (_) {
                    fieldFocusChange(
                        context, _fullNameFocusNode, _phoneNumberFocusNode);
                  },
                ),
              ),
              SizedBox(height: 20),
              Container(
                width: 250,
                child: AutoValidatingTextFormField(
                  decoration: InputDecoration(
                    hintText: "Phone Number",
                  ),
                  controller: _phoneNoController,
                  focusNode: _phoneNumberFocusNode,
                  keyboardType: TextInputType.number,
                  validators: [
                    Validators.required(),
                    Validators.validLength(5,
                        errorText: "Phone number should be of length 5"),
                  ],
                  onFieldSubmitted: (_) {
                    fieldFocusChange(
                        context, _phoneNumberFocusNode, _emailAddressFocusNode);
                  },
                ),
              ),
              SizedBox(height: 20),
              Container(
                width: 250,
                child: AutoValidatingTextFormField(
                  decoration: InputDecoration(
                    hintText: "Email Addres",
                  ),
                  focusNode: _emailAddressFocusNode,
                  controller: _emailAddressController,
                  keyboardType: TextInputType.emailAddress,
                  validators: [
                    Validators.required(),
                    Validators.pattern(
                        "^[a-zA-Z0-9.!#\$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?)*\$",
                        errorText: "Invalid email address."),
                  ],
                  onFieldSubmitted: (_) {
                    fieldFocusChange(
                        context, _emailAddressFocusNode, _passwordFocusNode);
                  },
                ),
              ),
              SizedBox(height: 20),
              Container(
                width: 250,
                child: AutoValidatingTextFormField(
                  decoration: InputDecoration(
                    hintText: "Password",
                  ),
                  obscureText: true,
                  focusNode: _passwordFocusNode,
                  controller: _passwordController,
                  keyboardType: TextInputType.text,
                  validators: [
                    Validators.required(),
                  ],
                  onFieldSubmitted: (_) {
                    fieldFocusChange(
                        context, _passwordFocusNode, _confirmPasswordFocusNode);
                  },
                ),
              ),
              SizedBox(height: 20),
              Container(
                width: 250,
                child: AutoValidatingTextFormField(
                  decoration: InputDecoration(
                    hintText: "Confirm Password",
                  ),
                  keyboardType: TextInputType.text,
                  focusNode: _confirmPasswordFocusNode,
                  controller: _confirmPasswordController,
                  obscureText: true,
                  validators: [
                    Validators.required(),
                    Validators.matches(
                      _passwordController,
                    )
                  ],
                ),
              ),
              SizedBox(height: 40),
              RaisedButton(
                child: Text(
                  "Sign Up",
                ),
                onPressed: () {
                  if (_formKey.currentState.validate()) {
                    _scaffoldKey.currentState.showSnackBar(
                      SnackBar(
                        content: Text(
                          "Signing up",
                        ),
                        duration: const Duration(seconds: 1),
                      ),
                    );
                  }
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}

void fieldFocusChange(
    BuildContext context, FocusNode currentFocus, FocusNode nextFocus) {
  currentFocus.unfocus();
  FocusScope.of(context).requestFocus(nextFocus);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  auto_validating_text_field: ^0.1.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:auto_validating_text_field/auto_validating_text_field.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
41
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [auto_validating_text_field] that is in a package requiring null.

Health suggestions

Format lib/auto_validating_text_field.dart.

Run flutter format to format lib/auto_validating_text_field.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (rxdart).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
rxdart ^0.23.1 0.23.1 0.24.1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test