Flutter--Stack组件(FrameLayout)
  45VoiS2mj7n5 2023年11月02日 31 0


属性

属性

释义

alignment

控制内部子元素显示位置

position

控制内部子元素的显示位置

  • 默认所有元素显示在左上角,和Android中的FrameLayout类似
eg:Stack使用:
class HomeContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment(1, 0.3), // 设置坐标的形式,不设置该属性所有元素默认显示在左上角
// alignment : Alignment.center, // 使用属性的形式
children: <Widget>[
Container(
height: 400,
width: 400,
color: Colors.red,
),
Text(
"hah",
style: TextStyle(fontSize: 20, color: Colors.white),
),
Text(
"----------",
style: TextStyle(fontSize: 20, color: Colors.black),
),
],
);
}
}

Flutter--Stack组件(FrameLayout)_ide

eg:Align使用
class HomeContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return Center(
child: Container(
height: 400,
width: 300,
color: Colors.black,
child: Stack(
// alignment: Alignment.center,
children: <Widget>[
Align(
alignment: Alignment(1,-0.2),
child: Icon(Icons.home,size: 40,color: Colors.white),
),
Align(
alignment: Alignment.center,
child: Icon(Icons.search,size: 30,color: Colors.white),
),
Align(
alignment: Alignment.bottomRight,
child: Icon(Icons.settings_applications,size: 30,color: Colors.white),
)
],
),
),
);
}
}

Flutter--Stack组件(FrameLayout)_ide_02

eg:Positioned使用
class HomeContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return Center(
child: Container(
height: 400,
width: 300,
color: Colors.black,
child: Stack(
// alignment: Alignment.center,
children: <Widget>[
Positioned(
left: 10, // 距左侧为10
top: 100, // 距上100
child: Icon(Icons.home,size: 40,color: Colors.white),
),
Positioned(
left: 10,
top: 10,
child: Icon(Icons.search,size: 30,color: Colors.white),
),
Positioned(
right: 10,
bottom: 10,
child: Icon(Icons.settings_applications,size: 30,color: Colors.white),
)
],
),
),
);
}
}

Flutter--Stack组件(FrameLayout)_Stack_03


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  b1UHV4WKBb2S   2023年11月13日   40   0   0 ide抗锯齿
  b1UHV4WKBb2S   2023年11月13日   37   0   0 裁剪ideflutter
  b1UHV4WKBb2S   2023年11月13日   29   0   0 flutterDart
  zSWNgACtCQuP   2023年11月13日   32   0   0 ide
45VoiS2mj7n5