搜尋分類、套件與程式碼儲存庫

套件詳情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

所屬分類

原始碼儲存庫

使用此套件的專案