Flutter: Lifecycle of a Widget and Navigation
I ended up stopping the controller
before I navigate to the other page and restart it, when pop()
is called.
//navigate to new page
void didDetectBarcode(String barcode) {
controller.stop();
Navigator.of(context)
.push(...)
.then(() => controller.start()); //future completes when pop() returns to this page
}
Another solution would be to set the maintainState
property of the route
that opens ScanPage
to false
.