首页 > 解决方案 > 我想为我的所有屏幕创建一个固定的 Appbar

问题描述

我正在尝试为我的所有屏幕使用相同的 Appbar,但我不想多次添加相同的代码,所以我考虑创建具有我的默认 Appbar 的 MyAppbar 类,以便我可以在我的屏幕没有重复相同的代码,但我不知道我错过了什么,因为它给了我以下错误:

没有为“MyAppbar”类定义方法“Appbar”。尝试将名称更正为现有方法的名称,或定义名为“Appbar”的方法。

这是我的代码:

class MyAppbar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Appbar(
        centerTitle: true,
        title: Center(
            child: Text("Title", style: TextStyle(fontFamily: 'theboldfont'))),
        actions: <Widget>[
          IconButton(
              icon: Icon(FontAwesomeIcons.bell),
              onPressed: () {
              }),
          IconButton(
              icon: CircleAvatar(
                  radius: 15,
                  backgroundImage: AssetImage("images/example.png")),
              onPressed: () {}),
        ]);
  }
}

谁能帮我解决这个错误?

谢谢!

标签: flutterflutter-layout

解决方案


我相信你有一个语法错误。是AppBar,不是Appbar


推荐阅读