搜索分类、插件与代码仓

插件详情v2.0.1

mock_data

使用 Dart 生成随机数据。可用于创建随机字符串、整数、名称、颜色、IP 地址、UUID、URL 和日期。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
2290
喜欢数
29
Pub 分数
160

安装插件

flutter pub add mock_data

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

mock_data 包在 Dart 中生成随机且真实的测试数据。它提供了创建随机字符串、整数、姓名、颜色、IP 地址、UUID、URL 和日期的工具,非常适合在开发和测试过程中模拟真实世界的数据。该包轻量且易于集成,支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。它特别适用于用占位内容填充 UI 或在不依赖外部源的情况下测试数据处理逻辑。

适合场景

  • 使用示例数据填充UI原型
  • 测试数据解析和显示逻辑
  • 生成虚假用户资料
  • 模拟 API 响应
  • 创建随机测试数据集
  • 使用虚拟输入填写表单

主要特点

  • 支持多种数据类型(字符串、数字、日期等)
  • 跨平台兼容性
  • 简单、直观的 API
  • 生成看起来真实的值
  • 通过 Flutter pub 实现轻松集成
  • 无外部依赖

适合对象

  • 开发人员创建原型
  • 需要随机输入的测试人员
  • 构建原型应用的团队
  • 前端开发人员原型设计用户界面
  • 任何人需要快速的虚假数据

使用建议

  • 不适合用于生产数据生成
  • 随机性可能不具备密码学安全性
  • 特定格式的自定义选项有限
  • 不支持复杂数据结构(开箱即用)
  • 仅限开发/测试环境使用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Mock Data Logo
Build Status License Version
Generate random data using Dart

Features

API provides generation of:

  • Integers in any range of numbers
  • Strings with various characters and length
  • Colors represented with needed color space
  • Dates between different moments in time
  • Names such as John or Mary
  • UUIDv4 and Timestamp-first UUIDs
  • URLs with many fragments
  • IPv4 and IPv6
  • Locations as either random points or in specified radius

Usage

A simple usage example:

import 'package:mock_data/mock_data.dart';

main() {

  mockName();           // Generate male or female first name. 
  mockName('male');     // Generate male first name. 
  mockName('female');   // Generate female first name. 

  mockInteger(1, 6);    // Generate integer in range from 1 do 6.

  mockString(16);       // Generate string of length 16.
  
  mockIPv4();           // Generate IPv4 represented with 
                        // format(default is '*.*.*.*') as String. 
  
  mockIPv6();           // Generate IPv6, same usage as with IPv4.

  mockColor('hex');     // Generate color represented in hex format.
  mockColor('rgb');     // Generate color represented in RGB format.
  
  mockUUID();           // Generate UUIDv4
  
  mockLocation();       // Generate random location.
  mockLocation(53.55, 108.14, 1000); // Generate random location in 1000 m radius from the specified coordinates.
  
}

These are some basic examples. There are many more methods and they all support tweeking of parameters to suit you in generating random data. By reading examples you can learn more about functionality and usage of mock_data

Contributors
License

MIT

所属分类

源码仓库

使用此插件的项目