Reputation: 302
I am working on a project where I am using a custom AppBar and hence using PreferredSize
but I am getting a error stating that:
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'.
Here's my part of the code:
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()
}
}
Edit : After removing PreferredSize got this error:
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,
),
],
)
Upvotes: 0
Views: 2043
Reputation: 5718
You may not even have to extend PreferredSize
you may just wrap an appBar or any other widget inside a PreferredSize
and just specify its height.
PreferredSize(
preferredSize: Size.fromHeight(72),
child: AppBar(
title: Text(title, style: TextStyles.h1),
centerTitle: false,
elevation: 0,
brightness: Brightness.light,
backwardsCompatibility: false,
bottom: bottomAppBarWidget,
))
Upvotes: 3