Flutter 颤振滚动条防止滚动条显示在水平listview上
当垂直滚动时,我的小部件树的右侧会显示一个Flutter 颤振滚动条防止滚动条显示在水平listview上,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,当垂直滚动时,我的小部件树的右侧会显示一个滚动条。现在,在我的小部件树中,我有一个水平的列表视图。如果用户水平滚动,滚动条也会显示在那里。我不希望滚动条出现在那里。有没有常用的方法来禁用显示在水平轴上 @override Widget build(BuildContext context) { return SafeArea( child: Scrollbar( child: SingleChildScrollView( child:
滚动条
。现在,在我的小部件树中,我有一个水平的列表视图
。如果用户水平滚动,滚动条也会显示在那里。我不希望滚动条出现在那里。有没有常用的方法来禁用显示在水平轴上
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scrollbar(
child: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height * 5,
margin: EdgeInsets.all(25),
child: Column(
children: <Widget>[
Row(
...
@覆盖
小部件构建(构建上下文){
返回安全区(
子:滚动条(
子:SingleChildScrollView(
子:容器(
高度:MediaQuery.of(context).size.height*5,
保证金:所有(25),
子:列(
儿童:[
划船(
...
稍后在listview上:
Expanded(child:
Consumer<Model>(builder: (context, myModel, child) {
return ListView.builder(
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
itemCount: list.length,
itemBuilder: (ctx, index) => ChangeNotifierProvider.value(
value: list[index],
child: GestureDetector(
扩展(子:
消费者(生成器:(上下文、myModel、子对象){
返回ListView.builder(
物理学:NeverscrollableScroll物理学(),
滚动方向:轴垂直,
itemCount:list.length,
itemBuilder:(ctx,index)=>ChangeNotifierProvider.value(
值:列表[索引],
儿童:手势检测器(
假设您有一个包含两个列表视图的小部件:
Scrollbar(
controller: scrollController,
child: ListView.builder(
controller: scrollController,
scrollDirection: Axis.vertical,
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
return SizedBox(
height: 90,
child: ListView.separated(
scrollDirection: Axis.horizontal,
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
return Container(
height: 100,
width: 100,
color: Colors.blue,
);
},
separatorBuilder: (context, index) {
return SizedBox(
width: 10,
);
},
itemCount: 50,
),
);
},
itemCount: 50,
),
),
一个简单的解决方案是用一个NotificationListener包装ListView,并将onNotification设置为返回true。在这种情况下,水平ListView将是有问题的小部件。这将告诉NotificationListener通知已被处理,这将阻止它发送Scro我将在小部件树上创建通知
因此,解决方案将是:
Scrollbar(
controller: scrollController,
child: ListView.builder(
controller: scrollController,
scrollDirection: Axis.vertical,
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
return SizedBox(
height: 90,
child: NotificationListener<ScrollNotification>(
onNotification: (_) => true,
child: ListView.separated(
scrollDirection: Axis.horizontal,
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
return Container(
height: 100,
width: 100,
color: themeColor,
);
},
separatorBuilder: (context, index) {
return SizedBox(
width: 10,
);
},
itemCount: 50,
),
),
);
},
itemCount: 50,
),
),
滚动条(
控制器:滚动控制器,
子项:ListView.builder(
控制器:滚动控制器,
滚动方向:轴垂直,
物理:AlwaysScrollableScrollPhysics(),
itemBuilder:(上下文,索引){
返回大小框(
身高:90,
孩子:NotificationListener(
onNotification:()=>true,
子项:ListView.separated(
滚动方向:轴水平,
物理:AlwaysScrollableScrollPhysics(),
itemBuilder:(上下文,索引){
返回容器(
身高:100,
宽度:100,
颜色:themeColor,
);
},
separatorBuilder:(上下文,索引){
返回大小框(
宽度:10,
);
},
物品计数:50,
),
),
);
},
物品计数:50,
),
),
为了深入理解,考虑阅读
想象一下,你有一个包含两个ListVIEW:的小部件
Scrollbar(
controller: scrollController,
child: ListView.builder(
controller: scrollController,
scrollDirection: Axis.vertical,
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
return SizedBox(
height: 90,
child: ListView.separated(
scrollDirection: Axis.horizontal,
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
return Container(
height: 100,
width: 100,
color: Colors.blue,
);
},
separatorBuilder: (context, index) {
return SizedBox(
width: 10,
);
},
itemCount: 50,
),
);
},
itemCount: 50,
),
),
一个简单的解决方案是用一个NotificationListener包装ListView,并将onNotification设置为返回true。在这种情况下,水平ListView将是有问题的小部件。这将告诉NotificationListener通知已被处理,这将阻止它发送Scro我将在小部件树上创建通知
因此,解决方案将是:
Scrollbar(
controller: scrollController,
child: ListView.builder(
controller: scrollController,
scrollDirection: Axis.vertical,
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
return SizedBox(
height: 90,
child: NotificationListener<ScrollNotification>(
onNotification: (_) => true,
child: ListView.separated(
scrollDirection: Axis.horizontal,
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
return Container(
height: 100,
width: 100,
color: themeColor,
);
},
separatorBuilder: (context, index) {
return SizedBox(
width: 10,
);
},
itemCount: 50,
),
),
);
},
itemCount: 50,
),
),
滚动条(
控制器:滚动控制器,
子项:ListView.builder(
控制器:滚动控制器,
滚动方向:轴垂直,
物理:AlwaysScrollableScrollPhysics(),
itemBuilder:(上下文,索引){
返回大小框(
身高:90,
孩子:NotificationListener(
onNotification:()=>true,
子项:ListView.separated(
滚动方向:轴水平,
物理:AlwaysScrollableScrollPhysics(),
itemBuilder:(上下文,索引){
返回容器(
身高:100,
宽度:100,
颜色:themeColor,
);
},
separatorBuilder:(上下文,索引){
返回大小框(
宽度:10,
);
},
物品计数:50,
),
),
);
},
物品计数:50,
),
),
对于一个深入的理解,考虑阅读有人有想法吗?这应该是一个可以解决的共同问题:有人有想法吗?这应该是一个可以解决的共同问题: