【笔记】Flutter的Stack堆布局组件

前言

Flutter的Stack堆布局组件学习笔记

Stack堆布局组件

  • Stack组件中的所有子组件是堆叠放置的

alignment:配置所有子元素位置

Alignment.center:所有元素都居中

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
27
28
29
30
31
32
33
34
35
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 Stack(
alignment: Alignment.center,
children: [
Container(
width: 200,
height: 200,
color: Colors.red,
),
Container(
width: 100,
height: 100,
color: Colors.yellow,
)
],
);
}
}

完成

参考文献

哔哩哔哩——筱筱知晓