easy_validator 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

easy_validator #

Simple Object Schema Validation for Flutter

Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

[0.0.1] - TODO: Add release date. #

[1.0.0] - Stable version for object schema validation #

example/main.dart

import 'package:easy_validator/easy_validator.dart' as V;

void main() {
  final schema = V.map().shape({
    'email': V.string()
      ..required()
      ..email()
      ..label = "Email",
    'password': V.string()
      ..required()
      ..min(6)
      ..max(8)
      ..label = "Password",
    'isRemember': V.bool()..label = "Remember"
  });

  // valid
  Map errors;
  errors =
      schema.validate({'email': 'mrphu3074@gmail.com', 'password': '123456'});
  print("VALID");
  print(errors); // {} | Empty

  // invalid
  errors =
      schema.validate({'email': 'mrphu3074@gmail', 'password': '123456789'});

  print("INVALID");
  print(errors);
  // {
  //    email: Email must be a valid email,
  //    password: Password must be at most 8 characters
  // }

  // Advance schema
  
    final contactSchema = V.map().shape({
    'firstName': V.string(),
    'lastName': V.string(),
    'phone': V.string(),
    'address': V.string()
  });

  final orderLineSchema = V.map().shape({
    'productId': V.int()..required(),
    'productName': V.string(),
    'qty': V.int()..required(),
    'price': V.double()..required(),
  });

  final saleOrderSchema = V.map().shape({
    'customer': V.string()..required(),
    "companyName": V.string(),
    'invoiceAddress': contactSchema,
    'deliveryAddress': contactSchema,
    'termsAndConditions': V.bool()..required(),
    'orderLines': V.list().of(orderLineSchema)..required()
  });

  final productSchema = V.map().shape({
    'name': V.string()..required()..label="Tên sản phẩm",
    'sku': V.string()..required(),
    'featured_image': V.string(),
    'type': V.string()..oneOf(['consumable', 'service']),
    'category_ids': V.list()..of(V.int()),
    'list_price': V.double()
      ..required()
      ..label = "Price",
    'sale_price': V.double()..label = "Sale Price",
    'cost': V.double()..label = "Cost",
    'description': V.string()
  });

  print(productSchema.validate({
    'name': '',
    'category_ids': [
      1,"abc",3
    ]
  }));
}

Use this package as a library

1. Depend on it

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


dependencies:
  easy_validator: ^1.0.2

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:easy_validator/easy_validator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
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.9+1
  • Flutter: 1.17.3

Analysis suggestions

Package not compatible with SDK dart

because of import path [easy_validator]

Health issues and suggestions

Document public APIs. (-1 points)

246 out of 246 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

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