【发布时间】:2021-06-12 14:04:27
【问题描述】:
这是我在 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 并没有出现在构建中。我哪里做错了?
【问题讨论】:
-
请分享您拥有此 appBar 的脚手架/容器代码。
-
这是脚手架;
标签: flutter dart widget flutter-layout