Flutter - 常见、通用的属性

width

height

alignment

子元素对齐方式。会让元素撑满父元素。

alignment: Alignment.topLeft
alignment: Alignment.topCenter
alignment: Alignment.topRight

alignment: Alignment.centerLeft
alignment: Alignment.center
alignment: Alignment.centerRight

alignment: Alignment.bottomLeft
alignment: Alignment.bottomCenter
alignment: Alignment.bottomRight

color

颜色

color: Color(0xFF000000)
color: Color.fromARGB(255, 0, 0, 0)
color: Color.fromRGBO(0, 0, 0, 1)
color: Colors.red
//MaterialColor是有个颜色map,可以选择不同色深的颜色,map中含有的色值才能正常展示
color: Colors.red[50]

margin

外边距

//上下左右均设置
margin: EdgeInsets.all(20)
//left-top-right-bottom
margin: EdgeInsets.fromLTRB(20, 20, 20, 20)
//单独设置单边
margin: EdgeInsets.only(left: 20,top: 20,right: 20,bottom: 20)
//设置上下或者左右
margin: EdgeInsets.symmetric(vertical: 20,horizontal: 20)

padding

内边距。也是使用EdgeInsets设置,同margin设置。

decoration

修饰,在child下面做背景展示
设置decoration,原控件color属性就要去除,设置在BoxDecoration

//边框
        decoration: BoxDecoration(
          border: Border.all(
            color: Colors.black,
            width: 1,
          ),
        ),
//圆角
        decoration: BoxDecoration(
          color: Colors.red,
          borderRadius: BorderRadius.circular(10),
        ),
//背景图
        decoration: BoxDecoration(
            image: DecorationImage(
              image: NetworkImage('https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=336492172,12372647&fm=26&gp=0.jpg'),
              fit: BoxFit.cover,
            )
        ),
//背景色
        decoration: BoxDecoration(
            color: Colors.red
        ),
//形状
        decoration: BoxDecoration(
          color: Colors.red,
          shape: BoxShape.circle,
        ),
//阴影
        decoration: BoxDecoration(
          color: Colors.red,
          boxShadow:[
            BoxShadow(
              color: Colors.green,
              blurRadius: 5
            ),
          ]
        ),
//渐变色
          gradient: LinearGradient(
              begin: Alignment.topRight,
              end: Alignment.bottomLeft,
              // Add one stop for each color. Stops should increase from 0 to 1
              stops: [
                0.3,
                0.5,
                0.7,
                0.9
              ],
              colors: [
                Colors.red[50],
                Colors.red[100],
                Colors.red[200],
                Colors.red[300]
              ]),

foregroundDecoration

修饰,和decoration类似,在child上面做蒙版展示。

transform

设置平移旋转缩放之类。使用Matrix4

//缩放
transform: Matrix4.diagonal3Values(1, 2, 1),
//平移
transform: Matrix4.translationValues(10.0, 10.0, 10.0),
//旋转
import 'package:flutter/material.dart';
transform: Matrix4.rotationZ(pi / 6),

constaints

为child设置限制约束。

		//约束宽高
        constraints: BoxConstraints.expand(height: 100, width: 100),
        //约束最小最大宽高
        constraints: BoxConstraints(
          minHeight: 100,
          maxHeight: 200,
          minWidth: 100,
          maxWidth: 200,
        ),
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值