display_metrics 1.0.0 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.
// 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(),
},
),
);
}
}