onClosed() is not fired when go "back" on navigation bar or by gesture
Opened this issue · 2 comments
troncomputers commented
Hi!
Would you guys be able to look at this. Inside scaffold's body I have a FutureBuilder and I'm filtering data in onChanged()
function.
_ProductsScreenState() {
searchBar = SearchBar(
setState: setState,
buildDefaultAppBar: buildAppBar,
inBar: true,
hintText: "Wyszukaj...",
onSubmitted: print,
onChanged: (value) async {
if (!["", null, false, 0].contains(value)) {
var products = await productsService.getProducts();
var filteredProducts =
products.where((element) => element.ean!.contains(value) || element.name.contains(value) || element.code.contains(value)).toList();
setState(() {
_products = Future.value(filteredProducts);
});
} else {
_products = productsService.getProducts();
}
},
onCleared: () {
_products = productsService.getProducts();
},
onClosed: () {
print("onClosed");
_products = productsService.getProducts();
});
}
Function onClosed()
is fired only when I tap on "back" icon provided by this plugin.
ArcticZeroo commented
I cannot reproduce this, at least using the example in the latest pr #46 . Are you perhaps recreating the state too often, which would cause a new search bar to be created?
troncomputers commented
I've changed things a little bit. onChanged()
is not async anymore. As you can see I'm setting the state on every key pressed
onChanged: (value) {
if (!["", null, false, 0].contains(value)) {
var customers = customersService.getCustomersFromBox();
var filteredCustomers = customers
.where((element) =>
element.code.toLowerCase().contains(value.toLowerCase()) ||
(element.name1 + " " + element.name2 + " " + element.name3).toLowerCase().contains(value.toLowerCase()) ||
element.vatNumber!.toLowerCase().contains(value.toLowerCase()))
.toList();
setState(() {
_customers = Future.value(filteredCustomers);
});
}
},
Is that the issue?