我正在处理一个使用自定义AppBar并因此使用PreferredSize的项目,但我得到了一个错误,说明:
The superclass 'PreferredSize' doesn't have a zero argument constructor. Try declaring a zero argument constructor in 'PreferredSize', or explicitly invoking a different constructor in 'PreferredSize'.
下面是我的部分代码:
class CustomAppBar extends PreferredSize {
final Widget child;
final double height;
CustomAppBar({required this.child, required this.height}); //getting error on this line
@override
Size get preferredSize => Size.fromHeight(height);
@override
Widget build(BuildContext context) {
return Container()
}
}编辑:删除PreferredSize后,得到了以下错误:
The named parameter 'child' isn't defined. Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'child'.
appBar:
PreferredSize(
preferredSize:Size.fromHeight(95),
child:
AppBar(
child: Column(
children: <Widget>[
SizedBox(height: 40),
Row(
children: <Widget>[
Builder(
builder: (context) => FlatButton.icon(
onPressed: () => Scaffold.of(context).openDrawer(),
icon: Icon(Icons.menu),
label: Text('')),
),
SizedBox(width: 60),
Text('Times ',
style: GoogleFonts.blackHanSans(
textStyle:
TextStyle(color: Colors.black, fontSize: 20))),
Image.asset(
'assets/newss.png',
height: 50,
),
],
)发布于 2021-05-26 16:54:03
您甚至不必扩展PreferredSize,只需将appBar或任何其他小部件封装在PreferredSize中,只需指定其高度即可。
PreferredSize(
preferredSize: Size.fromHeight(72),
child: AppBar(
title: Text(title, style: TextStyles.h1),
centerTitle: false,
elevation: 0,
brightness: Brightness.light,
backwardsCompatibility: false,
bottom: bottomAppBarWidget,
))https://stackoverflow.com/questions/67706471
复制相似问题