英文:
flutter modal bottom sheet above navigation bar
问题
我有一个带有图标按钮的导航栏。当我按下按钮时,我想在导航栏上方显示模态底部表单(使导航栏可见)。但我尝试了很久都无法实现。
我希望在导航栏上方显示模态底部表单
BottomNavigationBarItem(
icon: Container(
height: 40,
width: 54,
decoration: const BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: IconButton(
onPressed: () {
showModalBottomSheet(
context: context,
//backgroundColor: Colors.transparent,
builder: (context) => Container(
height: 200,
child: ListTile(
leading: Icon(Icons.share),
title: Text('Share'),
),
),
);
},
icon: const Icon(Icons.add_outlined, color: Colors.white),
),
),
label: '',
),
英文:
I have an navigation bar with icon button. When i pressed the button i want show modal bottom sheet above the navigation bar(so nav bar was visible). I cant i try long but cant make it.
I expect to show modal bottom sheet above the navigation bar
BottomNavigationBarItem(
icon:Container(
height: 40,
width: 54,
decoration: const BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.all(Radius.circular(10.0)
),
),
child: IconButton(onPressed: () {
showModalBottomSheet(
context: context,
//backgroundColor: Colors.transparent,
builder: (context) => Container(
height:200,
child: ListTile(
leading: Icon(Icons.share),
title: Text('Share'),
),
));
},
icon:const Icon(Icons.add_outlined,color: Colors.white,),),
),
label: '',
),
答案1
得分: 1
如果您正在使用modal_bottom_sheet
包,只需添加参数useRootNavigator
并将其设置为true。
> useRootNavigator
参数确保在设置为true时使用根导航器来显示底部表单。这在需要在所有其他内容之上显示模态底部表单但调用者位于另一个导航器内的情况下非常有用。
如果您正在使用Flutter的内部showModalBottomSheet
,不用担心,它也有相同的参数。只需将其设置为true。
BottomNavigationBarItem(
icon: Container(
height: 40,
width: 54,
decoration: const BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: IconButton(
onPressed: () {
showModalBottomSheet(
context: context,
useRootNavigator: true,
builder: (context) => Container(
height: 200,
child: ListTile(
leading: Icon(Icons.share),
title: Text('Share'),
),
),
);
},
icon: const Icon(Icons.add_outlined, color: Colors.white),
),
),
label: '',
),
<details>
<summary>英文:</summary>
If you are using [`modal_bottom_sheet`][1] package, just add the parameter `useRootNavigator` and set it to true.
> The useRootNavigator parameter ensures that the root navigator is used to display the bottom sheet when set to true. This is useful in the case that a modal bottom sheet needs to be displayed above all other content but the caller is inside another Navigator.
If you are using Flutter’s internal `showModalBottomSheet`, don’t worry, it also has the same parameter. Just set it to true.
BottomNavigationBarItem(
icon:Container(
height: 40,
width: 54,
decoration: const BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.all(Radius.circular(10.0)
),
),
child: IconButton(onPressed: () {
showModalBottomSheet(
context: context,
//backgroundColor: Colors.transparent,
useRootNavigator: true,
builder: (context) => Container(
height:200,
child: ListTile(
leading: Icon(Icons.share),
title: Text('Share'),
),
));
},
icon:const Icon(Icons.add_outlined,color: Colors.white,),),
),
label: '',
),
[1]: https://pub.dev/packages/modal_bottom_sheet
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论