Flutter 在Flatter中创建可重用的appBar

Flutter 在Flatter中创建可重用的appBar,flutter,Flutter,我正在尝试在我的Flatter应用程序中创建一个可重用的appBar。appbar的右栏按钮应该在添加它的主UI中进行控制。我可以创建并使用appBar,但无法更改appBar上按钮的文本颜色。以下是我创建appBar的代码: class SocialAppBar extends StatefulWidget implements PreferredSizeWidget { AppBarConfig appBarConfig; bool isEnabled = false;

我正在尝试在我的Flatter应用程序中创建一个可重用的appBar。appbar的右栏按钮应该在添加它的主UI中进行控制。我可以创建并使用appBar,但无法更改appBar上按钮的文本颜色。以下是我创建appBar的代码:

    class SocialAppBar extends StatefulWidget implements PreferredSizeWidget {
  AppBarConfig appBarConfig;
  bool isEnabled = false;
  VoidCallback rightButtonClickCallback;

  SocialAppBar({@required this.appBarConfig, @required this.rightButtonClickCallback});

  @override
  State<StatefulWidget> createState() {
    return SocialAppBarState();
  }

  @override
  Size get preferredSize => new Size.fromHeight(kToolbarHeight);
}

class SocialAppBarState extends State<SocialAppBar> {
  @override
  Widget build(BuildContext context) {
    return getAppBarWithProfilePic();
  }
  Widget getAppBarWithProfilePic() {
    return AppBar(
      brightness: Brightness.light,
      backgroundColor: Colors.white,
      centerTitle: true,
      leading: IconButton(
          icon: Icon(Icons.arrow_back_ios),
          key: const Key("backButton"),
          onPressed: () {
            Navigator.pop(context);
          }),
      iconTheme: const IconThemeData(
        color: Colors.black54, //change your color here
      ),
      titleSpacing: 0.0,
      title: Row(
        children: <Widget>[
          buildAvatar(),
          const SizedBox(
            width: 15,
          ),
          Text(widget.appBarConfig.fullName,
              style: TextStyle(color: AppColor.appbarTitleSecondaryColor, fontWeight: FontWeight.w400))
        ],
      ),
      actions: <Widget>[
        Container(
            alignment: Alignment.centerRight,
            padding: const EdgeInsets.only(left: 20, right: 20),
            child: InkWell(
              child: AutoSizeText(
                AppLocalizations.of(context).translate(GlobalString.labelNext),
                style: TextStyle(color: widget.isEnabled ? AppColor.blue : AppColor.greyMediumDark, fontSize: 16),
                textAlign: TextAlign.center,
              ),
              onTap: widget.rightButtonClickCallback,
            ))
      ],
    );
  }

  setNextButtonColor(){
    setState(() {

    });
  }
}
我可以使用上述代码设置下一步按钮启用/禁用,但无法将颜色从灰色更改为蓝色

关于

简单修复:

_textController.addListener((){
  setState(() {
    if (_textController.text.length > 0){
      appBar.isEnabled = true;
    }else {
      appBar.isEnabled = false;
    }
  });
});
简单修复:

_textController.addListener((){
  setState(() {
    if (_textController.text.length > 0){
      appBar.isEnabled = true;
    }else {
      appBar.isEnabled = false;
    }
  });
});
可重用AppBar:

Widget appBar(String text, IconButton iconButton) {
  return AppBar(
    title: Text(
      text,
      style: AppTheme.screenTitleStyle(),
    ),
    centerTitle: true,
    leading: IconButton(icon: iconButton, onPressed: () {}),
    backgroundColor: AppTheme.mainThemeColor(),
    brightness: Brightness.dark,
  );
}
在以下活动中使用此appBar:

 appBar: appBar(
        "Change Password",
        IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ),
可重用AppBar:

Widget appBar(String text, IconButton iconButton) {
  return AppBar(
    title: Text(
      text,
      style: AppTheme.screenTitleStyle(),
    ),
    centerTitle: true,
    leading: IconButton(icon: iconButton, onPressed: () {}),
    backgroundColor: AppTheme.mainThemeColor(),
    brightness: Brightness.dark,
  );
}
在以下活动中使用此appBar:

 appBar: appBar(
        "Change Password",
        IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ),

这对我不起作用。“下一步”按钮的颜色保持不变。它不适合我。“下一步”按钮的颜色保持不变。我们如何处理无法识别的AppTheme和iconButton?有什么东西需要导入吗?@JhourladEstrella AppTheme是我创建的一个类,在AppTheme中,你可以本地化你的颜色、样式,而且越来越重要的是它可以重复使用,你不必一次又一次地制作样式和字体,所以,这就是为什么我将我所有的风格和色彩都本地化了。我们处理的AppTheme和iconButton不被认可吗?有一些东西需要导入吗?@JhourladEstrella AppTheme是我创建的一个类,在AppTheme中,你可以本地化你的颜色和样式,而且越来越重要的是,它可以重复使用,你不必一次又一次地制作样式和字体,这就是为什么我要本地化我所有的样式和颜色