'flutter how to implement animation inside class GetView<Controller>
I'm starting a flutter project and many people said that GetX is the best state manager framework to use in flutter, so I decide to use it.
I want to do some animation in class HomePage, but when I use mixin SingleTickerProviderStateMixin, it throws a compile error that
error: 'SingleTickerProviderStateMixin<StatefulWidget>' can't be mixed onto 'GetView<HomePageController>' because 'GetView<HomePageController>' doesn't implement 'State<StatefulWidget>'.
Here is my code
class HomePage extends GetView<HomePageController> with SingleTickerProviderStateMixin {
final Duration duration = const Duration(milliseconds: 300);
AnimationController _animationController;
HomePage() {
_animationController = AnimationController(vsync: this, duration: duration);
}
@override
Widget build(BuildContext context) {
return Container();
}
}
Because to initialize an AnimationController, it needs an argument named 'vsync', so I have to implement the mixin SingleTickerProviderStateMixin. But because GetView<> doesn't implement State so it throws compile error.
I don't know what is the correct way to implement animation inside GetX, the weird thing is I can't find out any clue or guide for this on Google or any flutter community despite the wide popularity of GetX
Solution 1:[1]
Try use GetX version of SingleTickerProviderStateMixin - SingleGetTickerProviderMixin:
class HomePage extends GetView<HomePageController> with SingleGetTickerProviderMixin {
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Simon Sot |
