一、Scaffold

1.1 构造函数:

  1. const Scaffold({
  2. Key? key,
  3. this.appBar,
  4. this.body,
  5. this.floatingActionButton,
  6. this.floatingActionButtonLocation,
  7. this.floatingActionButtonAnimator,
  8. this.persistentFooterButtons,
  9. this.drawer,
  10. this.onDrawerChanged,
  11. this.endDrawer,
  12. this.onEndDrawerChanged,
  13. this.bottomNavigationBar,
  14. this.bottomSheet,
  15. this.backgroundColor,
  16. this.resizeToAvoidBottomInset,
  17. this.primary = true,
  18. this.drawerDragStartBehavior = DragStartBehavior.start,
  19. this.extendBody = false,
  20. this.extendBodyBehindAppBar = false,
  21. this.drawerScrimColor,
  22. this.drawerEdgeDragWidth,
  23. this.drawerEnableOpenDragGesture = true,
  24. this.endDrawerEnableOpenDragGesture = true,
  25. this.restorationId,
  26. })

1.2 主要参数说明:

appBar:顶部导航栏
body:页面内容
loatingActionButton:悬浮按钮
floatingActionButtonLocation:悬浮按钮位置
floatingActionButtonAnimator:悬浮按钮动画
persistentFooterButtons:显示在底部导航条上方的一组按钮
drawer:左侧菜单
onDrawerChanged:左侧抽屉菜单改变事件回调
endDrawer:右侧菜单
onEndDrawerChanged:右侧抽屉菜单改变事件回调
bottomNavigationBar:底部导航条
bottomSheet:持久在body下方,底部控件上方的控件
backgroundColor:背景颜色
resizeToAvoidBottomInset:防止小组件重复
primary:是否在屏幕顶部显示Appbar, 默认为 true,Appbar 是否向上延伸到状态栏,如电池电量,时间那一栏
drawerDragStartBehavior:检测手势行为方式,与drawer配合使用
extendBody:是否延伸到底部
extendBodyBehindAppBar:是否延伸到顶部,用于做半透明、毛玻璃效果的主要控制属性
drawerScrimColor:侧边栏弹出时非遮盖层主页面的颜色
drawerEdgeDragWidth:侧边栏弹出时非遮罩层的宽度
drawerEnableOpenDragGesture:左侧抽屉是否支持手势滑动
endDrawerEnableOpenDragGesture:右侧抽屉是否支持手势滑动
restorationId:状态还原标识符

1.3 代码示例:

1.4 显示效果:

二、Container

2.1 构造函数:

  1. Container({
  2. Key? key,
  3. this.alignment,
  4. this.padding,
  5. this.color,
  6. this.decoration,
  7. this.foregroundDecoration,
  8. double? width,
  9. double? height,
  10. BoxConstraints? constraints,
  11. this.margin,
  12. this.transform,
  13. this.transformAlignment,
  14. this.child,
  15. this.clipBehavior = Clip.none,
  16. })

2.2 主要参数说明:

alignment:容器内子组件的对齐方式
padding:容器的内边距
color:背景颜色
decoration:容器背景装饰 ,设置了decoration的话,就不能设置color属性,否则会报错,此时应该在decoration中进行颜色的设置。
foregroundDecoration:容器前景装饰
width:宽度
height:高度
constraints:容器的约束条件
margin:容器的外边距
transform:变换
child:容器的子组件
clipBehavior:裁剪方式

BoxDecoration的参数如下:

  1. const BoxDecoration({
  2. this.color, //颜色,会和Container中的color属性冲突
  3. this.image, //背景图片
  4. this.border, //边框,对应类型是Border类型,里面每一个边框使用BorderSide
  5. this.borderRadius, //圆角效果
  6. this.boxShadow, //阴影效果
  7. this.gradient, //渐变效果
  8. this.backgroundBlendMode, //背景混合
  9. this.shape = BoxShape.rectangle, //形变
  10. })

2.3 代码示例:

1.4 显示效果:

三、Padding

Padding可以给其子节点添加填充(留白),和边距效果类似。

3.1 构造函数:

  1. const Padding({
  2. Key? key,
  3. required this.padding,
  4. Widget? child,
  5. })

3.2 主要参数说明:

padding:EdgeInsetsGeometry类型(抽象类),使用EdgeInsets
child:子组件

EdgeInsets提供的便捷方法:
fromLTRB(double left, double top, double right, double bottom):分别指定四个方向的填充。
all(double value) : 所有方向均使用相同数值的填充。
only({left, top, right ,bottom }):可以设置具体某个方向的填充(可以同时指定多个方向)。
symmetric({ vertical, horizontal }):用于设置对称方向的填充,vertical指top和bottom,horizontal指left和right。

3.3 代码示例:

3.4 显示效果:

四、Clip

剪裁Widget 默认行为
ClipOval 子组件为正方形时剪裁成内贴圆形;为矩形时,剪裁成内贴椭圆
ClipRRect 将子组件剪裁为圆角矩形
ClipRect 默认剪裁掉子组件布局空间之外的绘制内容(溢出部分剪裁)
ClipPath 按照自定义的路径剪裁

4.1 构造函数:

  1. const ClipOval({
  2. Key? key,
  3. this.clipper,
  4. this.clipBehavior = Clip.antiAlias,
  5. Widget? child,
  6. })
  7. const ClipRRect({
  8. Key? key,
  9. this.borderRadius = BorderRadius.zero,
  10. this.clipper,
  11. this.clipBehavior = Clip.antiAlias,
  12. Widget? child,
  13. })
  14. const ClipRect({
  15. Key? key,
  16. this.clipper,
  17. this.clipBehavior = Clip.hardEdge,
  18. Widget? child,
  19. })

4.2 主要参数说明:

clipper:参数定义裁剪规则。
clipBehavior:参数定义了裁剪的方式,只有子控件超出父控件的范围才有裁剪的说法,各个方式说明如下:

  1. none:不裁剪,系统默认值,如果子组件不超出边界,此值没有任何性能消耗。
  2. hardEdge:裁剪但不应用抗锯齿,速度比none慢一点,但比其他方式快。
  3. antiAlias:裁剪而且抗锯齿,此方式看起来更平滑,比antiAliasWithSaveLayer快,比hardEdge慢,通常用于处理圆形和弧形裁剪。
  4. antiAliasWithSaveLayer:裁剪、抗锯齿而且有一个缓冲区,此方式很慢,用到的情况比较少。

child:子组件。

4.3 代码示例:

4.4 显示效果: