Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ancestorStateOfType is deprecated use findAncestorStateOfType instead

Tags:

flutter

dart

Since the release of Flutter 1.12 my following code for restarting the app:

final MyAppState state = context.ancestorStateOfType(const TypeMatcher<MyAppState>()):

warns with the following:

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

and with

'TypeMatcher' is deprecated and shouldn't be used. TypeMatcher has been deprecated because it is no longer used in framework(only in deprecated methods). This feature was deprecated after v1.12.1.. Try replacing the use of the deprecated member with the replacement.

For some reason I can't seem to figure out how to refactor this code to get it working. Anyone to the rescue?

like image 804
AlbertJanP Avatar asked Dec 22 '19 21:12

AlbertJanP


1 Answers

All you have to do is just put the widget that extends State<StatefulWidget> so for your example, since the class is called MyAppState, I'm assuming it extends State<MyApp> so, therefore:

final MyAppState state = context.findAncestorStateOfType<MyAppState>();
like image 129
Benjamin Avatar answered Nov 19 '22 09:11

Benjamin