Error: The method ‘inheritFromWidgetOfExactType’ isn’t defined for the class ‘BuildContext’

This error is caused by inheritFromWidgetOfExactType method.

This method is deprecated . Use dependOnInheritedWidgetOfExactType instead.

Your project simply contains it

First solution :

Go back to version 1.26.0-8.0 manually or use this command :

flutter downgrade

Second solution:

Switch to the beta channel

flutter channel beta

If you don’t have beta channel yet , you need to add flutter upgrade

Third solution:

Update your project

Find inheritFromWidgetOfExactType method in your code and adapt it with dependOnInheritedWidgetOfExactType.

Example of a replacement:

Before : with InheritFromWidgetOfExactType

static Name of(BuildContext context) {
  return context.inheritFromWidgetOfExactType(Name);  //before
}

Now with dependOnInheritedWidgetOfExactType (Recommanded)

static Name of(BuildContext context) {
  return context.dependOnInheritedWidgetOfExactType<Name>();  //after
}

Now instead of taking a Type as argument, The method is generic .
Brief <...>() instead of (...)

The error may also be caused by a package you have imported :

Solution:
Check if this package has a new update

In fact, this method has been depreciated since version 1.12.1 of flutter . But until then, its use was possible but not recommended.
Since version 1.26.0-12.0.pre it is no longer used, which explains the errors.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)