Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fakers in a list #68

Open
RicardoMudinyane opened this issue Dec 27, 2022 · 1 comment
Open

Multiple fakers in a list #68

RicardoMudinyane opened this issue Dec 27, 2022 · 1 comment

Comments

@RicardoMudinyane
Copy link

I am trying to create multiple users with lastName, firstName, email and so on...
I have a for loop and call faker each time, but it's creating the same user multiple times. I expected it to create multiple users with different names and so on...

Code snippet

for (int i = 0; i < 10; i++){
   var faker = Fake();
  
  users.add(
    Users(
      userid: faker.person.random.string(10),
      name: faker.person.firstName(),
      surname: faker.person.lastName(),
      phone: faker.phoneNumber.us(),
      email: faker.internet.email(),
      username: faker.internet.userName(),
    )
  );
}
@joaoantoniomartinsfilho

Hi @RicardoMudinyane, how are you doing?

I've run this code:

import 'package:faker/faker.dart';

void main() {
  final List<User> users = [];

  for (int i = 0; i < 10; i++) {
    var faker = Faker();

    users.add(User(
      name: faker.person.firstName(),
      lastName: faker.person.lastName(),
    ));
  }

  for (var user in users) {
    print('${user.name} ${user.lastName}');
  }
}

class User {
  String name;
  String lastName;

  User({required this.name, required this.lastName});
}

And got this output:

image

Are you still facing the error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants