mponkin / fading_edge_scrollview

Flutter library for displaying fading edges on scroll views
BSD 3-Clause "New" or "Revised" License
43 stars 30 forks source link

Don't dispose my ScrollController for me #3

Closed lynn closed 4 years ago

lynn commented 4 years ago

This plugin calls .dispose() on the ScrollController argument it receives.

This means the obvious usage pattern is now wrong:

class _MyWidgetState extends State<MyWidget> {
  ScrollController _myController;

  @override
  void initState() {
    super.initState();
    _myController = ScrollController();
  }

  @override
  void dispose() {
    // Wrong, because this plugin wants me *not* to dispose my own controller!
    _myController.dispose();
    super.dispose();
  }

  @override
  Widget build() {
    return FadingEdgeScrollView.fromScrollView(child: ... _myController ...);
  }
}

This is surprising: If I'm supposed to create the controller and pass it in, it should also be my job to dispose it. This is the way it works everywhere else in Flutter.

So, I think you should not dispose the controller and let the user control its lifetime instead. This user ran into the same problem and would probably agree.

Thank you!

knaeckeKami commented 4 years ago

Ran into the same issue, please don't dispose the controller or at add a flag for that.

mponkin commented 4 years ago

Thanks for reporting this problem. I've fixed it in version 1.1.1