PersistentBottomNavBarItem(
onPressed: _openRatingsLayer,
icon: Icon(
Icons.add,
color: Colors.white,
size: 35,
),
title: ("Add"),
activeColorPrimary: Colors.orange.shade800,
inactiveColorPrimary: Colors.grey,
),
void _openRatingsLayer() {
showModalBottomSheet(
elevation: 0,
backgroundColor: Colors.white,
isDismissible: true,
isScrollControlled: true,
context: context,
builder: (ctx) {
return Padding(
padding:
EdgeInsets.only(bottom: MediaQuery.of(ctx).viewInsets.bottom),
child: const DummyScreen(),
);
},
);
}
我期望当我单击添加导航栏项目时,它会向我显示 modalbottomsheet 而不是带我进入新屏幕...这就是为什么我尝试使用 permanentNavBarItem 的 onPressed 函数,但它给出了错误
OnPressed 参数是具有一个
BuildContext?
类型参数的函数 => Function(BuildContext?)
你的函数没有这个参数=>
_openRatingsLayer()
所以你不能按照你分配的方式分配它,因为你传递了错误类型的函数。
您可以修改您的函数并实现
BuildContext?
参数 => _openRatingsLayer(BuildContext? context)
,但我假设您想使用整个屏幕的上下文而不是导航栏的上下文。在这种情况下,最好添加这样的功能:
onPressed: (navBarContext) => _openRatingsLayer(),
或
onPressed: (navBarContext) {_openRatingsLayer();},
但是不要忘记在关闭模态框后调用导航栏控制器导航到不同的屏幕。
请参阅自定义导航栏样式