getNetworkInfo static method

Future<Map<String, dynamic>> getNetworkInfo()

Retrieves network information for web platforms

Returns a map containing:

  • Connection type (wifi, unknown)
  • Network speed (if available)
  • Connection status (online/offline)
  • IP address and MAC address (limited availability on web)

Note: Network connection details are limited on web platforms due to browser security restrictions.

Implementation

static Future<Map<String, dynamic>> getNetworkInfo() async {
  try {
    final navigator = web.window.navigator;

    String connectionType = 'unknown';
    String networkSpeed = 'Unknown';
    bool isConnected = navigator.onLine;

    // Network connection info is not directly available in package:web
    // Use basic online/offline detection
    if (isConnected) {
      connectionType = 'wifi'; // Assume WiFi if connected
      networkSpeed = 'Unknown';
    }

    return {
      'connectionType': connectionType,
      'networkSpeed': networkSpeed,
      'isConnected': isConnected,
      'ipAddress': 'unknown',
      'macAddress': 'unknown',
    };
  } catch (e) {
    final navigator = web.window.navigator;
    return {
      'connectionType': 'unknown',
      'networkSpeed': 'Unknown',
      'isConnected': navigator.onLine,
      'ipAddress': 'unknown',
      'macAddress': 'unknown',
    };
  }
}