Getx: Animation Controller with TickerProviderStateMixin

Created on 18 May 2020  路  4Comments  路  Source: jonataslaw/getx

hi @jonataslaw
first I wanna say thank you for great package Get,

as you said "Forget StatefulWidget", but how we create GetController for Animation Controller where we need TickerProviderStateMixin ?

example :

 class BottomBarView extends StatefulWidget {
   @override
   _BottomBarViewState createState() => _BottomBarViewState();
 }

 class _BottomBarViewState extends State<BottomBarView>
     with TickerProviderStateMixin {
   AnimationController animationController;

   @override
   void initState() {
     animationController = AnimationController(
       vsync: this,
       duration: const Duration(milliseconds: 1000),
     );
     animationController.forward();
     super.initState();
   }

   @override
   Widget build(BuildContext context) {
     return Scaffold(
     );
   }
}

Most helpful comment

I needed vsync to setup a controller for the tabbar, and looked inside the get package code and what worked with me is:

vsync: Navigator()

For me is TabController tabController = TabController(length: 10, vsync: NavigatorState());

Hope can help someone :+1:

All 4 comments

hi @jonataslaw
first I wanna say thank you for great package Get,

as you say "Forget StatefulWidget", but how we create GetController for Animation Controller where we need TickerProviderStateMixin ?

example :

class BottomBarView extends StatefulWidget {
@override
_BottomBarViewState createState() => _BottomBarViewState();
}
class _BottomBarViewState extends State
with TickerProviderStateMixin {
AnimationController animationController;
@override
void initState() {
animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1000),
);
animationController.forward();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
);
}
}

Actually there is no problem using StatefulWidget, but I needed to draw some attention to this, because in an app with a single FlatButton on the desktop Flutter that is now open, a StatelessWidget consumes 1mb and the same StatefulWidget class consumes 2mb. The difference is exactly double, so reducing the number of classes with StatefulWidget can significantly improve RAM consumption.
However, if one of the requirements of the class is to use StatefulWidget, there will be no problem using it, I would just say to create a separate widget for this component to make your code more readable and that is exactly what you did. Great!

I needed vsync to setup a controller for the tabbar, and looked inside the get package code and what worked with me is:

vsync: Navigator()

I needed vsync to setup a controller for the tabbar, and looked inside the get package code and what worked with me is:

vsync: Navigator()

For me is TabController tabController = TabController(length: 10, vsync: NavigatorState());

Hope can help someone :+1:

I needed vsync to setup a controller for the tabbar, and looked inside the get package code and what worked with me is:
vsync: Navigator()

For me is TabController tabController = TabController(length: 10, vsync: NavigatorState());

Hope can help someone 馃憤

@ghprod, you saved my life bro :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NiranjanShah picture NiranjanShah  路  4Comments

definev picture definev  路  3Comments

manojeeva picture manojeeva  路  3Comments

DarkHeros09 picture DarkHeros09  路  3Comments

Denilson-source picture Denilson-source  路  3Comments