Flutter Dropdown Search组件出现双层滚动条问题求助
解决DropdownSearch双层滚动条问题
针对你遇到的双层滚动条问题,给你几个直接的调试和解决方向:
1. 显式控制Popup的滚动条
在PopupProps.menu里添加scrollbarProps配置,强制统一滚动条的显示逻辑,消除双层叠加:
popupProps: PopupProps.menu( // 保留原有配置 emptyBuilder: (context, searchEntry) => Center( child: Text( 'Keine Video-IDs gefunden', style: TextStyle(fontWeight: FontWeight.bold), ), ), showSelectedItems: true, showSearchBox: true, // 新增滚动条控制 scrollbarProps: const ScrollbarProps( thumbVisibility: true, // 只保留这一个滚动条 trackVisibility: false, ), ),
2. 检查全局主题的Scrollbar配置
如果项目的ThemeData里全局设置了scrollbarTheme(比如开启了alwaysShow),会导致Dropdown内部的滚动条和全局滚动条叠加。可以临时注释主题里的Scrollbar配置测试,或者给Dropdown单独指定局部主题:
Theme( data: Theme.of(context).copyWith( scrollbarTheme: ScrollbarThemeData( thumbVisibility: MaterialStateProperty.all(true), ), ), child: DropdownSearch<String>( // 你的Dropdown原有配置 ), )
3. 自定义弹窗列表的滚动逻辑
如果上面的方法无效,直接自定义弹窗的itemBuilder,手动控制滚动容器:
popupProps: PopupProps.menu( // 保留原有配置 showSelectedItems: true, showSearchBox: true, // 自定义列表构建 itemBuilder: (context, items) { return Scrollbar( thumbVisibility: true, child: ListView.builder( itemCount: items.length, itemBuilder: (ctx, index) => ListTile( title: Text(items[index]), onTap: () => Navigator.pop(context, items[index]), ), ), ); }, ),
4. 切换弹窗类型测试
换成PopupProps.dialog类型排查,确认是不是menu类型的弹窗结构自带了额外的滚动容器:
popupProps: PopupProps.dialog( emptyBuilder: (context, searchEntry) => Center( child: Text( 'Keine Video-IDs gefunden', style: TextStyle(fontWeight: FontWeight.bold), ), ), showSelectedItems: true, showSearchBox: true, ),
内容的提问来源于stack exchange,提问作者flixcoo
相关产品推荐
相关产品推荐

