Updated 13 November 2024
In app development, things are not different: testing your application with real data can be a pain. This is something where fake data generation can be helpful.
In this blog post we will create a simple UI and fake data in Flutter which looks like as an output below.
Firstly, Create A New Project And Add dependencies Into the Pubspec.yaml file as
1 |
faker: ^2.2.0 |
Create a new Stateless Widget (FakeUserList) and add code for UI as shown below:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
class FakeUserList extends StatelessWidget { List<UserData> users = []; List<UserData> generateFakeUsers(int count) { final faker = Faker(); return List.generate(count, (index) { return UserData( name: faker.person.name(), email: faker.internet.email(), address: faker.address.streetAddress(), ); }); } @override Widget build(BuildContext context) { users = generateFakeUsers(10); return Scaffold( appBar: AppBar( title: const Text('Fake User List'), ), body: ListView.builder( itemCount: users.length, itemBuilder: (context, index) { final user = users[index]; return ListTile( title: Text(user.name), subtitle: Text('${user.email}\n${user.address}'), isThreeLine: true, ); }, ), ); } } |
In the above example code we have create basic UI to display the random generated users list in app as :-
generateFakeUsers
function. This list is stored in the users
variable.Simple UI output for generate fake data in Flutter
Thanks for reading this article ❤️
I hope this blog will help you to learn about Generating Fake Data in Flutter and you will be able to implement it.
For more updates, make sure to keep following Mobikul Blogs to learn more about mobile app development.
Happy Learning ✍️
Other blogs you may like…
Expandable ListView in Flutter
How To Reset Lost Upload Key on Playstore
Flavoring Application in Flutter
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.