This content originally appeared on CodeSource.io and was authored by Jatin Hemnani
In this article, you will learn How to Update the State in Flutter.
Creating State
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Container(
);
}
}
Above you have a empty Stateful widget with empty container.
Creating Variable
String text = 'codesource.io';
Here you have created a variable which you will change when button is clicked.
Creating Button
OutlineButton(
child: Text('Change State'),
onPressed: () {
setState(() {
text = 'codesource.io is great';
});
},
)
Above you have an OutlineButton() with onPressed. To change the state you use the setState method which takes a callback and then you can easily change the state.
Result
The post Update State In Flutter appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Jatin Hemnani

Jatin Hemnani | Sciencx (2021-03-02T11:39:46+00:00) Update State In Flutter. Retrieved from https://www.scien.cx/2021/03/02/update-state-in-flutter/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.