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

flutter_alice 封面
套件詳情v3.0.0

flutter_alice

Alice 是一個 HTTP 檢查工具,可協助除錯 HTTP 請求。它會捕獲並儲存 HTTP 請求和回應,可透過簡單的 UI 進行檢視。

AndroidiOSmacOSWindowsLinux
近 30 天下載
1.2萬
喜歡數
52
Pub 分數
140

安裝套件

flutter pub add flutter_alice

套件介紹

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

Flutter Alice 是一個用於 HTTP 請求的除錯工具,可捕捉並儲存所有送出的請求及其回應。它提供一個簡單直覺的使用者介面,用以檢視每個請求與回應的完整細節,包含標頭、主體、狀態碼與時間。非常適合開發者在應用程式開發與測試期間使用,能快速識別 API 通訊中的問題。此工具可無縫整合至 Flutter 應用程式中,並支援多個平台,讓 Android、iOS、macOS、Windows 及 Linux 都能輕鬆使用。其開源性質確保了透明度與社群貢獻。

適用情境

  • 開發過程中調試 API 呼叫
  • 檢查請求/回應標頭和正文
  • 監控網路效能
  • 測試 RESTful 服務
  • 排查失敗的 HTTP 請求

主要特色

  • 即時 HTTP 請求記錄
  • 基於網絡的互動式檢查使用者介面
  • 支援所有主要平台
  • 透過 pub.dev 實現輕鬆整合
  • 開源且可自訂

適合對象

  • Flutter 開發者
  • API 測試人員
  • 移動應用調試器
  • 前端工程師
  • 團隊協作解決網路問題

使用建議

  • 不建議用於生產建構
  • 需要在開發模式下手動啟用
  • 使用者介面可能不適合複雜的資料結構
  • 僅限HTTP流量
  • 在高負載使用期間可能輕微影響效能

原始 README

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

A ⭐ star on GitHub repo is the greatest motivation for me

to keep improving this project! 💖

Alice

pub package pub package pub package

Alice is an HTTP Inspector tool for Flutter which helps debugging http requests. It catches and stores http requests and responses, which can be viewed via simple UI. It is inspired from Chuck (https://github.com/jgilfelt/chuck) and Chucker (https://github.com/ChuckerTeam/chucker).

Overlay bubble version of Alice: https://github.com/jhomlala/alice

Supported Dart http client plugins:

  • Dio
  • HttpClient from dart:io package
  • Http from http/http package
  • Generic HTTP client

Features:
✔️ Detailed logs for each HTTP calls (HTTP Request, HTTP Response)
✔️ Inspector UI for viewing HTTP calls
✔️ Statistics
✔️ Support for top used HTTP clients in Dart
✔️ Error handling
✔️ HTTP calls search ✔️ Bubble overlay entry

Install

  1. Add this to your pubspec.yaml file:
dependencies:
  flutter_alice: ^1.0.1
  1. Install it
$ flutter pub get
  1. Import it
import 'package:flutter_alice/alice.dart';

Usage

Alice configuration
  1. Create Alice instance:
// Define a navigator key
final navigatorKey = GlobalKey<NavigatorState>();

// Create Alice with the navigator key
final alice = Alice(navigatorKey: navigatorKey);
  1. Add navigator key to your application:
MaterialApp(
  navigatorKey: navigatorKey,
  home: YourHomeWidget(),
)

You need to add this navigator key in order to show inspector UI.

  1. Optional: To use bubble overlay, wrap your app with OverlaySupport:
// Don't forget to import overlay_support package
import 'package:overlay_support/overlay_support.dart';

OverlaySupport(
  child: MaterialApp(
    navigatorKey: navigatorKey,
    home: YourHomeWidget(),
  ),
)
HTTP Client configuration
For Dio

Add interceptor to your Dio instance:

final dio = Dio();
dio.interceptors.add(alice.getDioInterceptor());
For HTTP package

You can use extension methods for cleaner code:

// Import extensions
import 'package:flutter_alice/core/alice_http_extensions.dart';

// Use extension methods
http
  .get(Uri.parse('https://jsonplaceholder.typicode.com/posts'))
  .interceptWithAlice(alice);

// For POST requests with body
http
  .post(Uri.parse('https://jsonplaceholder.typicode.com/posts'), body: body)
  .interceptWithAlice(alice, body: body);

Or use the standard approach:

http.get(Uri.parse('https://jsonplaceholder.typicode.com/posts')).then((response) {
  alice.onHttpResponse(response);
});

// For POST requests with body
http.post(Uri.parse('https://jsonplaceholder.typicode.com/posts'), body: body).then((response) {
  alice.onHttpResponse(response, body: body);
});
For HttpClient from dart:io

You can use extension methods:

// Import extensions
import 'package:flutter_alice/core/alice_http_client_extensions.dart';

// Use extension methods
httpClient
  .getUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"))
  .interceptWithAlice(alice);

// For POST requests with body
httpClient
  .postUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"))
  .interceptWithAlice(alice, body: body, headers: Map());

Or use the standard approach:

httpClient
  .getUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"))
  .then((request) async {
    alice.onHttpClientRequest(request);
    var httpResponse = await request.close();
    var responseBody = await utf8.decoder.bind(httpResponse).join();
    alice.onHttpClientResponse(httpResponse, request, body: responseBody);
  });

### Opening the Inspector
You can open the inspector UI in different ways:

```dart
// Open directly
ElevatedButton(
  child: Text("Open Inspector"),
  onPressed: alice.showInspector,
)

// Or call from anywhere in your code
alice.showInspector();

所屬分類

依賴

依賴清單 4 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。