Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Flutter Projects

You're reading from   Flutter Projects A practical, project-based guide to building real-world cross-platform mobile applications and games

Arrow left icon
Product type Paperback
Published in Apr 2020
Publisher Packt
ISBN-13 9781838647773
Length 490 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Simone Alessandria Simone Alessandria
Author Profile Icon Simone Alessandria
Simone Alessandria
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Hello Flutter! 2. Miles or Kilometers? Using Stateful Widgets FREE CHAPTER 3. My Time - Listening to a Stream of Data 4. Pong Game - 2D Animations and Gestures 5. Let's Go to the Movies - Getting Data from the Web 6. Store That Data - Using Sq(F)Lite To Store Data in a Local Database 7. Firing Up the App - Integrating Firebase into a Flutter App 8. The Treasure Mapp - Integrating Maps and Using Your Device Camera 9. Let's Play Dice: Knockout - Creating an Animation with Flare 10. ToDo App - Leveraging the BLoC Pattern and Sembast 11. Building a Flutter Web App 12. Assessment 13. Other Books You May Enjoy Appendix

Understanding state and stateful widgets

The widgets that we've seen so far are stateless widgets, meaning that once created they are immutable, and they do not keep any state information. When you interact with your users, you expect things to change. For example, if you want to convert a measure from one system to another, the result must change, based on some user input.

The most basic way to deal with changes in Flutter is using State.

State is information that can be used when a widget is built and can change during the lifetime of a widget.

An important part of this definition is that state is information that can change, and the most obvious takeaway of this concept is that when you want to add interactivity to your app, you can use State. But, if you read this definition thoroughly, it also means that it's not the widget itself that will change, it's the State of a widget that will change, and when it does, the widget will be rebuilt. When a widget has a State, it's called a stateful widget. And in Flutter, stateful widgets are immutable. It's only the State itself that changes.


Each time the State changes, the widget gets rebuilt.

Let's have a look at the main differences between a stateless widget, which we've used so far, and a stateful widget. Of course, the most obvious difference is explained by the name itself, the State: State/less and State/ful.

But there is a different implementation as well. In order to see it in detail, we'll create a new app and see it in practice.

You have been reading a chapter from
Flutter Projects
Published in: Apr 2020
Publisher: Packt
ISBN-13: 9781838647773
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image