如何使用Flutter构建能够拖动到全屏的底部小部件?

Jac*_*Sun 6 android ios flutter flutter-animation

我想构建一个底部表格小部件,它可以拖动到全屏。

谁能告诉我该怎么做?

谷歌地图有一个小部件能够做到这一点。这是屏幕截图(请查看附件图像):

向上拖动之前:

底页带有向上拖动按钮 向上拖动后:

向上拖动后的底页

Roh*_*eja 19

DraggableBottomSheet小部件与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)