水平列表视图不在网络上滚动,而是在移动设备上滚动 [英] Horizontal listview not scrolling on web but scrolling on mobile
问题描述
flutter 2.5 更新后,列表视图仅在移动平台上滚动.当我在网络上打开它时它不会滚动.它在以前的版本中运行良好.我尝试了滚动物理,但没有奏效.你建议我做什么?抱歉我的英语不好.
<预><代码>返回大小框(高度:400,孩子:ListView.builder(物理:ClampingScrollPhysics(),滚动方向:Axis.horizontal,//忽略:necessary_null_comparisonitemCount: items == null ?0 : items.length,itemBuilder:(上下文,索引){返回手势检测器(onTap: () {登录表格();},孩子:容器(利润:EdgeInsets.symmetric(水平:20,垂直:6),孩子:SizedBox(宽度:400,身高:50,孩子:堆栈(适合:StackFit.expand,孩子们:<小部件>[容器(装饰:BoxDecoration(边界半径:BorderRadius.all(Radius.circular(20.0)),框阴影:[盒影(颜色:fromCssColor(项目[索引].color.toString()),//颜色: Colors.black38,偏移量:偏移量(2.0, 2.0),模糊半径:5.0,传播半径:1.0)]),),ClipRRect(边界半径:BorderRadius.all(Radius.circular(20.0)),孩子:图像.资产(项目[索引].image.toString(),适合:BoxFit.cover,),),容器(装饰:BoxDecoration(边界半径:BorderRadius.all(Radius.circular(20.0)),渐变:LinearGradient(开始:Alignment.topCenter,结束:Alignment.bottomCenter,颜色: [颜色.透明,颜色.black45]))),],),),Flutter 2.5 总结
<块引用>ScrollBehaviors 现在允许或禁止从指定的拖动滚动指针设备种类.ScrollBehavior.dragDevices,默认情况下,允许由所有 PointerDeviceKinds 拖动的滚动小部件,除了PointerDeviceKind.mouse.
//为整个应用程序设置 ScrollBehavior.材料应用(scrollBehavior: MyCustomScrollBehavior(),//...);
class MyCustomScrollBehavior 扩展 MaterialScrollBehavior {//覆盖行为方法和 getter,如 dragDevices@覆盖设置<PointerDeviceKind>获取拖动设备 =>{PointerDeviceKind.touch,PointerDeviceKind.mouse,};}
参考:文档
After flutter 2.5 update listview is scrolling only on mobile platforms. It doesn't scroll when I open it on the web. It was working fine in the previous version. I tried the scroll physics but it didn't work. what do you suggest i do? sorry for my bad english.
return SizedBox(
height: 400,
child: ListView.builder(
physics: ClampingScrollPhysics(),
scrollDirection: Axis.horizontal,
// ignore: unnecessary_null_comparison
itemCount: items == null ? 0 : items.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
LoginForm();
},
child: Container(
margin:
EdgeInsets.symmetric(horizontal: 20, vertical: 6),
child: SizedBox(
width: 400,
height: 50,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(20.0)),
boxShadow: [
BoxShadow(
color: fromCssColor(
items[index].color.toString()),
// color: Colors.black38,
offset: Offset(2.0, 2.0),
blurRadius: 5.0,
spreadRadius: 1.0)
]),
),
ClipRRect(
borderRadius:
BorderRadius.all(Radius.circular(20.0)),
child: Image.asset(
items[index].image.toString(),
fit: BoxFit.cover,
),
),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(20.0)),
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black45
]))
),
],
),
),
Flutter 2.5 Summary
ScrollBehaviors now allow or disallow drag scrolling from specified PointerDeviceKinds. ScrollBehavior.dragDevices, by default, allows scrolling widgets to be dragged by all PointerDeviceKinds except for PointerDeviceKind.mouse.
// Set ScrollBehavior for an entire application.
MaterialApp(
scrollBehavior: MyCustomScrollBehavior(),
// ...
);
class MyCustomScrollBehavior extends MaterialScrollBehavior {
// Override behavior methods and getters like dragDevices
@override
Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
};
}
Referrence: Documentation
这篇关于水平列表视图不在网络上滚动,而是在移动设备上滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!