1 更改StatusBar颜色
其实很简单,在需要改变的页面中用AnnotatedRegion<SystemUiOverlayStyle>包一下 里面指定 SystemUiOverlayStyle.dark
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.dark,
child: Scaffold(
body: SafeArea(child: pageBody),
));
2 减少Widget嵌套
使用 Dart 中的扩展函数方式,为Widget增加扩展
extension WidgetExt on Widget {
Container intoContainer({
//复制Container构造函数的所有参数(除了child字段)
Key key,
AlignmentGeometry alignment,
EdgeInsetsGeometry padding,
Color color,
Decoration decoration,
Decoration foregroundDecoration,
double width,
double height,
BoxConstraints constraints,
EdgeInsetsGeometry margin,
Matrix4 transform,
}) {
//调用Container的构造函数,并将当前widget对象作为child参数
return Container(
key: key,
alignment: alignment,
padding: padding,
color: color,
decoration: decoration,
foregroundDecoration: foregroundDecoration,
width: width,
height: height,
constraints: constraints,
margin: margin,
transform: transform,
child: this,
);
}
Padding intoPadding({Key key, EdgeInsetsGeometry padding}) {
return Padding(key: key, padding: padding, child: this);
}
}
使用处
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [Text('2'), Text('333')])
.intoContainer(padding: EdgeInsets.only(top: 20.0, bottom: 20))
就不用在外面再包一层 Container了
遇到问题就更新吧
网友评论