1

I just want to start a function when all the widgets on my page are built, looking around on the internet I found this function Flutter: Run method on Widget build complete :

void initState() {
   super.initState();
   if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks) {
        SchedulerBinding.instance.addPostFrameCallback((_) => yourFunction(context));
   }

But I got this error :

The property 'schedulerPhase' can't be unconditionally accessed because the receiver can be 'null'.
Try making the access conditional (using '?.') or adding a null check to the target ('!').

And :

The method 'addPostFrameCallback' can't be unconditionally invoked because the receiver can be 'null'.
Try making the call conditional (using '?.') or adding a null check to the target ('!')

I assume these are some checks included in null safety , any ideas?

Finley Adams
  • 773
  • 1
  • 8
  • 20

0 Answers0