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

套件詳情v2.0.0

dart_strapi

Strapi V4 的 Dart 客戶端

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
63
喜歡數
25
Pub 分數
130

安裝套件

flutter pub add dart_strapi

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個用於 Strapi V4 的 Dart 客戶端,可實現 Dart/Flutter 應用與 Strapi 後端服務的無縫整合。它提供了一個乾淨、類型安全的 API,用於與 Strapi 的 RESTful 端點進行互動,支援認證、資料取得和 CRUD 操作。專為依賴 Strapi 作為無頭 CMS 或後端的開發者設計,簡化了跨多個平台的 API 通訊。

適用情境

  • 將 Flutter 應用與 Strapi V4 後端整合
  • 從無頭CMS獲取和管理內容
  • 使用 Strapi 實現用戶身分驗證
  • 使用即時數據建構動態網頁和行動應用程式
  • 在Flutter客戶端和Strapi伺服器之間同步資料

主要特色

  • 類型安全的 API 呼叫
  • 支援 Strapi V4 驗證
  • 跨平台相容性
  • 透過 Flutter pub 輕鬆設定
  • 內建的錯誤處理與回應解析

適合對象

  • 使用 Strapi V4 的 Flutter 開發人員
  • 建構無頭CMS驅動的應用程式團隊
  • 需要後端整合的行動和網頁應用
  • 尋求輕量級 Strapi 客戶端的開發者
  • 需要跨平台保持一致的 API 互動的項目

使用建議

  • 需要 Strapi V4 後端
  • 僅限 REST API(不支援 GraphQL)
  • 依賴於 Strapi 的 API 結構
  • 可能需要自定義擴展以支援進階功能
  • 驗證流程需要正確設定

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

dart_strapi

dart client for Strapi V4

For Strapi V3 client check v1.2.0

Example

import 'package:dart_strapi/dart_strapi.dart';

final serverUrl = 'http://localhost:1337';
final authToken = '<token>';
final collection = '<collectionType>';
final single = '<singleType>';

void main() async {
  final client = Strapi(
    serverUrl,
    token: authToken,
  );

  final singleResponse = await client.single.get(single);
  print("Single Response: $singleResponse");
  print("Data: ${singleResponse.item1}");
  print("Meta: ${singleResponse.item2}");
  print("\n----------------------------------------------------\n");

  final singleNotFoundResponse = await client.single.get("lalala");
  print("Single Not Found Response: $singleNotFoundResponse"); // [null, null]
  print("Data: ${singleNotFoundResponse.item1}"); // null
  print("Meta: ${singleNotFoundResponse.item2}"); // null
  print("\n----------------------------------------------------\n");

  final collectionResponse = await client.collection.get(collection);
  print("Collection Response: $collectionResponse");
  print("Data: ${collectionResponse.item1}");
  print("Meta: ${collectionResponse.item2}");
  print("\n----------------------------------------------------\n");

  final collectionNotFoundResponse = await client.collection.get('rarara');
  print("Collection Not Found Response: $collectionNotFoundResponse"); // [null, null]
  print("Data: ${collectionNotFoundResponse.item1}"); // null
  print("Meta: ${collectionNotFoundResponse.item2}"); // null
  print("\n----------------------------------------------------\n");

  final collectionSingleResponse = await client.collection.getOne(collection, 1);
  print("Collection Single Response: $collectionSingleResponse");
  print("Data: ${collectionSingleResponse.item1}");
  print("Meta: ${collectionSingleResponse.item2}");
  print("\n----------------------------------------------------\n");

  final collectionSingleNotFoundResponse = await client.collection.getOne("xaxaxa", 1);
  print("Collection Single Not Found Response: $collectionSingleNotFoundResponse"); // [null, null]
  print("Data: ${collectionSingleNotFoundResponse.item1}"); // null
  print("Meta: ${collectionSingleNotFoundResponse.item2}"); // null
  print("\n----------------------------------------------------\n");

  final resourceSingle = await client.resource.get(single);
  print("Resource Single Response: $resourceSingle"); // Response<Data.single>
  print("\n----------------------------------------------------\n");

  final resourceCollection = await client.resource.get(collection);
  print("Resource Collection Response: $resourceCollection"); // Response<Data.collection>
  print("\n----------------------------------------------------\n");

  final resourceCollectionSingle = await client.resource.get("$collection/1");
  print("Resource Collection Single Response: $resourceCollectionSingle"); // Response<Data.single>
  print("\n----------------------------------------------------\n");

  final resourceNoExists = await client.resource.get("lalala");
  print("Resource Not Found Response: $resourceNoExists"); // Response.error
  print("\n----------------------------------------------------\n");
}

Output

Single Response: [{id: 1, attributes: {...}}, Meta(pagination: null)]
Data: {id: 1, attributes: {...}}
Meta: Meta(pagination: null)

----------------------------------------------------

Single Not Found Response: [null, null]
Data: null
Meta: null

----------------------------------------------------

Collection Response: [[{id: 1, attributes: {...}}, {id: 2, attributes: {...}}], Meta(pagination: Pagination(page: 1, pageSize: 25, pageCount: 1, total: 2))]
Data: [{id: 1, attributes: {...}}, {id: 2, attributes: {...}}]
Meta: Meta(pagination: Pagination(page: 1, pageSize: 25, pageCount: 1, total: 2))

----------------------------------------------------

Collection Not Found Response: [null, null]
Data: null
Meta: null

----------------------------------------------------

Collection Single Response: [{id: 1, attributes: {...}}, Meta(pagination: null)]
Data: {id: 1, attributes: {...}}
Meta: Meta(pagination: null)

----------------------------------------------------

Collection Single Not Found Response: [null, null]
Data: null
Meta: null

----------------------------------------------------

Resource Single Response: Response(data: Data.single(data: {id: 1, attributes: {...}}), meta: Meta(pagination: null))

----------------------------------------------------

Resource Collection Response: Response(data: Data.collection(data: [{id: 1, attributes: {...}}, {id: 2, attributes: {...}}]), meta: Meta(pagination: Pagination(page: 1, pageSize: 25, pageCount: 1, total: 2)))

----------------------------------------------------

Resource Collection Single Response: Response(data: Data.single(data: {id: 1, attributes: {...}}), meta: Meta(pagination: null))

----------------------------------------------------

Resource Not Found Response: Response.error(message: ...)

----------------------------------------------------

This package is in active development process, there are implemented methods to query, if you need create / update / delete or call other api you can use client.httpClient to call Dio client directly.

Check Examples for more

所屬分類

依賴

依賴清單 4 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。