flunt_dart 0.4.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

Flunt-dart #

Build Status codecov

Library that provides a fluent way to use Notification Pattern. It is based on Flunt.

Usage #

Create a contract #

Create a contract for a attribute ou a class.

class Customer {
  final String firstName;
  final String lastName;

  Customer(this.firstName, this.lastName);
}

class NameContract extends Contract<String> {
  NameContract(String value, String name) : super(value, name) {
      isNotEmpty("not should be empty");
      hasMaxLen(40, "should have no more than 40 chars");
      hasMinLen(3, "should have at least 3 chars");
  }
}

class CustomerContract extends Contract<Customer> {
  CustomerContract(
    Customer customer,
  ) : super(customer, "Customer") {
    addNotifiable(NameContract(customer.firstName, "First Name"));
    addNotifiable(NameContract(customer.lastName, "Last Name"));
  }
}

Use the contract #

  var customer = Customer("Pedro", "Bissonho");
  var customerContract = CustomerContract(customer);

  if (customerContract.valid) {
    // The customer is valid and can be used.
  }

BrContract #

O BrContract prove validações especificas para o Brasil.
// Métodos atualmente disponíveis.
isCep("O CEP não é válido.")
isCnpj("O CPNJ não é válido")
isCpf("O CPF não é válido");
The BrContract provides specific validations for brazil.
// Methods currently available.
isCep("O CEP not is valid.")
isCnpj("O CPNJ not is valid")
isCpf("O CPF not is valid");

Validations #

Num

void isGreaterThan(int compare, String message);
void isLowerThan(int compare, String message);
void between(num from, num to, String message);
void notBetween(num from, num to, String message);

String

void hasLen(int length, String message);
void hasMaxLen(int max, String message);
void hasMinLen(int min, String message);
void isWhiteSpace(String message); 
void constains(String value, String message);
void isNotEmpty(String message); 
void isEmpty(String message);

Object

void isNull(String message)
void isNotNull(String message)
void equasA(Object compare, String message); 

Pattern

void matchs(String pattern, String message);
void isUrl(String message);
void isEmail(String message);
void isDigit(String message);

Bool

void isTrue(String message);
void isFalse(String message); 

Credits #

This library uses concepts and implementations based from the following repositories.

0.4.0 #

  • Added BrContract.
  • Breaking Change: The contract no longer has the notIsEmpty method. Use the isNotEmpty method.

0.2.0 #

  • Notifiable return a immutable list.
  • Fixed a bug in Notifiable.

0.0.3 #

  • Added forProperty method in Notifiable class.
  • Documentation updates.

0.0.2 #

Documentation updates.

0.0.1 #

  • Initial version

example/example.dart

import 'package:flunt_dart/flunt_dart.dart';

class Customer {
  final String firstName;
  final String lastName;

  Customer(this.firstName, this.lastName);
}

class NameContract extends Contract<String> {
  NameContract(String value, String name) : super(value, name) {
    isNotEmpty("not should be empty");
    hasMaxLen(40, "should have no more than 40 chars");
    hasMinLen(3, "should have at least 3 chars");
  }
}

class CustomerContract extends Contract<Customer> {
  CustomerContract(Customer user) : super(user, "Customer") {
    addNotifiable(NameContract(user.firstName, "First Name"));
    addNotifiable(NameContract(user.firstName, "Last Name"));
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flunt_dart: ^0.4.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:flunt_dart/flunt_dart.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 Mar 26, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

Document public APIs. (-0.55 points)

65 out of 66 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.5.0 <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.0
test_coverage ^0.3.0+1