Showmodalbottomsheet自适应尺寸颤动

发布于 2025-01-19 21:33:40 字数 2720 浏览 0 评论 0原文

我有下一个问题,即使这里有一个空白空间

Future<void> buildScrollableSheet([Widget? header]) {
    return showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (context) => makeDismissible(
        child: DraggableScrollableSheet(
          initialChildSize: 0.3,
          maxChildSize: 0.9, // this one should be adaptive
          builder: (_, controller) => Container(
            decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.vertical(
                top: Radius.circular(25),
              ),
            ),
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: Column(
              // crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                const Padding(
                  padding: EdgeInsets.all(24),
                  child: Center(
                    child: Text(
                      'My header',
                      style: TextStyle(
                        color: Color(0xff757575),
                        fontSize: 14,
                      ),
                    ),
                  ),
                ),
                Flexible(
                  child: Material(
                    color: Colors.white,
                    child: ListView(
                      shrinkWrap: true,
                      controller: controller,
                      children: [
                        SimpleHeader(
                          title: 'title',
                          text: 'text',
                        ),
                        SimpleHeader(
                          title: 'title',
                          text: 'text',
                        ),
                        SimpleHeader(
                          title: 'title',
                          text: 'text',
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

,您可以看到MaxChildSize设置为0.9,这是0.9,这是listView,即使您可以看到MaxChildSize ,也可以看到MaxChildSize的设置为0.9,即使您可以看到MaxChildSize ,也可以看到MaxChildSize,即,但是在这种情况下,只有3个元素,我想防止滚动到全尺寸,也可以将initaryChildSize设置为Childs尺寸,因此,如果我有大量的项目列表总是会打开。 谢谢你!

I have the next problem, having a little number of children allows users to scroll even though there is an empty space

Future<void> buildScrollableSheet([Widget? header]) {
    return showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (context) => makeDismissible(
        child: DraggableScrollableSheet(
          initialChildSize: 0.3,
          maxChildSize: 0.9, // this one should be adaptive
          builder: (_, controller) => Container(
            decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.vertical(
                top: Radius.circular(25),
              ),
            ),
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: Column(
              // crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                const Padding(
                  padding: EdgeInsets.all(24),
                  child: Center(
                    child: Text(
                      'My header',
                      style: TextStyle(
                        color: Color(0xff757575),
                        fontSize: 14,
                      ),
                    ),
                  ),
                ),
                Flexible(
                  child: Material(
                    color: Colors.white,
                    child: ListView(
                      shrinkWrap: true,
                      controller: controller,
                      children: [
                        SimpleHeader(
                          title: 'title',
                          text: 'text',
                        ),
                        SimpleHeader(
                          title: 'title',
                          text: 'text',
                        ),
                        SimpleHeader(
                          title: 'title',
                          text: 'text',
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

Here you can see maxChildSize is being set as 0.9 which is fine with a lot of children inside ListView, but in this case, there are only 3 elements and I want to prevent scrolling to full size, also it would be great to set initialChildSize to childs size, so if I have a huge list of items it would always open full.
Thank you!

showModalBottomSheet
openedModalSheet

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文