I would like to manage TabController state in riverpod.
But error of Undefined name 'vsync'
will happen
final recentWatchScreenTabStateTestProvider = StateProvider((ref) => TabController(
length: 3,
vsync: vsync, // error here
));
How to fix this?
or I can’t manage TabController state in riverpod?
If use StatefullWidget, I can use TabController.
But, I want to use TabController in another Widget.
2
Answers
To get
vsync
you have to use the mixin SingleTickerProviderStateMixin. Here is a small example:If you need more info check out TabController.
You can do it in a slightly different way. Let each widget that needs a
TabController
create one based on parameters from other providers:That way, in another widget where you need a
TabController
you can again create based on thelengthProvider
(and others you define).But, for good, in this case it is worth abandoning the use of a provider for
TabController
and organizing it all through the usualStatefulWidget
and overriddeninitState
anddispose
methods. And to receive parameters ininitState
throughref.read(lengthProvider)
. Each widget will have its own tab controller