I am calling notifyListeners() towards the end of a class which returns a Future, just before the return statement. The actions initiated by notifyListeners do not fully complete before the return is called and subsequent statements are processed, resulting in errors. It appears that notifyListeners is somehow completing asynchronously.
I asked about this on an alternate forum and was told that this is a common flutter bug, particularly in relation to animation. It seems to me more likely that I am doing something wrong with my syntax. Has anyone come across this 'bug' before?
I tried using both .then() and async / await. Both have the same outcome.
Future<bool> updateProduct(Map<String, dynamic> updatedProduct)
...
return http
.put(
'https://chocolate-f3e81.firebaseio.com/products/${newProduct.serverID}.json',
body: json.encode(newProductMap))
.then<bool>((http.Response response) {
if (response.statusCode == 200 || response.statusCode == 201) {
_products[selectedProductIndex] = newProduct;
setIsLoading(false);
print('model selectedProductIndex ${selectedProductIndex}');
print('model selectedProductServerID ${_selectedProductServerID}');
notifyListeners();
return true;
I expected everything initiated by notifyListeners() to complete before 'return true' is actioned. This does not happen, instead the return is actioned and other code continues and gets ahead of the code initiated by notifyListeners().