美文网首页
flutter 基本操作

flutter 基本操作

作者: 苍老师的眼泪 | 来源:发表于2020-10-23 03:16 被阅读0次
  1. 获取一个uuid
//https://pub.dev/packages/uuid

//在pubspec.yaml中添加
dependencies:
  uuid: 2.2.2
//引入文件,设置变量,生成uuid
import 'package:uuid/uuid.dart';
var uuid = Uuid();
uuid.v4();

  1. 获取设备横竖方向, 尺寸,DPR
//Orientation.landscape or Orientation.portrait
MediaQuery.of(context).orientation

MediaQuery.of(context).size.width
MediaQuery.of(context).size.height

MediaQuery.of(context).devicePixelRatio
  1. 获取父元素的尺寸
    return LayoutBuilder(
      builder: (context, constraints) {
        return Container(
          width: constraints.maxWidth / 2,
          height: constraints.maxHeight / 2,
          color: Colors.red,
        );
      },
    );

相关文章

网友评论

      本文标题:flutter 基本操作

      本文链接:https://www.haomeiwen.com/subject/vqicuktx.html