在我们的应用中,我们使用了bottomSheet和bottomNavigationBar。
bottomSheet出现在bottomNavigationBar上方,有没有办法让它出现在下面?
以下是一个示例应用:
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,
),
),
),
);
}
}
答案 0 :(得分:4)
添加:useRootNavigator:true,
showModalBottomSheet(
context: context,
useRootNavigator: true,
builder: (context) {},
);
答案 1 :(得分:1)
您可以使用Column
将弹出窗口与底部导航栏结合起来,并使用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(),
),
],
),
),
),
);
}
}
对于生产应用,请考虑使用SafeArea
在底部添加适当的填充。
答案 2 :(得分:1)
提到您的问题。有同样的问题,找到了更好的解决方案。使用showModalBottomSheet()
。它将覆盖底部导航。