Tom*_*van 7 modal-dialog dart flutter bottom-sheet
在颤动中是否可以在初始状态下部分查看底部页面,然后可以展开/关闭?
我已经包含了 Google Maps 实现的示例的屏幕截图。
将DraggableScrollableSheet小部件与Stack小部件一起使用:
这是这个^ GIF 中整个页面的要点,或者试试Codepen。
下面是整个页面的结构:
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
CustomGoogleMap(),
CustomHeader(),
DraggableScrollableSheet(
initialChildSize: 0.30,
minChildSize: 0.15,
builder: (BuildContext context, ScrollController scrollController) {
return SingleChildScrollView(
controller: scrollController,
child: CustomScrollViewContent(),
);
},
),
],
),
);
}
Run Code Online (Sandbox Code Playgroud)
在Stack:
- 谷歌地图是最底层。
- 标题(搜索字段 + 水平滚动芯片)位于地图上方。
- DraggableBottomSheet 位于标题上方。
中定义的一些有用参数draggable_scrollable_sheet.dart:
/// The initial fractional value of the parent container's height to use when
/// displaying the widget.
///
/// The default value is `0.5`.
final double initialChildSize;
/// The minimum fractional value of the parent container's height to use when
/// displaying the widget.
///
/// The default value is `0.25`.
final double minChildSize;
/// The maximum fractional value of the parent container's height to use when
/// displaying the widget.
///
/// The default value is `1.0`.
final double maxChildSize;
Run Code Online (Sandbox Code Playgroud)
编辑:谢谢@Alejandro指出小部件名称中的错字:)
小智 4
我将在接下来的几周内实现相同的行为,并且我将参考 Flutter Gallery 中的背景实现,我之前能够对其进行修改以滑动以显示和隐藏(使用窥视区域)。
准确地说,您可以通过更改 Flutter Gallery 中的background_demo.dart 中的这行代码来复制所需的效果:
void _handleDragUpdate(DragUpdateDetails details) {
if (_controller.isAnimating)// || _controller.status == AnimationStatus.completed)
return;
_controller.value -= details.primaryDelta / (_backdropHeight ?? details.primaryDelta);
}
Run Code Online (Sandbox Code Playgroud)
我刚刚评论了控制器状态检查,以允许面板可滑动。
我知道这不是您正在寻找的完整实现,但我希望这对您有所帮助。
| 归档时间: |
|
| 查看次数: |
2123 次 |
| 最近记录: |