flutterdart

ScrollController in StatelessWidget


Is it ok to use a ScrollController for a ListView within a StatelessWidget. If so, how can the controller be disposed?


Solution

  • If you are using a ScrollController, I think that you probably has a State (to change or maintain) in your widget.

    In that case you need to go for a StatefulWidget.

    I would just change to a StatefulWidget and use the dispose() method to clean memory.

    But first of all, think if you controller has a purpose to exist in the first place. Maybe in your case makes sense.

    Check this answer too --> Do stateless widgets dispose on their own?