搜尋套件、儲存庫與 APP 分類

GitHub 儲存庫samieruashovo/flutter_faker_plus

flutter_faker_plus

samieruashovo/flutter_faker_plus open-source repository details.

flutter_faker_plus 專案封面
星標
0
分支
0
最近推送(UTC)
2025年12月13日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

flutter_faker_plus

A comprehensive fake data generator for Flutter/Dart applications.

Mobile Screenshot

🚀 Features

  • User Profiles: Generate random user profiles with:
    • Name
    • Email
    • Phone number
    • Address
    • Date of birth
    • Gender
    • Profile picture URL
    • Bio
  • E-commerce Products: Create random product data including:
    • Product name
    • Price
    • Category
  • Geolocation: Generate random latitude and longitude coordinates.
  • Lorem Ipsum: Added Lorem Ipsum placeholder text.
  • Future Plans:
    • Add image URLs for e-commerce products.
    • Support additional fake data types.
    • Implement a fake QR code generator.

Flutter Faker Data Generator Example

This example demonstrates how to generate fake user, product, and location data using the flutter_faker_plus library in Flutter.


void main() {
  WidgetsFlutterBinding.ensureInitialized();

  // Register all mock routes
  setupMockServer();

  runApp(const FakeDataApp());
}


class FakeDataApp extends StatelessWidget {
  const FakeDataApp({super.key});
  @override
  Widget build(BuildContext context) {
    // Generate fake user, product, and location data using flutter_faker_plus.
    final UserProfile user =
        UserProfile.generate(); // Generate a fake user profile.
    final EcommerceProduct product =
        EcommerceProduct.generate(); // Generate a fake e-commerce product.
    final GeoLocation location =
        GeoLocation.generate(); // Generate a fake geo-location.

    final LoremIpsum loremIpsum = LoremIpsum();
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Fake Data Generator Example'),
        ),
        body: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('User Profile:', style: TextStyle(fontSize: 20)),
                // Displays a heading for the user profile section.

                Text('Name: ${user.name}'),
                // Displays the generated user's name.

                Text('Email: ${user.email}'),
                // Displays the generated user's email.

                Text('Phone: ${user.phoneNumber}'),
                // Displays the generated user's phone number.

                Text('Address: ${user.address}'),
                // Displays the generated user's address.

                Text('Date of Birth: ${user.dateOfBirth}'),
                // Displays the generated user's date of birth.

                Text('Gender: ${user.gender}'),
                // Displays the generated user's gender.

                Image.network(user.profilePictureUrl),
                // Displays the user's profile picture from a network URL.

                Text('Bio: ${user.bio}'),
                // Displays the generated user's bio.

                SizedBox(height: 20),
                // Adds vertical spacing of 20 pixels.

                Text('E-Commerce Product:', style: TextStyle(fontSize: 20)),
                // Displays a heading for the product section.

                Text('Product: ${product.name}'),
                // Displays the product name.

                Text('Category: ${product.category}'),
                // Displays the product category.

                Text('Price: \$${product.price}'),
                // Displays the product price prefixed with a dollar sign.

                SizedBox(height: 20),
                // Adds vertical spacing of 20 pixels.

                Text('Geo-Location:', style: TextStyle(fontSize: 20)),
                // Displays a heading for the geo-location section.

                Text('Latitude: ${location.latitude}'),
                // Displays the generated latitude.

                Text('Longitude: ${location.longitude}'),
                // Displays the generated longitude.

                SizedBox(height: 20),
                // Adds vertical spacing of 20 pixels.

                Text('Lorem Ipsum:', style: TextStyle(fontSize: 20)),
                Text(
                  loremIpsum.generate(words: 20),
                ),
                SizedBox(height: 5),
                Text(
                  loremIpsum.generate(
                      words: 60, paragraphs: 3, showLoremIpsum: true),
                ),
                SizedBox(
                  height: 600,
                  child: UserPage())
              ],
            ),
          ),
        ),
      ),
    );
  }
}

🧪 Mock API Requests

flutter_faker_plus comes with a mock backend server for testing without a real API.

  1. Setup Mock Server
import 'package:flutter/material.dart';
import 'mock_server.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  setupMockServer(); // Register all mock routes

  runApp(const FakeDataApp());
}

  1. ApiService Example
import 'mock_server.dart';

class ApiService {
  final _client = MockHttpClient(mockApi);

  Future<List<Map<String, dynamic>>> getUsers() async {
    final res = await _client.request(method: HttpMethod.get, path: '/users');
    return (res.data as List).map((e) => Map<String, dynamic>.from(e)).toList();
  }

  Future<Map<String, dynamic>> createUser(Map<String, dynamic> payload) async {
    final res = await _client.request(
      method: HttpMethod.post,
      path: '/users',
      body: payload,
    );
    return Map<String, dynamic>.from(res.data);
  }
}
  1. Using Mock Requests in Widgets
final api = ApiService();

FutureBuilder<List<Map<String, dynamic>>>(
  future: api.getUsers(),
  builder: (context, snapshot) {
    if (!snapshot.hasData) return CircularProgressIndicator();
    final users = snapshot.data!;
    return ListView.builder(
      itemCount: users.length,
      itemBuilder: (_, i) {
        final u = users[i];
        return ListTile(
          title: Text(u['name'] ?? 'No Name'),
          subtitle: Text(u['email'] ?? 'noemail@domain.com'),
        );
      },
    );
  },
);
  1. Create New User
await api.createUser({
  'name': 'John Doe',
  'email': 'john.doe@example.com',
});

🛠 Installation

Add flutter_faker_plus to your pubspec.yaml file:

dependencies:
  flutter_faker_plus: ^2.0.0
Samier Uddin Ahammad Shovo GitHub avatar
GitHub 作者

Samier Uddin Ahammad Shovo ↗

Software Engineer | Flutter | Django | ML/AI

NeosCoderUttara, Dhaka, Bangladesh
語言DartC++CMakeSwiftCHTMLKotlinObjective-C

此儲存庫發佈的套件

使用的依賴

依賴清單 4 項

  • flutter{"sdk":"flutter"}
  • intl^0.20.2
  • flutter_test開發依賴{"sdk":"flutter"}
  • flutter_lints開發依賴^5.0.0

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗