Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package:flutter/src/widgets/overlay.dart': Failed assertion: line 133 pos 12: '_overlay != null':

Tags:

flutter

dart

entry is a instance of OverlayEntry class

entry?.remove();

Error

Package:flutter/src/widgets/overlay.dart': Failed assertion: line 133 pos 12: '_overlay != null':
like image 758
Ravindra Bhanderi Avatar asked Jul 20 '18 13:07

Ravindra Bhanderi


2 Answers

Resolved

After lots of research a try I found below a simple solution.

entry?.remove();
entry = null;
like image 106
Ravindra Bhanderi Avatar answered Oct 21 '22 03:10

Ravindra Bhanderi


If there is no OverlayEntry inserted to the Overlay and you try to call the remove method, you will get that error: Failed assertion: '_overlay != null'. So before removing the entry, add a condition to judge whether it is legal or not. It's more like a hack code, you can add a variable like isEntryNotNull for convenience and understandable as well. And when you insert a new OverlayEntry into Overlay, reassign it to the entry variable, then the condition will work fine.

if (entry != null) {
  entry.remove();
  entry = null;
}
like image 25
halface_sun Avatar answered Oct 21 '22 03:10

halface_sun