Flutter通过showDialog实现下拉筛选菜单效果

一、效果图

二、 实现方式

  1. 获取固定在顶部筛选头部Widget在屏幕上的位置和它的高度
  2. 在弹窗中通过获取到的高度进行内容显示区域定位
  3. 巧用AnimatedContainer组件实现下拉动画效果
  4. 最后在底部加上黑色蒙层
dart 复制代码
unawaited(
      showDialog(
        context: context,
        useSafeArea: false,
        barrierColor: Colors.transparent,
        builder: (_) {
          return Padding(
            padding: EdgeInsets.only(top: startY),
            child: Column(
              children: [
                ColoredBox(
                  color: Colors.white,
                  child: Column(
                    children: [
                      Container(
                        height: 1,
                        margin: const EdgeInsets.symmetric(horizontal: 16),
                        color: const Color(0xfff6f7f9).withOpacity(0.8),
                      ),
                      ///下拉效果
                      ValueListenableBuilder<double>(
                        valueListenable: _notifier,
                        builder: (context, value, child) {
                          return AnimatedContainer(
                            height: value,
                            curve: Curves.fastEaseInToSlowEaseOut,
                            duration: const Duration(milliseconds: 300),
                            child: child,
                          );
                        },
                        child: widget.content,
                      ),
                    ],
                  ),
                ),
                ///底部黑色蒙层
                Expanded(
                  child: GestureDetector(
                    onTap: _close,
                    behavior: HitTestBehavior.opaque,
                    child: Container(
                      color: Colors.black.withOpacity(0.7),
                    ),
                  ),
                ),
              ],
            ),
          );
        },
      ),
    );

三、具体代码可查看此处的完整Demo

相关推荐
芙莉莲教你写代码19 小时前
Flutter 框架跨平台鸿蒙开发 - 谜语大全
flutter·华为·harmonyos
2501_920627611 天前
Flutter 框架跨平台鸿蒙开发 - 古文学习应用
学习·flutter·harmonyos
芙莉莲教你写代码1 天前
Flutter 框架跨平台鸿蒙开发 - 魔术教学
flutter·华为·harmonyos
weixin_443478511 天前
Flutter第三方常用组件包之路由管理
前端·javascript·flutter
左手厨刀右手茼蒿1 天前
Flutter 三方库 bs58 的鸿蒙化适配指南 - 在鸿蒙系统上构建极致、高效的 Base58 数字货币与区块链数据编解码引擎
flutter·harmonyos·鸿蒙·openharmony
加农炮手Jinx1 天前
Flutter 组件 substrate_bip39 的适配 鸿蒙Harmony 实战 - 驾驭区块链级助记词原语、实现鸿蒙端金融级 BIP39 安全私钥推导方案
flutter·harmonyos·鸿蒙·openharmony·substrate_bip39
左手厨刀右手茼蒿1 天前
Flutter 组件 substrate_bip39 的适配 鸿蒙Harmony 实战 - 驾驭区块链级 BIP39 安全底座、实现鸿蒙端私钥派生与国密级密钥保护方案
flutter·harmonyos·鸿蒙·openharmony·substrate_bip39
加农炮手Jinx1 天前
Flutter 三方库 fast_base58 的鸿蒙化进阶指南 - 挑战编解码吞吐量极限、助力鸿蒙端大规模区块链与分布式存储数据处理
flutter·harmonyos·鸿蒙·openharmony·fast_base58
里欧跑得慢1 天前
Flutter 三方库 ethereum 鸿蒙分布式区块链数字资产上链钱包适配突破:接通 JSON-RPC 加密管线深入打通智能合约闭环实现高价值数字加密交互-适配鸿蒙 HarmonyOS ohos
分布式·flutter·harmonyos
2501_920627611 天前
Flutter 框架跨平台鸿蒙开发 - 压力管理助手应用
flutter·华为·harmonyos