Home > OS >  How can I determine maximum X and maximum Y of flutter screen?
How can I determine maximum X and maximum Y of flutter screen?

Time:09-08

I try to find maximum x and maximum y of screen size by height and width and below image and code.

Expected Output

enter image description here

Path drawPath(){
        double width = window.physicalSize.width;
        double height = window.physicalSize.height;
        Path path = Path();
        path.moveTo(0,0);
        path.lineTo(width, height);
        return path;
  }

Getting Output

enter image description here

So how can I find Maximum X and Maximum Y in flutter screen ?

Expected output(not perfect but approx.) getting by this code.

Path drawPath(){
            double width = window.physicalSize.width;
            double height = window.physicalSize.height;
            Path path = Path();
            path.moveTo(0,0);
            path.lineTo(width/2, height/2); //need to divide by 2
            return path;
      }

CodePudding user response:

If you have access to the BuildContext, you can retrieve width and height such as:

final double width = MediaQuery.of(context).size.width;
final double height = MediaQuery.of(context).size.height;

Or if you don't:

import 'dart:ui';

final double width = window.physicalSize.width / window.devicePixelRatio;
final double height = window.physicalSize.height / window.devicePixelRatio;
  • Related