Skip to content
pubscout

display_metrics

2.7.0, released 3 weeks ago by nukeolay.dev

Retrieve physical display size, resolution, and PPI, and convert inches and mm to logical pixels.

WASM-ready
$ flutter pub add display_metrics
Source repository

What it does

A Flutter plugin that retrieves physical display metrics such as resolution, size in inches, diagonal, and PPI across multiple platforms. It provides a widget and BuildContext extensions to convert physical units like inches and millimeters into Flutter logical pixels.

AI-written summary of version 2.7.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need physical display dimensions like inches or millimeters for accurate scaling or UI creation.
  • You need to convert physical measurements (inches, mm) directly into Flutter logical pixels.

Skip it when

  • You are targeting web platforms where physical dimensions cannot be accurately determined due to browser limitations.

Strengths

  • Supports multiple platforms including Android, iOS, Windows, macOS, Linux, and Web.
  • Provides convenient BuildContext extension methods for unit conversion.
  • Handles unknown or new devices via an onUnknownDisplay callback.

Weaknesses

  • Physical dimensions and DPI cannot be accurately determined on the web platform due to browser restrictions.
  • Requires placing DisplayMetricsWidget above MaterialApp in the widget tree.

Setup

Kind
Plugin (native code)
Effort
Low
Code generation
No
Direct dependencies
7

Add DisplayMetricsWidget above MaterialApp in your widget tree to enable DisplayMetrics.of(context) and BuildContext extensions.

DisplayMetricsWidget(
  child: MaterialApp(
    home: Scaffold(
      body: const BodyWidget(),
    ),
  ),
);

Alternatives

Packages that do the same job and could replace display_metrics.