flutter_login_validations 0.0.1 copy "flutter_login_validations: ^0.0.1" to clipboard
flutter_login_validations: ^0.0.1 copied to clipboard

A new Flutter project.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_login_validations/flutter_login_validations.dart';
import 'package:fluttertoast/fluttertoast.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String _title = 'Sample App';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const MyStatefulWidget(),
      ),
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({Key? key}) : super(key: key);

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  TextEditingController nameController = TextEditingController();
  TextEditingController passwordController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: const EdgeInsets.all(10),
        child: ListView(
          children: <Widget>[
            Container(
                alignment: Alignment.center,
                padding: const EdgeInsets.all(10),
                child: const Text(
                  'Login',
                  style: TextStyle(
                      color: Colors.blue,
                      fontWeight: FontWeight.w500,
                      fontSize: 30),
                )),
            Container(
              padding: const EdgeInsets.all(10),
              child: TextField(
                controller: nameController,
                decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  labelText: 'User Name',
                ),
              ),
            ),
            Container(
              padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
              child: TextField(
                obscureText: true,
                controller: passwordController,
                decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  labelText: 'Password',
                ),
              ),
            ),
            Container(
                height: 50,
                margin:const EdgeInsets.fromLTRB(0, 20, 0, 0),
                padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
                child: ElevatedButton(
                  child: const Text('Login'),
                  onPressed: () {
                    if(isValid(nameController.text,passwordController.text)){
                      Fluttertoast.showToast(
                          msg: "Successful login"
                      );
                    }
                  },
                )
            ),
          ],
        ));
  }

  bool isValid(String email, String password) {
    bool valid = false;
    if(FlutterLoginValidations.checkFieldIsEmptyOrNot(nameController.text)){
      if(FlutterLoginValidations.emailValidation(nameController.text)){
        if(FlutterLoginValidations.checkFieldIsEmptyOrNot(passwordController.text)){
          if(FlutterLoginValidations.passwordValidationWithoutSpecialCharacters(password, 7, 10)){
            valid = true;
          }
          else{
            Fluttertoast.showToast(
                msg: "Password length should be with in range"
            );
          }
        }
        else{
          Fluttertoast.showToast(
              msg: "Please enter password"
          );
        }
      }
      else{
        Fluttertoast.showToast(
            msg: "Please enter valid mail id"
        );
      }
    }
    else{
      Fluttertoast.showToast(
          msg: "Please enter mail id"
      );
    }
   return valid;
  }
}
0
likes
100
pub points
0%
popularity

Publisher

unverified uploader

A new Flutter project.

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_login_validations