dart_lib 1.0.1
dart_lib: ^1.0.1 copied to clipboard

Faker for dart.

Library based on faker.js

Install #

dart pub add dart_lib
dependencies:
  dart_lib: ^1.0.0

Usage #

import 'package:dart_lib/dart_lib.dart';

class User {
  String firstName, lastName, country, city, email;
  User(this.firstName, this.lastName, this.country, this.city, this.email);
}

Future<void> main(List<String> args) async {
  var fake = await Faker().fake(); // English By default

  var firstName = Faker.shuffle(fake['name']['first_name']);
  var lastName = Faker.shuffle(fake['name']['last_name']);
  var country = Faker.shuffle(fake['address']['country']);
  var city = Faker.shuffle(fake['address']['city_name']);
  var smtp = Faker.shuffle(fake['internet']['free_email']);
  var email = '$firstName.$lastName@$smtp';

  var user = User(firstName, lastName, country, city, email);
  print(user.firstName);
  print(user.lastName);
  print(user.country);
  print(user.city);
  print(user.email);

  // By Locale
  var heFaker = await Faker.Locale('he').fake(); // Hebrew

  firstName = Faker.shuffle(heFaker['name']['first_name']);
  lastName = Faker.shuffle(fake['name']['last_name']);
  country = Faker.shuffle(fake['address']['country']);
  city = Faker.shuffle(fake['address']['city_name']);
  smtp = Faker.shuffle(fake['internet']['free_email']);
  email = '$firstName.$lastName@$smtp';

  user = User(firstName, lastName, country, city, email);
  print(user.firstName);
  print(user.lastName);
  print(user.country);
  print(user.city);
  print(user.email);

  var frFaker = await Faker.Locale('fr').fake(); //France

  firstName = Faker.shuffle(frFaker['name']['first_name']);
  lastName = Faker.shuffle(frFaker['name']['last_name']);
  country = Faker.shuffle(frFaker['address']['country']);
  city = Faker.shuffle(frFaker['address']['city_name']);
  smtp = Faker.shuffle(frFaker['internet']['free_email']);
  email = '$firstName.$lastName@$smtp';

  user = User(firstName, lastName, country, city, email);
  print(user.firstName);
  print(user.lastName);
  print(user.country);
  print(user.city);
  print(user.email);

  // ....
}



## Full Documentaion

Faker.js [issue tracker][tracker].

[tracker]: https://github.com/marak/Faker.js/