我想建立一个底部表单小部件,它可以拖动到全屏.

有人能告诉我怎么做吗?

谷歌 map 有一个小工具可以做到这一点.以下是屏幕截图(请查看附图):

Before drag up:

Bottom sheet with drag up buttonAfter drag up:

Bottom sheet after drag up

推荐答案

DraggableBottomSheet小部件与Stack小部件一起使用:

Google Maps Draggable Sheet

这是这个^GIF中整个页面的gist,或者试试Codepen.

下面是整个页面的 struct :

  @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(),
              );
            },
          ),
        ],
      ),
    );
  }


在前Stack名中:
-Google map 是最低层.
-标题(搜索域+水平滚动筹码)位于 map 上方.
-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;

Flutter相关问答推荐

此同步方法会返回True还是False?

在Riverpod ConsumerWidget中使用文本编辑控制器

如何在2024年使用Ffltter将用户数据保存在云FireStore中?

Flutter 翼future 建造者不断开火和重建.它在每次重建时都会生成一个新的随机数--我如何防止这种情况?

如何正确处理Flutter 翼中使用火基时发生的碰撞?

在背景图像上排列定位徽标

如何让两个展开的Widget根据其子窗口的屏幕大小

如何画三角形的圆角?

在 Flutter 中滑动关闭 PageView.builder 时出现问题

在使用 Android 12+ 的真实 Android 设备上,SingleChildScrollView 中最初位于视口之外的无响应 Web 视图

如果有空间则居中CustomScrollView

在 Flutter 中更改喜欢按钮的 colored颜色

Flutter 3.10 - 'window' 已弃用,不应使用

如何在 flutter 中使用带有有效负载数据的重定向来执行 firebase 推送通知.?

Flutter ListView 在 Column 中工作但在 Row 中不工作

无法将参数类型Future Function(String?)分配给参数类型void Function(NotificationResponse)?

在 Android 12+ 中,REST API 调用在 flutter 中非常慢,在 WiFi 中需要 10 秒,而在移动数据中不到一秒

Positioned 的宽度或 SizedBox 的宽度都不适用于堆栈小部件 - Flutter

在 Flutter 中,如何使用文本字段和方形图像进行行布局

使用 Firebase/Flutter 进行应用判断 - 100% 无效请求