class BaseViewBar extends PreferredSize {
Widget childView;
@override final Size preferredSize; //Size.fromHeight(56.0)
BaseViewBar({this.preferredSize, this.childView});
@override Widget build(BuildContext context) {
Widget current = childView;
if (childView == null) {
current = LimitedBox(
maxWidth: 0.0,
maxHeight: 0.0,
child: ConstrainedBox(constraints: const BoxConstraints.expand()),
);
}
return current;
}
}
下面是使用BaseViewBar
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
appBar: new BaseViewBar(
childView: new CommonTitleBar( //自定义的标题栏类
title: "Profile",
color: Colors.white,
rightClick: _onClickGold,
),
preferredSize: Size.fromHeight(56.0)
),
body: Text("hello")
);
}