flutter - Flutter:在浮动操作按钮中使用 appBar 小部件而不是 appBar?
问题描述
这是我在 appBar 中使用的小部件;
appBar: AppBar(actions: <Widget>[myAppBarIcon()],)
以及小部件本身的代码;
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,
);
}
但我现在想在浮动操作按钮而不是 appBar 中使用小部件。所以这就是我尝试过的;
Scaffold(
body: FoldableSidebarBuilder(
drawerBackgroundColor: Colors.black45,
drawer: CustomDrawer(closeDrawer: (){
setState(() {
drawerStatus = FSBStatus.FSB_CLOSE;
});
},),
screenContents: mainStage(),
status: drawerStatus,
),
floatingActionButton: Stack(
children: <Widget>[
Positioned(
bottom:140,
left: 17,
child: FloatingActionButton(
mini: true,
heroTag: null,
backgroundColor: Colors.black12,
child: myAppBarIcon()
),
),
],
),
),
但是,虽然没有出现错误,但 myAppBarIcon 并没有出现在构建中。我哪里做错了?
解决方案
事实证明它确实有效。起初我不这么认为,直到我意识到我需要在 FCM 通知出现之前收到它。这条线就是原因。
return newNotificationCounterValue == 0? Container()
所以我要在容器中放一个空的通知图标。
推荐阅读
- python - 没有得到所需的箱线图输出
- c# - 如何在 C# 中使用 ftpwebrequest 从 FTP 服务器下载非常大的文件(~50 GB)
- html - 未应用 Div Container CSS... 新手
- javascript - 创建一个在容器中显示卡片列表的响应式 React 应用程序
- spring - 如何使用本机查询(插入)将数据保存到数据库?
- c++ - std::map std::priority_queue && lambda 比较器
- google-cloud-platform - Google Ads Data Hub (ADH) 是否可以设置在与 Google Analytics BigQuery 导出和第一方数据相同的 GCP 项目中?
- python - 将所有 OUTGOING 事件的日期和时间值保存在元组列表中
- python - 如何在两个方括号中的numpy数组中添加一个值
- python - 如何在 Django 中使用查询集更改日期时间字段