首页 > 其他分享 >Flutter使用ScrollBar设置thumbVisibility属性出现Another exception was thrown: The Scrollbar's ScrollCont

Flutter使用ScrollBar设置thumbVisibility属性出现Another exception was thrown: The Scrollbar's ScrollCont

时间:2025-01-08 15:54:38浏览次数:1  
标签:thrown exception ScrollPosition Scrollbar Another ScrollController was

══╡ 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

相关文章

  • CF2057E2 Another Exercise on Graphs (hard version) 题解
    感觉和[NOI2018]归程有点像(?考虑对每个询问二分答案,设二分到的答案是\(x\),要判断路径上的\(k\)大值是否能不大于\(x\),只需先将价值不大于\(x\)的所有边的边权设为\(0\),其他边设为\(1\),跑一遍\(a\)到\(b\)的最短路,看最短路长度是否不大于\(k\)即可。因为\(x\)的......
  • Redis可视化工具 Another Redis Desktop Manager工具使用详细教程(附下载链接)
    Redis可视化工具推荐:AnotherRedisDesktopManagerRedis是一种高性能的键值数据库,广泛应用于缓存和消息队列等场景。对于开发者来说,命令行工具固然强大,但操作繁琐。而一款高效易用的可视化工具可以极大地提升使用效率。本篇将为大家推荐一款开源、跨平台且功能强大的Redis可......
  • window环境运行 django+celery+redis 异步任务报错:kombu.exceptions.OperationalError
    在所有配置都正常,并且redis服务正常,django和celery服务启动都正常;但就在请求执行异步任务时报错了:kombu.exceptions.OperationalError:[WinError10061]由于目标计算机积极拒绝,无法连接。启动服务指令:django:pythonmanage.pyrunservercelery:celery-Adifyworker-l......
  • 【Azure Event Hub】Kafka消息发送失败(Timeout Exception)
    问题描述使用AzureEventHub,客户端通过kafka发送消息到EventHub中,规律性的遇见TimeoutException"sendfail;nestedexceptionisorg.springframework.kafka.kafkaException:xxx" 问题解答Kafka客户端与EventHub服务端的连接(Connection)空闲事件过长,EventHub服务端......
  • SpringBoot项目启动报错java.lang.ArrayStoreException: sun.reflect.annotation.Type
    问题今天启动业余学习项目里的某服务A发现启动失败,报错信息如下:[ERROR][2025-01-0515:41:26,083][main]com.cdfive.springboot.startup.ApplicationStartupExceptionReporter[30]-error=>java.lang.ArrayStoreException:sun.reflect.annotation.TypeNotPresentExcepti......
  • java.lang.NullPointerException
    1、字符串变量未初始化2、接口类型的对象没有用具体的类初始化,比如:Mapmap//会报错Mapmap=newMap();//则不会报错了3、当一个对象的值为空时,你没有判断为空的情况。4、字符串与文字的比较,文字可以是一个字符串或Enum的元素,如下会出现异常Stringstr=null;if(str.equals(“T......
  • Cause: java.sql.SQLDataException: ORA-01841: (完整) 年份值必须介于 -4713 和 +999
    报错信息:###Theerrormayexistinfile[E:\IdeaProjects\FeiShuEHR\target\classes\mapper\ZzzHrOaQingJiaMapper.xml]###TheerrormayinvolvedefaultParameterMap###Theerroroccurredwhilesettingparameters###SQL:SELECTDANHAO,A0190,LEAVE_TYPEI......
  • docker 部署项目 Linux 可以ping通域名,但是服务无法访问域名 UnknownHostException: a
    问题描述:这个问题发生在服务器加装安全组件后,一顿网络操作(如重启网卡、重启网络)之后就发生linux无法ping通域名,但是ping通外网ip是没问题的。这个问题他们安全组件的会解决。我这里就不做重点讲解。后来安全组件那边弄通ping域名也没问题后,项目依旧无法访问域名。具体报错......
  • 【长路经】C#读取文件抛出FileNotFoundException异常
    前言在winform中读取文件信息时,突然抛出了FileNotFoundException的异常,但是本地是有这个文件的。随后找到了这个文件,查看属性,[位置]属性,多了"\\?\"的前缀,百度得知这是windows对长路经的处理。需要注意:目前在NetFx框架下,才有这个问题。在NetCore框架下,是正常运行。复现问题......
  • Hyperf async-queue 队列 [ERROR] RedisException: read error on connection to xxx
    起因:在redis异步队列中总是有很多超时的任务,于是将redis-queue的任务超时时间调整到了3600async_queue.php'default'=>['driver'=>\Hyperf\AsyncQueue\Driver\RedisDriver::class,'redis'=>['pool'=>'def......