createController method
Creates a new ScrollController with the given key.
If a controller with the same key already exists, it will be disposed and replaced with a new one.
initialScrollOffset - The initial scroll offset of the controller.
keepScrollOffset - Whether to keep the scroll offset when the controller
is disposed and recreated.
Implementation
ScrollController createController(
String key, {
double initialScrollOffset = 0.0,
bool keepScrollOffset = true,
}) {
// Dispose existing controller if any
if (_controllers.containsKey(key)) {
_controllers[key]!.dispose();
}
final controller = ScrollController(
initialScrollOffset: initialScrollOffset,
keepScrollOffset: keepScrollOffset,
);
_controllers[key] = controller;
return controller;
}