【问题标题】:Flutter Scrollbar with scrollController doesn't work带有滚动控制器的颤振滚动条不起作用
【发布时间】:2021-08-16 05:13:51
【问题描述】:

当我在 ListView() 上包装 Scrollbar() 滚动条()不起作用 可以看到但不能拖动

这是我的代码

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: Text('products', style: TextStyle(color: Colors.black87)),
          elevation: 0.5,
        ),
        body: SafeArea(
          child: Scrollbar(
            child: ListView.builder(
              padding: EdgeInsets.only(top: kMediumGap),
              controller: _scrollController, // ✅
              shrinkWrap: true,
              itemCount: _products.length + 1,

...

@override
  void initState() {
    super.initState();

    _scrollController.addListener(() {
      if (_scrollController.position.pixels >= _scrollController.position.maxScrollExtent && !_fetching) {
        debugPrint('???? end of list = end of list');
        fetchProducts();
      }
}


  1. 如果我删除(分离)ListView() 中的 _scrollController 滚动条()工作正常。但我无法注意到滚动的结束,所以这是必要的

  2. 如果我使用 _scrollController 设置 Scrollbar() 控制器属性 滚动很脏。一点都不流畅。

有什么原因或解决办法吗? 我想注意滚动和 Scrollbar() 拖动功能的结束。两者都有。

【问题讨论】:

  • 尝试在列表视图中使用physics和BouncingScrollPhysics or ClampingScrollPhysics ,您可以在此链接中找到还删除滚动条和滚动控制器,如果您有长数据,请尝试延迟加载或分页以获得更好的性能medium.com/flutter-community/…跨度>
  • 我认为这不是我所期望的,但是
  • 我一直在寻找弹跳滚动物理 几个月前我看过视频教程,但我找不到确切的技能名称,但现在你指导我,谢谢????
  • 乐于助人

标签: flutter scroll controller scrollbar


【解决方案1】:

我测试了你的代码,它对我来说很好。我认为您的 fetchProducts() 函数有问题。

【讨论】:

  • 好吧..实际上我在测试时没有获取我想我应该更详细地检查我的其他代码谢谢
猜你喜欢
  • 1970-01-01
  • 2021-11-29
  • 1970-01-01
  • 2013-09-17
  • 2012-11-26
  • 2016-11-03
  • 1970-01-01
  • 1970-01-01
  • 2021-08-11
相关资源
最近更新 更多