前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Flutter Positioned 组件

Flutter Positioned 组件

作者头像
赵哥窟
发布2019-09-25 15:35:20
6830
发布2019-09-25 15:35:20
举报
Positioned

这个使用控制Widget的位置,通过他可以随意摆放一个组件,有点像绝对布局

Positioned({
  Key key,
  this.left,
  this.top,
  this.right,
  this.bottom,
  this.width,
  this.height,
  @required Widget child,
})

left、top 、right、 bottom分别代表离Stack左、上、右、底四边的距离

import 'package:flutter/material.dart';

class PositionedPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Text('PositionedDemo'), backgroundColor: Colors.blue[400]),
      body: Container(
        color: Colors.orange[100],
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        margin: EdgeInsets.all(15),
        child: Stack(
          children: <Widget>[
            Positioned(
                child:MaterialButton(
                  minWidth: 100,
                  onPressed: () {},
                  color: Colors.greenAccent,
                ),
              right:10,
              top: 10,
            ),
            Positioned(
              child:MaterialButton(
                minWidth: 100,
                height: 40,
                onPressed: () {},
                color: Colors.red,
              ),
              left: MediaQuery.of(context).size.width / 2 * 0.8,
              top: MediaQuery.of(context).size.height / 2 * 0.7,
            ),
            Positioned(
              child:MaterialButton(
                minWidth: 100,
                onPressed: () {},
                color: Colors.yellow,
              ),
              left: 10,
              bottom: 10,
            ),
          ],
        ),
      ),
    );
  }
}

demo 地址

Simulator Screen Shot - iPhone 11 Pro Max - 2019-09-24 at 15.21.03.png

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.09.24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Positioned
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档