I have a counter app with 2 buttons. One for reset to 0, other for incrementing. Now I want to store the count value. So when I close it and open again, it will show the last count value. I tried get_storage but it is not working as I expected. If I put save_logic inside "onpressed" of the button, then it works fine. [ Because each time when the button is pressed, we are storing fresh value of count variable ]. But if I put save_logic inside dispose(), it doesn't work.
[ It should work because as far as I know it will be called just before the StateFull widget is destroyed or removed from widgets_tree ]. [ Interesting confusion is - I tried it before and I remembered that worked. Then I deleted the project thinking I understood it but now I am confused 🙁 ]
1条答案
按热度按时间bnl4lu3b1#
GetStorage
是async
调用,就像您在initState
中所做的那样,您应该await
它。但是,由于dispose
是sync
,因此最好在每次按下increment
或decrement
按钮时更新存储中的值