display_metrics 1.0.0 copy "display_metrics: ^1.0.0" to clipboard
display_metrics: ^1.0.0 copied to clipboard

Flutter plugin to retrieve device display metrics (resolution, size, PPI, diagonal). Convert inches & mm to Flutter logical pixels.

example/lib/main.dart

// This Flutter app demonstrates how to use the display_metrics package
// to access display metrics and convert between logical pixels and real world units.

import 'package:display_metrics_example/screens/metrics.dart';
import 'package:display_metrics_example/screens/ruler.dart';
import 'package:flutter/material.dart';

import 'package:display_metrics/display_metrics.dart';

void main() {
  runApp(const ExampleApp());
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    // add DisplayMetricsWidget to Widget tree above MaterialApp to use
    // DisplayMetrics.of(context) and BuildContext extension methods
    return DisplayMetricsWidget(
      // Set this to true if you need to update size
      // when orientation of your device changes
      updateSizeOnRotate: true,
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        theme: ThemeData.light(
          useMaterial3: true,
        ).copyWith(
          appBarTheme: AppBarTheme(
            color: Colors.blue.shade900,
            foregroundColor: Colors.white,
          ),
          colorScheme: const ColorScheme.light().copyWith(
            primary: Colors.blue.shade900,
            onPrimary: Colors.white,
            surface: Colors.grey.shade300,
            onSurface: Colors.black,
          ),
        ),
        routes: {
          '/': (_) => const MetricsScreen(),
          '/ruler': (_) => const RulerScreen(),
        },
      ),
    );
  }
}
13
likes
160
points
743
downloads

Publisher

verified publishernukeolay.dev

Weekly Downloads

Flutter plugin to retrieve device display metrics (resolution, size, PPI, diagonal). Convert inches & mm to Flutter logical pixels.

Repository (GitHub)
View/report issues

Topics

#screen #ppi #size #resolution #pixels

Documentation

API reference

License

MIT (license)

Dependencies

display_metrics_android, display_metrics_ios, display_metrics_linux, display_metrics_macos, display_metrics_platform_interface, display_metrics_web, display_metrics_windows, flutter

More

Packages that depend on display_metrics