-2

E/flutter (17200): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'findRootAncestorStateOfType' was called on null.

2 Answers2

0

This error is caused when you are using context before your Widget is build.

Try this code:

WidgetsBinding.instance.addPostFrameCallback((_) {
  // put the code here where you are using context.
});

I hope this helps, in case of any doubt please comment. If this answer helps you then please accept and up-vote it.

Kalpesh Kundanani
  • 5,413
  • 4
  • 22
  • 32
-1

I got this error when executing some code after calling Navigator.of(context).pop(). Your BuildContext object is null.

S Fitz
  • 1,074
  • 15
  • 31
  • please post a question – Yadu Apr 22 '20 at 15:25
  • @iamyadunandan It's an alternate answer, not a question. If you try to use the context after popping it then this error will occur. Please don't downvote when you don't understand. – S Fitz Apr 23 '20 at 06:39