Since the release of Flutter 1.12 my following code:
static MyInheritedWidget of(BuildContext context) {
return context.inheritFromWidgetOfExactType(MyInheritedWidget) as MyInheritedWidget;
}
warns with the following:
'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.
But when I try to replace it, it does not work:
static MyInheritedWidget of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType(MyInheritedWidget) as MyInheritedWidget;
}
Does someone know how to do it? Thanks!
The API changed slightly.
Now instead of taking a Type
as argument, the method is generic.
Before:
final widget = context.inheritFromWidgetOfExactType(MyInheritedWidget) as MyInheritedWidget;
After:
final widget = context.dependOnInheritedWidgetOfExactType<MyInheritedWidget>();
Note that the cast is no longer necessary
InheritFromWidgetOfExactType method is deprecated , Use dependOnInheritedWidgetOfExactType method instead.
Example of a replacement:
Before : with InheritFromWidgetOfExactType
static Name of(BuildContext context) {
return context.inheritFromWidgetOfExactType(Name); //here
}
Now with dependOnInheritedWidgetOfExactType (Recommanded)
static Name of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<Name>(); //here
}
Now instead of taking a
Type
as argument, The method is generic .
Brief<...>()
instead of(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With