2

I want to implement best practices for constants in Flutter by Rémi Rousselet's: What's the best practice to keep all the constants in Flutter?

but inheritFromWidgetOfExactType is deprecated:

'inheritFromWidgetOfExactType' is deprecated and shouldn't be used. Use dependOnInheritedWidgetOfExactType instead. This feature was deprecated after v1.12.1.. Try replacing the use of the deprecated member with the replacement.

Could you help me to implement that with dependOnInheritedWidgetOfExactType?

nvoigt
  • 75,013
  • 26
  • 93
  • 142
rafitajaen
  • 399
  • 6
  • 15

2 Answers2

6

I use in my class Provider extends InheritedWidget like this

static Bloc of(BuildContext context) {
    return context.dependOnInheritedWidgetOfExactType<Provider>().bloc;
  }
0

Example of a replacement:

// Before, We write :
 context.inheritFromWidgetOfExactType(Name) as Name;

// Now instead of taking a Type as argument, The method is a generic.
  context.dependOnInheritedWidgetOfExactType<Name>();

A snippet of using the dependOnInheritedWidgetOfExactType method

 static Name of(BuildContext context) {
    return context.dependOnInheritedWidgetOfExactType<Name>();
  }
Kab Agouda
  • 6,309
  • 38
  • 32