美文网首页
Flutter问题 can't be assigned to t

Flutter问题 can't be assigned to t

作者: 基本密码宋 | 来源:发表于2019-04-23 16:31 被阅读0次

当我appbar抽出来的时候。如:

class getAppBarWidget extends StatelessWidget  {


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new AppBar(
      title: new Text(this.name),
    );
  }

  final String name;

  getAppBarWidget({Key key, @required this.name}) :super(key: key);
}

引用的时候会出现问题
'getAppBarWidget' can't be assigned to the parameter type 'PreferredSizeWidget'.
解决方法

class getAppBarWidget extends StatelessWidget implements PreferredSizeWidget {


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new AppBar(
      title: new Text(this.name),
    );
  }

  final String name;

  getAppBarWidget({Key key, @required this.name}) :super(key: key);

  @override
  // TODO: implement preferredSize
  Size get preferredSize => getSize();


Size getSize() {
    return new Size(100.0, 100.0);
  }
}

Scaffold需要appbar作为实现PreferredSizeWidget的类

相关文章

网友评论

      本文标题:Flutter问题 can't be assigned to t

      本文链接:https://www.haomeiwen.com/subject/jjxbgqtx.html