Reputation: 439
In our app we're using a bottomSheet along with a bottomNavigationBar.
The bottomSheet appears above the bottomNavigationBar, is there a way to make it appear underneath?
Here's a sample app:
import 'package:flutter/material.dart';
void main() {
runApp(SampleApp());
}
class SampleApp extends StatefulWidget {
@override
_SampleAppState createState() => new _SampleAppState();
}
class _SampleAppState extends State<SampleApp> {
final _scaffoldKey = GlobalKey<ScaffoldState>();
PersistentBottomSheetController _sheetController;
@override
Widget build(BuildContext context) {
final _showBottomSheet = () {
_sheetController = _scaffoldKey.currentState.showBottomSheet((context) {
return Container(
color: Colors.grey[200],
child: Column(mainAxisSize: MainAxisSize.min, children: [
RadioListTile(dense: true, title: Text('Test'), groupValue: 'test', onChanged: (value) {}, value: true),
RadioListTile(dense: true, title: Text('Test'), groupValue: 'test', onChanged: (value) {}, value: true),
]));
});
};
return MaterialApp(
home: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text('Sample App'),
),
bottomNavigationBar: Container(
child: IconButton(
icon: Icon(Icons.edit),
onPressed: _showBottomSheet,
),
),
),
);
}
}
Upvotes: 14
Views: 11711
Reputation: 11
USE ScaffoldMessenger instead, Like code below!
onTap: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
final snackBar = SnackBar(
backgroundColor: Colors.white,
padding: EdgeInsets.all(0),
duration: Duration(days: 365),
content: Container(
height: 120,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(32.0),
topRight: Radius.circular(32.0),
),
border: Border.all(width: 0.1)),
),
);
// Find the ScaffoldMessenger in the widget tree
// and use it to show a SnackBar.
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
Upvotes: 1
Reputation: 189
add : useRootNavigator: true,
showModalBottomSheet(
context: context,
useRootNavigator: true,
builder: (context) {},
);
Upvotes: 16
Reputation: 119
Noticed your question. Had same problem and found better solution. Use showModalBottomSheet()
. It will overlay bottom navigation.
Upvotes: 2
Reputation: 2920
You can combine your popup with the bottom navigation bar using Column
and simulate bottom sheet behavior using Expandable:
import 'package:flutter/material.dart';
import 'package:expandable/expandable.dart';
void main() {
runApp(SampleApp());
}
class SampleApp extends StatefulWidget {
@override
_SampleAppState createState() => new _SampleAppState();
}
class _SampleAppState extends State<SampleApp> {
@override
Widget build(BuildContext context) {
buildBottomSheet() {
return Container(
color: Colors.grey[200],
child: Column(mainAxisSize: MainAxisSize.min, children: [
RadioListTile(dense: true, title: Text('Test'), groupValue: 'test', onChanged: (value) {}, value: true),
RadioListTile(dense: true, title: Text('Test'), groupValue: 'test', onChanged: (value) {}, value: true),
]));
}
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Sample App'),
),
body: Container(
color: Colors.green,
),
bottomNavigationBar: ExpandableNotifier(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ExpandableButton(
child: SizedBox(height: 50,
child: Center(
child: Icon(Icons.edit),
),
),
),
Expandable(
expanded: buildBottomSheet(),
),
],
),
),
),
);
}
}
For a production app, consider using SafeArea
to add proper padding at the bottom.
Upvotes: 2