RenderObjectWidget
SingleChildRenderObjectWidget
Align
const Align({
this.alignment = Alignment.center,
this.widthFactor,
this.heightFactor,
Widget? child,
})
Padding
ConstrainedBox
约束
this.minWidth = 0.0,
this.maxWidth = double.infinity,
this.minHeight = 0.0,
this.maxHeight = double.infinity,
ConstrainedBox(
constraints: const BoxConstraints.expand(),
child: const Card(child: Text(‘Hello World!’)),
)
Offstage
Offstage的布局行为完全取决于其offstage参数 。。 当点击切换按钮的时候,可以看到Offstage显示消失。
当offstage为true,当前控件不会被绘制在屏幕上,不会响应点击事件,也不会占用空间;
当offstage为false,当前控件则跟平常用的控件一样渲染绘制;
另外,当Offstage不可见的时候,如果child有动画,应该手动停掉,Offstage并不会停掉动画。
Opacity
隐藏控件,但保留位置
Opacity(
opacity: 0.0,
child: Container(
height: 80,
width: 80,
color: Colors.green,
alignment: Alignment.center,
child: Text(‘2’,style: TextStyle(color: Colors.white),),
),
)
使用Opacity控件和另一个控件层叠在一起,将会出现“蒙层效果”:
SizedBox
SizedBox(
height: 60,
width: 200,
child: Container(
color: Colors.blue,
alignment: Alignment.center,
child: Text(‘SizedBox’),
),
)
DecoratedBox
DecoratedBox 是一个装饰类组件。
decoration属性可以设置子控件的背景颜色、形状等。通常使用BoxDecoration。
Baseline
如果child有baseline,则根据child的baseline属性,调整child的位置;
如果child没有baseline,则根据child的bottom,来调整child的位置。
const Baseline({
Key key,
@required this.baseline,
@required this.baselineType,
Widget child
})
AnimatedSize
AnimatedSize是一个动画组件,当指定子组件的尺寸发生变化时,它就会在给定的时间内自动变换其尺寸
AnimatedSize(
vsync: this,
duration: Duration(seconds: 1),
child: Container(
height: _height,
width: _width,
color: _color,
),
)
AspectRatio
它试图按特定的长宽比调整子组件的大小
AspectRatio(
aspectRatio: 16 / 9,
child: Container(
color: Colors.green,
),
)
FractionallySizedBox
当我们需要一个控件的尺寸是相对尺寸时,比如当前按钮的宽度占父组件的70%,可以使用FractionallySizedBox来实现此效果
使用FractionallySizedBox包裹子控件,设置widthFactor宽度系数或者heightFactor高度系数,系数值的范围是0-1,0.7表示占父组件的70%
FractionallySizedBox(
widthFactor: .7,
child: RaisedButton(
child: Text(‘button’),
),
)
BackdropFilter
该过滤器将应用于其父部件或祖先部件剪辑内的所有区域。如果没有剪辑,过滤器将被应用到全屏。
BackdropFilter(
filter: ui.ImageFilter.blur(
sigmaX: 5.0,
sigmaY: 5.0,
),
FittedBox
当子组件的宽高比和父组件的宽高比不一样时,我们等比拉伸或者填充父组件,这时我们可以使用FittedBox
fit参数表示了子控件的填充方式,说明如下:
fill:填充父组件,宽高比发生变化。
contain:等比拉伸,但子控件不能超出父控件。
cover:尽可能的小,等比拉伸充满父控件。
fitWidth:等比拉伸,宽充满父控件。
fitHeight:等比拉伸,高充满父控件。
none:默认子控件居中,不做拉伸处理,超出父控件的部分裁剪。
scaleDown:在子控件为Image且缩小的情况和contain一样,否则和none一样。
ClipOval
使用椭圆剪辑子控件的小部件。
CustomClipper, for information about creating custom clips.
ClipRect, for more efficient clips without rounded corners.
ClipRRect, for a clip with rounded corners.
ClipPath, for an arbitrarily shaped clip.
ColorFiltered
可以用作蒙层,图片加蒙版
FadeTransition
FadeTransition提供了快速构建渐隐渐显动画的组件
IgnorePointer
AbsorbPointer本身可以接收点击事件,消耗掉事件,而IgnorePointer无法接收点击事件,其下的控件可以接收到点击事件(不是子控件)。
LimitedBox
LimitedBox是将child限制在其设定的最大宽高中的,但是这个限定是有条件的。当LimitedBox最大宽度不受限制时,child的宽度就会受到这个最大宽度的限制,同理高度。
LimitedBox(
maxWidth: 150.0,
child: Container(
color: Colors.blue,
width: 250.0,
),
),
Listener
Listener是一个监听指针事件的控件,比如按下、移动、释放、取消等指针事件,但Listener无法监听鼠标特有的事件,比如:移入、悬停、移出事件。鼠标事件使用MouseRegion监听。
通常情况下,监听手势事件使用GestureDetector,GestureDetector是更高级的手势事件。
Listener的事件介绍如下:
onPointerDown:按下时回调
onPointerMove:移动时回调
onPointerUp:抬起时回调
position:相对屏幕的坐标的偏移。
localPosition:相对当前控件的偏移。
pressure:按压力度。
delta:2次指针移动事件的偏移。
orientation:指针移动方向
Transform
return Transform(
transform: Matrix4.rotationZ(0.5),
child: Container(
height: 100,
width: 100,
color: Colors.red,
),
);
OverflowBox
OverflowBox,允许child超出parent的范围显示,当然不用这个控件,也有很多种方式实现类似的效果。
当OverflowBox的最大尺寸大于child的时候,child可以完整显示,
当其小于child的时候,则以最大尺寸为基准,当然,这个尺寸都是可以突破父节点的。。
当最小以及最大宽高度,如果为null的时候,就取父节点的constraint代替。
PhysicalModel
代表物理层的控件,将其子控件裁剪为一个形状,可以设置阴影值及颜色
PhysicalModel(
borderRadius: BorderRadius.circular(20),
color: Colors.blue,
elevation: 8,
child: Container(
height: 100,
width: 100,
),
)
PhysicalShape
PhysicalShape 与PhysicalModel类似,其提供阴影
RotatedBox
RotatedBox和Transform.rotate功能相似,它们都可以对子组件进行旋转变换,但是有一点不同:RotatedBox的变换是在layout阶段,会影响子组件的位置和大小
RotatedBox(
quarterTurns: 1, //旋转90度(1/4圈)
child: Text(“Hello world”),
),
Semantics
Semantics组件用于屏幕阅读器、搜索引擎、或者其他语义分析工具,比如视力有障碍的人士需要借助屏幕阅读器,屏幕阅读器可以对Semantics进行解析,比如语音。
ShaderMask
Flutter 中渐变有三种:
LinearGradient:线性渐变
RadialGradient:放射状渐变
SweepGradient:扇形渐变
ShaderMask(
shaderCallback: (Rect bounds) {
return LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.red,Colors.blue,Colors.green],
).createShader(bounds);
},
blendMode: BlendMode.color,
child: Image.asset(
‘assets/images/b.jpg’,
fit: BoxFit.cover,
),
)
SizeChangedLayoutNotifier
当子组件尺寸发生变化时,此组件发出通知(Notification),通知类型为SizeChangedLayoutNotification。
NotificationListener(
onNotification: (notification) {
print(‘child:$notification’);
return false;
},
child: SizeChangedLayoutNotifier(
child: Container(width: size, height: size, color: Colors.red),
),
),
SizedOverflowBox
AbsorbPointer
ImageFiltered
IndexedSemantics
IntrinsicHeight
IntrinsicWidth
SliverFadeTransition
SliverIgnorePointer
SliverOffstage
SliverOpacity
SliverOverlapAbsorber
SliverOverlapInjector
SliverPadding
SliverToBoxAdapter
AnnotatedRegion
MergeSemantics
MetaData
RepaintBoundary
CompositedTransformFollower
CompositedTransformTarget
ConstraintsTransformBox
CustomPaint画布
CustomSingleChildLayout
ExcludeSemantics
FractionalTranslation
ColoredBox
BlockSemantics