【发布时间】:2021-02-11 21:24:03
【问题描述】:
我正在使用 showButtomSheet 显示包含 DraggableScrollableSheet 的 BottomSheet。我想通过单击 DarggableScrollableSheet 上的按钮来关闭 BottomSheet。我该怎么做?
只要 DraggableScrollableSheet 不靠近屏幕顶部,我就可以让它工作,但是当它接近顶部时,表格下方会出现一个模态类型的叠加层,当我关闭时工作表,模态覆盖仍然存在。
我尝试使用 PersistentBottomSheetController.close() 来关闭工作表,并使用 Navigator.pop 如下所示,但结果是一样的:关闭工作表后仍然存在深色覆盖,我找不到一种删除它的方法。
飞镖盘:http://dartpad.dev/7ec436f3c850936d74dcdbb6ff17f97c
截屏:https://i.stack.imgur.com/vE1VE.gif
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
body: MyStatelessWidget(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
MyStatelessWidget({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
child: const Text('showBottomSheet'),
onPressed: () {
Scaffold.of(context).showBottomSheet<void>(
(BuildContext context) {
return DraggableScrollableSheet(
expand: false,
maxChildSize: 0.935,
builder: (context, scrollController) => ListView(
controller: scrollController,
padding: const EdgeInsets.all(8),
children: <Widget>[
Container(
height: 200,
color: Colors.amber[600],
child: Center(
child: ElevatedButton(
child: const Text('Close BottomSheet'),
onPressed: () => Navigator.pop(context),
),
),
),
Container(
height: 500,
color: Colors.amber[500],
child: const Center(child: Text('Entry B')),
),
],
),
);
},
);
},
),
);
}
}
【问题讨论】: