display_metrics_macos 1.0.1 copy "display_metrics_macos: ^1.0.1" to clipboard
display_metrics_macos: ^1.0.1 copied to clipboard

PlatformmacOS
unlisted

macOS platform implementation of display_metrics plugin. This package will be automatically included in your app when you use display_metrics in macOS project

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:display_metrics_macos/display_metrics_macos.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late final DisplayMetricsMacos _displayMetricsPlugin;
  Size? _resolution;
  String? _resolutionError;
  Size? _size;
  String? _sizeError;

  @override
  void initState() {
    super.initState();
    _displayMetricsPlugin = DisplayMetricsMacos();
    _getResolution();
    _getSize();
  }

  Future<void> _getResolution() async {
    try {
      final resolution = await _displayMetricsPlugin.getResolution();
      setState(() {
        _resolution = resolution;
        _resolutionError = null;
      });
    } on PlatformException {
      setState(() {
        _resolutionError = 'Failed to get screen resolution';
      });
    }
  }

  Future<void> _getSize() async {
    try {
      final size = await _displayMetricsPlugin.getSize();
      setState(() {
        _size = size;
        _sizeError = null;
      });
    } on PlatformException {
      setState(() {
        _sizeError = 'Failed to get screen size';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('display resolution: ${_resolution ?? _resolutionError}'),
              Text('display size: ${_size ?? _sizeError}'),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
160
points
715
downloads

Publisher

verified publishernukeolay.dev

Weekly Downloads

macOS platform implementation of display_metrics plugin. This package will be automatically included in your app when you use display_metrics in macOS project

Repository (GitHub)
View/report issues

Topics

#screen #ppi #size #resolution #pixels

Documentation

API reference

License

MIT (license)

Dependencies

display_metrics_platform_interface, flutter

More

Packages that depend on display_metrics_macos