- 获取一个uuid
//https://pub.dev/packages/uuid
//在pubspec.yaml中添加
dependencies:
uuid: 2.2.2
//引入文件,设置变量,生成uuid
import 'package:uuid/uuid.dart';
var uuid = Uuid();
uuid.v4();
- 获取设备横竖方向, 尺寸,DPR
//Orientation.landscape or Orientation.portrait
MediaQuery.of(context).orientation
MediaQuery.of(context).size.width
MediaQuery.of(context).size.height
MediaQuery.of(context).devicePixelRatio
- 获取父元素的尺寸
return LayoutBuilder(
builder: (context, constraints) {
return Container(
width: constraints.maxWidth / 2,
height: constraints.maxHeight / 2,
color: Colors.red,
);
},
);
网友评论