Flutter State Management - setState() Example
If you want to manage a simple state maybe just for a screen or if the app is very limited in terms of a number of screens, the best possible way is to use setState( ) to manage the state. In the below example, I will take two numbers the addition of two numbers will be updated using setState().
The below is my main.dart file I just have the main method and I kept Operations as my root widget
The below is my operations.dart file
The code which will update something in the screen needs to be wrapped in the setState which will update the screen. As added value need to be updated here, we have put that code in setState().
I have kept the same code in GitHub also it was coded in Flutter SDK 2.8.1. You can find it here
Comments
Post a Comment