8000 scrollview的controller被SmartRefresher替换的问题 · Issue #46 · peng8350/flutter_pulltorefresh · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

scrollview的controller被SmartRefresher替换的问题 #46

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

Closed
oliverlife opened this issue Mar 29, 2019 · 3 comments
Closed

scrollview的controller被SmartRefresher替换的问题 #46

oliverlife opened this issue Mar 29, 2019 · 3 comments

Comments

@oliverlife
Copy link
oliverlife commented Mar 29, 2019

SmartRefresher使用了新创建的_scrollController做scrollview offset的相关控制。
这会导致问题:#14
关联代码如下:

class _SmartRefresherState extends State<SmartRefresher> {
  ...
  void _init() {
    _scrollController = new ScrollController();
    ...
  }

  @override
  Widget build(BuildContext context) {
    ...
    return new LayoutBuilder(builder: (context, cons) {
      return new Stack(
        ...
                child: new CustomScrollView(
                  physics: new RefreshScrollPhysics(enableOverScroll: widget.enableOverScroll),
                  controller: _scrollController,
                  slivers:  slivers,
      ...
    );
  }

建议在scrollview有controller的时候,使用scrolview的controller而不用新创建。
即代码改为:

class _SmartRefresherState extends State<SmartRefresher> {
  ...
  void _init() {
    _scrollController = widget.child.controller ?? ScrollController();
    ...
  }
@oliverlife
Copy link
Author

刚看源码发现作者已经做了修正,不过修正中还有两处存疑:

  @override
  void dispose() {
    // TODO: implement dispose
    _scrollController.removeListener(_handleOffsetCallback);
    应该只对new出来的_scrollController做dispose()
    if (widget.child.controlle == _scrollController) {
        _scrollController.dispose();
    }
    super.dispose();
  }
  @override
  void didUpdateWidget(SmartRefresher oldWidget) {
    // TODO: implement didUpdateWidget
    仍需更新_scrollController
    _scrollController = widget.child.controller ?? ScrollController();
    widget.controller._scrollController = _scrollController;
    widget.controller._footerHeight = oldWidget.footerConfig is RefreshConfig?(oldWidget.footerConfig as RefreshConfig).height:0.0;
    super.didUpdateWidget(oldWidget);
  }

@peng8350
Copy link
Owner

谢谢指出毛病,已修正!

@oliverlife
Copy link
Author
oliverlife commented Apr 1, 2019

谢谢你对库的持续维护!

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

2 participants
0