floating_logger 是一個 Flutter 套件,可提供浮動小組件以在應用程式開發期間顯示即時 API 請求日誌。它幫助開發者輕鬆監控網路活動,顯示請求 URL、方法、回應時間和狀態碼等詳細資訊。該組件懸浮於螢幕上,方便存取而不會中斷使用者流程。專為除錯與測試設計,可無縫整合至跨多個平台的 Flutter 應用程式中。適合需要快速掌握 API 行為而無需依賴外部工具的團隊。
適用情境
開發過程中的即時 API 監控
在 Flutter 應用中調試網路請求
快速檢查HTTP呼叫詳細資訊
改善團隊在API問題上的協作
在各種條件下測試API效能
主要特色
用於持續日誌可視化的浮動 UI
即時顯示API請求/回應資料
支援所有主要的桌面和行動平台
使用一條命令進行最小化設定
可自訂的日誌過濾和樣式
適合對象
正在開發中的Flutter開發者
專注於API除錯的團隊
需要頻繁進行網路測試的應用程式
使用 REST API 的前端工程師
在需要對網路呼叫進行快速反饋的專案中
使用建議
不適用於生產環境
如果記錄過多資料,可能會影響效能
發布應用前需手動移除
僅限除錯建構
UI 可能會遮蔽小尺寸裝置上的螢幕內容
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
floating_logger 🚀
floating_logger is a Flutter library designed to help developers debug and test API calls with ease. It provides a floating widget that allows you to monitor API requests in real-time and even copy the curl command for quick testing. Perfect for anyone who wants to streamline the development and debugging process! ⚡
📌 Features
✅ Advanced Search & Deep Debugging - Search log path, headers, body, response, and deep JSON content with highlighting and auto-expansion
✅ Dynamic Search Navigation - Easily navigate through multiple search matches with up/down arrows
🎚 Toggle Floating Logger Visibility Using Preferences
Use ValueNotifier to toggle the logger visibility dynamically. This allows you to enable or disable the logger and persist the setting across app sessions.
You can easily customize the appearance of your floating logger widget by using the style property. This allows you to adjust the background color, tooltip, icon, and even the size of the floating widget to match your app’s theme. 🎨✨
backgroundColor: Set a vibrant color to make your floating widget stand out.
tooltip: Add a custom tooltip text to provide helpful hints when hovering over the widget.
icon: Choose an icon (like offline_bolt, info, etc.) and customize its size, color, and appearance.
size: Adjust the size using Size class to adjust floating widget size.
🛠️ Adding a Single Custom Interceptor
To add a single custom interceptor to DioLogger, you can use the addInterceptor method. Here’s an example of adding a custom InterceptorsWrapper that handles the onResponse and onError events.
/// Example to add a custom single interceptorDioLogger.instance.addInterceptor(
InterceptorsWrapper(
onResponse: (response, handler) {
// Add custom logic for onResponseprint('Custom onResponse interceptor');
handler.next(response);
},
onError: (error, handler) {
// Add custom logic for onErrorprint('Custom onError interceptor');
handler.next(error);
},
),
);
Explanation:
onResponse : This is triggered when a successful response is received. You can add custom logic here, such as logging or modifying the response.
onError : This is triggered when an error occurs. You can handle errors, log them, or perform recovery actions.
handler.next() : This ensures the interceptor chain continues to the next interceptor or the final handler.
🛠️ Add List Custom Interceptor
If you want to add multiple interceptors at once, you can use the addListInterceptor method. This is useful when you have several interceptors that need to be applied together.
Here’s an example:
DioLogger.instance.addListInterceptor(
[
InterceptorsWrapper(
onResponse: (response, handler) {
// Add custom logic for onResponseprint('Custom onResponse interceptor');
handler.next(response);
},
onError: (error, handler) {
// Add custom logic for onErrorprint('Custom onError interceptor');
handler.next(error);
},
),
// You can add more interceptors in the list
],
);
Explanation:
List of Interceptors: You can define multiple InterceptorsWrapper objects in a list. Each interceptor will be executed in the order they are added.
Order Matters: The first interceptor in the list will be executed first, followed by the next, and so on.
⚡ Network Simulator (Built-in)
floating_logger comes with a powerful Network Simulator built right in! No extra packages needed. You can easily simulate different network conditions to test how your app handles:
Normal: Standard network behavior.
Slow: Simulates a 3-second delay (configurable).
Offline: Simulates no internet connection (throws error).
floating_logger is a powerful tool that simplifies debugging API calls in Flutter applications. Whether you need to inspect responses, copy cURL commands, or customize the UI, this package provides a seamless experience for developers. Integrate it today and streamline your debugging process! 🚀