Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

onClosed() is not fired when go "back" on navigation bar or by gesture #45

Open
troncomputers opened this issue Apr 20, 2021 · 2 comments

Comments

@troncomputers
Copy link

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
Copy link
Owner

ArcticZeroo commented May 1, 2021

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
Copy link
Author

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants