Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

内层 listview 无法使用 controller #14

Closed
Shu-Ji opened this issue Oct 3, 2018 · 1 comment
Closed

内层 listview 无法使用 controller #14

Shu-Ji opened this issue Oct 3, 2018 · 1 comment

Comments

@Shu-Ji
Copy link

Shu-Ji commented Oct 3, 2018

SmartRefresher(
  controller: _refresh_controller,
  child: ListView.builder(
    controller: _list_controller

    ... // 在某个点击事件中使用 list controller 会报错
    onTap: () {
        print(_list_controller);
        _list_controller.animateTo(.0, Duration(seconds: 1), Curves.ease);
    }
  )
)

print 语句打印结果为:

ScrollController#4e01c(no clients)

如果去掉 SmartRefresher,打印结果类似为:

ScrollController#4e01c(one client, offset 3.3)

�报错信息:

I/flutter ( 7395): ══╡ EXCEPTION CAUGHT BY GESTURE ╞══
I/flutter ( 7395): The following assertion was thrown while handling a gesture:
I/flutter ( 7395): ScrollController not attached to any scroll views.
I/flutter ( 7395): 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 149 pos 12:
I/flutter ( 7395): '_positions.isNotEmpty'
@Shu-Ji
Copy link
Author

Shu-Ji commented Oct 3, 2018

解决了。
通过查看源码,不需要自己定义 controller:

    onTap: () {
        _refresh_controller.scrollController.animateTo(.0, Duration(seconds: 1), Curves.ease);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant