【笔记】Flutter的AspectRatio宽高比组件

前言

Flutter的AspectRatio宽高比组件学习笔记

AspectRatio宽高比组件

  • AspectRation组件可以设置子元素的宽高比

aspectRatio:指定容器的宽高比

2:宽的比例
1:高的比例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import 'package:flutter/material.dart';

void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("文本内容"),
),
body: const App(),
),
));
}

class App extends StatelessWidget {
const App({super.key});

@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 2/1,
child: Container(
color: Colors.red,
),
);
}
}

完成

参考文献

哔哩哔哩——筱筱知晓