I use CupertinoTabBar, but want to show material design BottomSheet when user's device is Android. However, when I used both of them, BottomSheet is hidden behind CupertinoTabBar like below.
Could you help me to fix this? Or is it bad to use both of them?
My simplified code
class MyApp extends StatelessWidget {
void onPressed(BuildContext context) async {
await showModalBottomSheet(
context: context,
builder: (context) => Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
title: Text('Delete'),
onTap: () => Navigator.of(context).pop('delete'),
),
Divider(),
ListTile(
title: Text('Cancel'),
onTap: () => Navigator.of(context).pop('cancel'),
)
],
),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.music_note),
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
),
]
),
tabBuilder: (context, index) {
switch (index) {
case 0:
return CupertinoTabView(
builder: (context) {
return CupertinoPageScaffold(
child: FlatButton(
child: Text('button'),
onPressed: () => onPressed(context),
),
);
},
);
case 1:
return CupertinoTabView(
builder: (context) {
return CupertinoPageScaffold(
child: Text('tab 2'),
);
},
);
}
return Container();
}
)
);
}
}
You just need to set
useRootNavigator
totrue
. This will display model sheet above all other content.Refactored code: