getDeviceScreenSize method

Future<String> getDeviceScreenSize()

Retrieves the screen size of the device.

Returns the screen size as a string in the format 'width x height'. If an error occurs, it returns 'Unknown'.

Implementation

Future<String> getDeviceScreenSize() async {
  try {
    final size = MediaQueryData.fromView(
            WidgetsBinding.instance.platformDispatcher.views.first)
        .size;
    final width = size.width;
    final height = size.height;
    return '${width.toInt()} x ${height.toInt()}';
  } catch (e) {
    debugPrint('Error getting screen size: $e');
    return 'Unknown';
  }
}