Wigets学习之Stack
时间:2021-06-24 06:48:24
Stack → postion: absolute(Css)
使子部件绝对定位,可以配合使用
Positioned部件一起使用,实现类似Css中的绝对定位效果
textDirection:文字排列方式fit:定义未定位的对象大小,StackFit.loose(不约束)、StackFit.expand(充满)、StackFit.passthrough(继承父级约束)
Positioned
设置在
Stack中的位置
child:子部件(必传)left:左侧距离top:顶部距离right:右侧距离bottom:底部距离height:高度width:宽度
import 'package:flutter/material.dart';
void main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Stack(
textDirection: TextDirection.ltr,
fit: StackFit.loose,
children: [
Positioned(
bottom: 20,
height: 200,
width: 200,
child: Container(
color: Colors.yellow,
)),
Container(
height: 400,
width: 400,
color: Colors.green,
),
],
);
}
}
