flutter_screenutil

 

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'dart:ui';


main()=>runApp(MaterialApp(
  home: MyApp(),
));

class MyApp extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return MyAppState();
  }
}


class MyAppState extends State<MyApp> {

  c(DragDownDetails x){
    var a = 750 * x.globalPosition.dx/350.0;
    var b = 1334 * x.globalPosition.dy/672;
    print('a:$a,  b:$b');
  }

  @override
  Widget build(BuildContext context) {

    print(MediaQuery.of(context).size);
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: true)..init(context);
    var t = MediaQuery.of(context).padding.top;
    print('t: $t');

    var s = ScreenUtil.statusBarHeight;
    print('s: $s');

    var wx = window.physicalSize;
    print('wx: $wx');

    var wp = window.padding;
    print('wp: $wp');

    var ss = window.devicePixelRatio;
    print('ss: $ss');

    var su = ScreenUtil.pixelRatio;
    print('su: $su');

    return Scaffold(
//      appBar: AppBar(title: Text('abc'),),
      body: Container(
        width: ScreenUtil().setWidth(750.0),
        height: ScreenUtil().setHeight(1334),
        color: Colors.red,
        child: GestureDetector(
          onPanDown: (v){
            c(v);
          },
          child: Text('HELLO', style: TextStyle(color: Colors.white),),
        ),
      ),
    );
  }
}

  

    原文作者:CrossPython
    原文地址: https://www.cnblogs.com/pythonClub/p/10953487.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞