Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The method 'createTicker' isn't defined for the type

I was trying to create a simple ticker:

Ticker? ticker;

@override
void initState() {
  super.initState();
  ticker = createTicker(tick);
  ticker!.start();
}

@override
void dispose() {
  ticker?.stop();
  ticker?.dispose();
  super.dispose();
}

void tick(Duration elapsed) {
  setState(() {
    // Do whatever
  });
}

The problem is that I get the error The method 'createTicker' isn't defined for the type '[WidgetName]'. I can’t find any info about this. Is depracated or something? I can’t find any other method like this. And yes, I am importing 'package:flutter/scheduler.dart'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should use SingleTickerProviderStateMixin. Later, in case you need more than 1 ticker object, you may consider migrate to TickerProviderStateMixin.

These mixins declare needed method createTicker.

So, just add mixing to you state like this:

class _MyWidgetState extends State<MyWidget>
    with SingleTickerProviderStateMixin { ... }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading