如何解决Flutter:在浮动操作按钮中使用 appBar 小部件而不是 appBar?
这是我在 appBar 中使用的小部件;
!!
以及小部件本身的代码;
appBar: AppBar(actions: <Widget>[myAppBarIcon()],)
但我现在想在浮动操作按钮而不是 appBar 中使用小部件。所以这就是我尝试过的;
Widget myAppBarIcon() {
return ValueListenableBuilder(
builder: (BuildContext context,int newNotificationCounterValue,Widget child) {
return newNotificationCounterValue == 0? Container(): Stack(
children: [
Icon(
Icons.notifications,color: Colors.white,size: 30,),Container(
width: 30,height: 30,child: Container(
width: 15,height: 15,decoration: Boxdecoration(
shape: BoxShape.circle,color: Color(0xffc32c37),border: Border.all(color: Colors.white,width: 1)),child: Padding(
padding: const EdgeInsets.all(0.0),child: Text(
newNotificationCounterValue.toString(),],);
},valueListenable: notificationCounterValueNotifer,);
}
虽然没有出现错误,但 myAppBarIcon 并没有出现在构建中。我哪里做错了?
解决方法
事实证明它确实有效。起初我并不这么认为,直到我意识到我需要在它出现之前收到 FCM 通知。这行是原因。;
return newNotificationCounterValue == 0? Container()
所以我要在容器中放置一个空的通知图标。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。