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

PlatformLinux
unlisted

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

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:display_metrics_linux/display_metrics_linux.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 DisplayMetricsLinux _displayMetricsPlugin;
  Size? _resolution;
  String? _resolutionError;
  Size? _size;
  String? _sizeError;

  @override
  void initState() {
    super.initState();
    _displayMetricsPlugin = DisplayMetricsLinux();
    _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
306
downloads

Publisher

verified publishernukeolay.dev

Weekly Downloads

Linux platform implementation of display_metrics plugin. This package will be automatically included in your app when you use display_metrics in Linux 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_linux