Book Image

Managing State in Flutter Pragmatically

By : RAHUL AGARWAL, Waleed Arshad
Book Image

Managing State in Flutter Pragmatically

By: RAHUL AGARWAL, Waleed Arshad

Overview of this book

Flutter is a cross-platform user interface (UI) toolkit that enables developers to create beautiful native applications for mobile, desktop, and the web with a single codebase. State management in Flutter is one of the most crucial and complex topics within Flutter, with a wide array of approaches available that can make it easy to get lost due to information overload. Managing State in Flutter Pragmatically is a definitive guide to starting out with Flutter and learning about state management, helping developers with some experience of state management to choose the most appropriate solutions and techniques to use. The book takes a hands-on approach and begins by covering the basics of Flutter state management before exploring how to build and manipulate a shopping cart app using popular approaches such as BLoC/Cubit, Provider, MobX, and Riverpod. Throughout the book, you'll also learn how to adopt approaches from React such as Redux and all its types. By the end of this Flutter book, you'll have gained a holistic view of all the state management approaches in Flutter, and learned which approach is the best solution for managing state in your app development journey.
Table of Contents (14 chapters)
1
Section 1:The Basics of State Management
4
Section 2:Types, Techniques, and Approaches
8
Section 3:Code-Level Implementation

Revisiting the techniques

Let's begin by revising the concepts and keywords of all the techniques we have learned in this book, starting from the very basic—that is, setState.

Note

Some techniques (such as InheritedWidget and InheritedModel, Business Logic Component (BLoC), Cubit, and so on) have been coupled together in a single subsection due to major similarities.

setState

We studied that setState is the simplest form of state management in Flutter. This technique is used to rebuild your current widget and the widgets inside it whenever there is user interaction inside your widget. Some key points that we studied for setState include the following:

  • It is a function that allows you to rebuild your widget's build method with updated variables' values. Here is a short reminder of how it is used in the counterexample application:
    void _incrementCounter() {
        setState(() {
          _counter++;...