══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during a scheduler callback:
The Scrollbar's ScrollController has no ScrollPosition attached.
A Scrollbar cannot be painted without a ScrollPosition.
The Scrollbar attempted to use the PrimaryScrollController. This ScrollController should be
associated with the ScrollView that the Scrollbar is being applied to.
If a ScrollController has not been provided, the PrimaryScrollController is used by default on
mobile platforms for ScrollViews with an Axis.vertical scroll direction.
To use the PrimaryScrollController explicitly, set ScrollView.primary to true on the Scrollable
widget.
When the exception was thrown, this was the stack
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: The Scrollbar's ScrollController has no ScrollPosition attached.
Another exception was thrown: The Scrollbar's ScrollController has no ScrollPosition attached.
...
Widget build(BuildContext context) {
return Scrollbar(
thumbVisibility: true,
child: GridView.builder(
itemCount: 6,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (BuildContext context, int index) {
return Center(
child: Text('item $index'),
);
},
),
);
}
...
以上代码只所以出现上面的错误信息,就是没有绑定ScrollController控制器,导致自动寻找控制器的行为无法满足,才报错的。
以上代码我们将其添加ScrollController参数就可以了,注意Scrollbar盒GridView需要绑定同一个控制器。
这是相应的代码示例,切记controllerOne方法别忘调用dispose方法进行释放。
一般是在有状态Widget中的dispose方法进行释放当前组件的资源。
final ScrollController controllerOne = ScrollController();
...
Widget build(BuildContext context) {
return Scrollbar(
controller: controllerOne,
thumbVisibility: true,
child: GridView.builder(
controller: controllerOne,
itemCount: 6,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (BuildContext context, int index) {
return Center(
child: Text('item $index'),
);
},
),
);
}
...
标签:thrown,exception,ScrollPosition,Scrollbar,Another,ScrollController,was
From: https://www.cnblogs.com/XingXiaoMeng/p/18659935