class MyHome extends StatefulWidget { @override State createState() => new MyHomePage2(); } class MyHomePage2 extends State
I was also setting the state during build, so, I deferred it to the next tick and it worked.
previously
myFunction()
New
Future.delayed(Duration.zero, () async { myFunction(); });