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

cote_network_logger 封面
套件詳情v1.2.0

cote_network_logger

用於即時HTTP網路監控的美觀Flutter開發工具,附帶Web儀表板

AndroidiOSmacOSWindowsLinux
近 30 天下載
173
喜歡數
28
Pub 分數
150

安裝套件

flutter pub add cote_network_logger

套件介紹

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

Cote Network Logger 是一個 Flutter 開發工具,可實時監控 HTTP 網路請求與回應。它提供一個優雅的 Web 仪表板來視覺化網路活動,讓開發過程中的除錯與效能分析更輕鬆。該工具可無縫整合至 Android、iOS、macOS、Windows 與 Linux 上的 Flutter 應用,提供對請求頭、狀態碼、回應時間及資料內容的詳細洞察。對於處理複雜網路密集型應用的團隊而言,它在無需額外設定(除了最初的 pub add 命令)的情況下提升了可見性。

適用情境

  • 即時 API 調試
  • 網路呼叫的效能監控
  • 團隊協作解決網路問題
  • 開發環境故障排除
  • API 集成測試

主要特色

  • 即時網路儀表板
  • 跨平台支援
  • 請求/回應檢查
  • 顏色編碼的狀態指示器
  • Minimal setup with pub add

適合對象

  • Flutter 開發者
  • 後端API測試人員
  • 移動應用調試器
  • DevOps 團隊
  • 前端工程師

使用建議

  • 不適用於生產使用
  • 需要執行本機Web伺服器
  • 可能影響應用程式效能於除錯模式
  • 僅限開發環境
  • 依賴網路連接以存取儀表板

原始 README

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

🚀 CoteNetworkLogger

A powerful Flutter package for real-time HTTP network monitoring during development and staging environments.

✨ Features

  • 🔍 Real-time network monitoring - See HTTP requests as they happen
  • 📱 Cross-platform support - Android, iOS, macOS, Windows, Linux
  • 🌐 Web dashboard - Beautiful browser-based interface
  • 🎨 Material Design 3 - Modern, responsive UI
  • 🔄 Auto-refresh - Smart refresh that pauses during user interaction
  • 💾 Memory efficient - In-memory storage with auto-cleanup
  • 🌍 Environment support - Debug, Staging, and Release modes

🛠️ Quick Start

  1. Add to your pubspec.yaml:

    dependencies:
      cote_network_logger: ^1.0.5
    
  2. Start the server in your main.dart:

    import 'package:cote_network_logger/cote_network_logger.dart';
    
    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await startNetworkLogServer();
      runApp(MyApp());
    }
    
  3. Add the interceptor to your Dio instance:

    import 'package:dio/dio.dart';
    import 'package:cote_network_logger/cote_network_logger.dart';
    
    final dio = Dio();
    dio.interceptors.add(const CoteNetworkLogger());
    
  4. Open the dashboard URL in your browser!

🌍 Environment Support

The network logger is available in the following environments:

  • ✅ Debug Mode: Always enabled during development
  • ✅ Staging Environment: Enabled when STAGING_ENV=true
  • ✅ Release Mode: Can be enabled with NETWORK_LOGGER_ENABLED=true
  • ❌ Production Environment: Disabled by default for security
Running in Different Environments
Debug Mode (Default)
flutter run
Staging Environment
flutter run --dart-define=STAGING_ENV=true
Release Mode with Logger
flutter run --release --dart-define=NETWORK_LOGGER_ENABLED=true
Building for Different Flavors

For Android:

# Debug flavor
flutter build apk --flavor debug

# Staging flavor
flutter build apk --flavor staging --dart-define=STAGING_ENV=true

# Production flavor
flutter build apk --flavor production

For iOS:

# Debug configuration
flutter build ios --flavor Debug

# Staging configuration
flutter build ios --flavor Staging --dart-define=STAGING_ENV=true

# Release configuration
flutter build ios --flavor Release

📱 Platform Support

iOS Simulator (Best for Mac)
  1. Run your Flutter app on iOS simulator
  2. Open browser on your Mac
  3. Navigate to: http://localhost:3000
Android Emulator
  1. Run your Flutter app on Android emulator
  2. Open browser on the emulator itself
  3. Navigate to: http://localhost:3000
Physical Devices
  1. Find your device's IP address
  2. Open browser on any device on the same network
  3. Navigate to: http://YOUR_DEVICE_IP:3000

🔧 Troubleshooting

Dashboard Not Loading
  • Check if server is running (look for console message)
  • Verify platform support
  • Check environment settings
  • Ensure port 3000 is not blocked
iOS Local Network Setup
  1. Go to iOS Settings → Privacy & Security → Local Network
  2. Find your app and toggle it ON
  3. Run your app and try accessing the dashboard

📚 API Reference

Main Functions
// Start the network logger server
Future<bool> startNetworkLogServer()

// Stop the network logger server
Future<void> stopNetworkLogServer()

// Check if server is running
bool isNetworkLogServerRunning()

// Get dashboard URL
String? getNetworkLogDashboardUrl()

// Check platform support
bool isNetworkLoggerSupported()
Configuration
class NetworkLoggerConfig {
  // Check if logger is enabled
  static bool get isEnabled

  // Get current flavor/environment
  static String get currentFlavor

  // Check if logger is enabled in specific flavor
  static bool isEnabledInFlavor(String flavor)
}
Configuration Examples
Basic Setup
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // Start the logger (automatically handles environment)
  await NetworkLogger.start();
  
  runApp(MyApp());
}
Environment Configuration
void setupNetworkLogger() {
  // Configure with predefined environments
  NetworkLogger.configure(
    environments: [
      NetworkLoggerEnvironment.debug,
      NetworkLoggerEnvironment.staging,
      NetworkLoggerEnvironment.qa,
    ],
  );
}

// Or use custom environments
NetworkLogger.configure(
  environments: [
    NetworkLoggerEnvironment.custom(
      name: 'uat',
      enableByDefault: true,
      description: 'User Acceptance Testing',
    ),
    NetworkLoggerEnvironment.custom(
      name: 'preprod',
      enableByDefault: true,
      description: 'Pre-Production Environment',
    ),
  ],
);
Enable in Release Mode
// Enable logger in release mode for specific environments
NetworkLogger.configure(
  environments: [NetworkLoggerEnvironment.staging],
  enableInRelease: true,
);
Check Logger Status
// Check if logger is running
if (NetworkLogger.isRunning) {
  // Get dashboard URL
  final url = NetworkLogger.dashboardUrl;
  print('Dashboard available at: $url');
}
Environment-Specific Behavior
// The logger automatically handles different environments:
// - Debug: Always enabled
// - Staging: Enabled by default
// - QA: Enabled by default
// - Beta: Enabled by default
// - Production: Always disabled
// - Custom: Configurable via enableByDefault

🎯 Use Cases

Quick Start
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await NetworkLogger.start();
  runApp(MyApp());
}
QA Testing Setup
void setupForQATesting() {
  NetworkLogger.configure(
    environments: [NetworkLoggerEnvironment.qa],
    enableInRelease: true,
  );
}
Multiple Environment Support
void setupAllEnvironments() {
  NetworkLogger.configure(
    environments: [
      NetworkLoggerEnvironment.debug,
      NetworkLoggerEnvironment.staging,
      NetworkLoggerEnvironment.qa,
      NetworkLoggerEnvironment.beta,
    ],
  );
}
Custom Environment
void setupCustomEnvironment() {
  NetworkLogger.configure(
    environments: [
      NetworkLoggerEnvironment.custom(
        name: 'demo',
        enableByDefault: true,
        description: 'Demo Environment',
      ),
    ],
  );
}
Custom Environment Support

The network logger supports custom environment types for flexible configuration:

  1. Add Custom Environments

    // Add your custom environments
    NetworkLoggerConfig.addCustomEnvironment('qa');
    NetworkLoggerConfig.addCustomEnvironment('beta');
    NetworkLoggerConfig.addCustomEnvironment('uat');
    
  2. Run with Custom Environment

    # Run with QA environment
    flutter run --dart-define=CUSTOM_ENV=qa --dart-define=NETWORK_LOGGER_ENABLED=true
    
    # Run with Beta environment
    flutter run --dart-define=CUSTOM_ENV=beta --dart-define=NETWORK_LOGGER_ENABLED=true
    
  3. Environment-Specific Behavior

    • Debug: Always enabled
    • Staging: Enabled by default
    • Custom: Enabled when NETWORK_LOGGER_ENABLED=true
    • Production: Always disabled
QA Testing in Release Mode

The network logger is particularly useful for QA teams testing release builds in staging environment:

  1. Release Mode Testing

    # Build release version with staging environment
    flutter build apk --release --dart-define=STAGING_ENV=true
    
  2. Enable Logger in Release

    # Enable logger in release mode for staging environment
    flutter run --release --dart-define=STAGING_ENV=true --dart-define=NETWORK_LOGGER_ENABLED=true
    
  3. Benefits for QA Teams

    • Monitor network requests in release builds
    • Debug issues in staging environment
    • Test with production-like performance
    • Maintain security in production
Development Workflow
  1. Local Development

    • Debug mode with full logging
    • Real-time request monitoring
    • Immediate feedback
  2. Staging Testing

    • Release mode with controlled logging
    • QA team access to network logs
    • Production-like environment
  3. Production Deployment

    • Logger automatically disabled
    • No performance impact
    • Secure by default

🎯 Example

Check out the example directory for a complete working example.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

所屬分類

依賴

依賴清單 4 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。