flutter 学习笔记

常用属性

container

  • 填充padding,边距margins,边框borders,背景色color,
  • decoration: 渐变gradient-Alignment(x,y),圆角borderRadius,阴影boxShadow,圆shape

icon

  • 颜色color

text

  • style:字体fontSize,颜色color,粗细fontWeight,文本间距letterSpacing、wordSpacing
  • 溢出文本用省略号表示:overflow: TextOverflow.ellipsis, maxLines: 1

column, row

  • 子项的垂直水平对齐crossAxisAlignment(横轴)、占据空间大小mainAxisAlignment(主轴)

Transform

  • 旋转: transform: new Matrix4.identity()..rotateZ(15 * 3.1415927 / 180),
  • 缩放: transform: new Matrix4.identity().scale(1.5),

常用widgets

Container

  • 添加 padding, margins, borders, background color, 或将其他装饰添加到widget.

GridView

  • 网格形式,二维列表
  • 制定列数GridView.count, 最大像素宽度GridView.extent

ListView

  • 类似于列,渲染内容过长自动提供滚动
  • 可与ListTile搭配使用

Stack

  • 组织需要重叠的widgets
  • 第一个widget是base widget,随后的覆盖在base widget的顶部
  • 可与Positioned搭配使用

Card

  • 通常与ListTile一起使用
  • elevation属性允许您控制投影效果,用SizedBox包装进行大小调整
  • Card内容不能滚动

ListTile

  • 专门的行级widget
  • 包含最多3行文本和可选的行前和行尾图标

Stateful有状态和Stateless无状态widgets

区别

  • 用户与widget交互,widget发生变化,则此widget就是有状态的
  • 常见的Stateful子类: Checkbox, Radio, Slider, InkWell, Form, TextField
  • 常见的Stateless子类: Icon, IconButton, Text

常用获取设备参数的方法

获取设备屏幕宽度

  • MediaQuery.of(context).size.width
原文地址:https://www.cnblogs.com/shellon/p/13395452.html