首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决PreferredSize颤振中的零参数构造函数错误?

如何解决PreferredSize颤振中的零参数构造函数错误?
EN

Stack Overflow用户
提问于 2021-05-26 13:57:46
回答 1查看 1.5K关注 0票数 0

我正在处理一个使用自定义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'.

下面是我的部分代码:

代码语言:javascript
复制
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'.

代码语言:javascript
复制
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,
          ),
        ],
      )
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-26 16:54:03

您甚至不必扩展PreferredSize,只需将appBar或任何其他小部件封装在PreferredSize中,只需指定其高度即可。

代码语言:javascript
复制
PreferredSize(
            preferredSize: Size.fromHeight(72),
            child: AppBar(
              title: Text(title, style: TextStyles.h1),
              centerTitle: false,
              elevation: 0,
              brightness: Brightness.light,
              backwardsCompatibility: false,
              bottom: bottomAppBarWidget,
            ))
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67706471

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档