physical_diagonal 0.1.1 copy "physical_diagonal: ^0.1.1" to clipboard
physical_diagonal: ^0.1.1 copied to clipboard

Detects physical screen diagonal in inches. Physical diagonal of the screen helps to optimize design for Tablets/bigger screens. Calculation relies on system pixel density information, so it might be [...]

example/lib/main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double _diagonalSize = 0.0;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    double diagonalSize;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      diagonalSize = await PhysicalDiagonal.platformVersion;
    } on PlatformException {
      diagonalSize = 0.0;
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _diagonalSize = diagonalSize;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Define screen diagonal'),
        ),
        body: Center(
          child: (_diagonalSize != 0.0)? Text('Screen diagonal in inches: $_diagonalSize') : Text('Screen size not defined'),
        ),
      ),
    );
  }
}
0
likes
30
pub points
0%
popularity

Publisher

unverified uploader

Detects physical screen diagonal in inches. Physical diagonal of the screen helps to optimize design for Tablets/bigger screens. Calculation relies on system pixel density information, so it might be slightly inaccurate for Android devices (about 5%)

Homepage
Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on physical_diagonal