当前位置:网站首页>[shutter -- layout] stacked layout (stack and positioned)
[shutter -- layout] stacked layout (stack and positioned)
2022-07-25 12:28:00 【Kevin-Dev】

List of articles
Flutter Use in Stack and Positioned These two components work together to achieve absolute positioning .Stack Allow subcomponents to stack , and Positioned For use in accordance with Stack Four corners to determine the location of the subcomponents .
Stack
1. brief introduction
Stack By analogy web Medium absolute, Absolute layout . Absolute layout is generally used less in mobile terminal development , But in some scenarios , It still has its function . Of course , It works Stack The absolute layout is complete , It can also be realized with other control combinations .
2. attribute
alignment: Alignment mode , The default is the upper left corner (topStart).
textDirection: Direction of text , Most don't need to deal with .
fit: Define how to set non-positioned Node size , The default is loose.
among StackFit There are the following :
- loose: The value of the child node is loose , It can be downloaded from min To max The size of the ;
- expand: Child nodes occupy as much space as possible , take max Size ;
- passthrough: Do not change the constraints of child nodes .
overflow: Whether the excess part is cut off (clipped).
3. example
1. design sketch

3. Code
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({
Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text(' Lay out in layers '),
),
body: Center(
child: Stack(
alignment: const Alignment(0.6, 0.6),
children: <Widget>[
CircleAvatar(
backgroundImage: AssetImage('images/avatar.png'),
radius: 100.0,
),
Container(
decoration: BoxDecoration(
color: Colors.black45
),
child: Text(
'KevinDev',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
)
],
),
)
)
);
}
}
Positioned
1. brief introduction
Absolute positioning , Used to locate subcomponents
2. attribute
left、top、right、bottom: They stand for leaving Stack Left 、 On 、 Right 、 The distance between the lower four sides .
width、height: Specify the width and height of the element to be positioned .
notes :Positioned Of width、height It's a little different from other places , It's used to match left、top 、right、 bottom To locate components ,
3. example
1. design sketch

2. Code
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({
Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text(' Lay out in layers '),
),
body: ConstrainedBox(
constraints: BoxConstraints.expand(),
child: Stack(
alignment:Alignment.center , // Specify no or partial positioning widget The alignment of
children: <Widget>[
Container(
child: Text("Hello world",style: TextStyle(color: Colors.white)),
color: Colors.blue,
),
Positioned(
left: 18.0,
child: Text("I am Kevin"),
),
Positioned(
top: 18.0,
child: Text("Your friend"),
)
],
),
)
)
);
}
}
边栏推荐
- Numpy first acquaintance
- 919. 完全二叉树插入器 : 简单 BFS 运用题
- Script set random user_ agent
- 微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告
- Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
- 2022.07.24(LC_6125_相等行列对)
- PyTorch项目实战—FashionMNIST时装分类
- [ROS advanced chapter] Lecture 9 programming optimization of URDF and use of xacro
- 通过Referer请求头实现防盗链
- 【3】 DEM mountain shadow effect
猜你喜欢
随机推荐
pytorch环境配置及基础知识
WPF project introduction 1 - Design and development of simple login page
【十】比例尺添加以及调整
1.1.1 欢迎来到机器学习
Eureka注册中心开启密码认证-记录
Dr. water 2
水博士2
R language ggplot2 visualization: visualize the scatter diagram, add text labels to some data points in the scatter diagram, and use geom of ggrep package_ text_ The repl function avoids overlapping l
mysql实现一张表数据插入另一张表
Introduction to the scratch crawler framework
Median (two point answer + two point search)
Fiddler抓包APP
微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告
想要做好软件测试,可以先了解AST、SCA和渗透测试
【4】 Layout view and layout toolbar usage
Week303 of leetcode (20220724)
和特朗普吃了顿饭后写下了这篇文章
[ROS advanced chapter] Lecture 9 programming optimization of URDF and use of xacro
【6】 Map box settings
intval md5绕过之[WUSTCTF2020]朴实无华








