Flutter add item to list example. I will try to give an explanation of what is happing here take a look on this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import 'dart:async'; void main() { List<int> userSearchItems = []; Timer _sendTimeOutTimer; const oneSec = Duration(seconds: 2); _sendTimeOutTimer = Timer.periodic(oneSec, (Timer t) { userSearchItems.add(1); print(userSearchItems.length); // result 1 and it will be executed after 2 seconds _sendTimeOutTimer.cancel(); }); print(userSearchItems.length); // result 0 and it will be executed first } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.