Managing State in Flutter Pragmatically: Discover how to adopt the best state management approach for scaling your Flutter app

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Explore popular state management techniques in Flutter and implement them in real-world applications

Key Features

  • Get to grips with popular approaches for managing your Flutter application state
  • Think declaratively in order to decide on the most fitting approach for different applications
  • Learn to implement state management solutions by building a popular use case in the form of a shopping cart app

Book Description

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.

What you will learn

  • Understand the core concepts of different state management techniques used in Flutter
  • Build optimal and performant applications in Flutter
  • Develop an understanding of which technique to apply in what sort of apps
  • Build the habit of writing clean state management code
  • Produce code with techniques from beginner to advanced level for different state management solutions
  • Use state management techniques to create robust and scalable apps in Flutter

Who this book is for

This book is for developers who have already started with their Flutter journey and are now looking to learn optimal state management approaches for app development. The book will also help less experienced Flutter engineers to find the best state management solution to fit their app, along with Flutter engineers who want to learn which state management approach should be taken under what circumstances.

Table of Contents

  1. States and State Management Overview
  2. The Core Building Blocks of State Management
  3. Diving into Advanced State Management Approaches
  4. Adopting State Management Approaches from React
  5. Executing Distinctive Approaches like GetX, GetIt, and Binder
  6. Creating a Shopping Cart Application Using Basic Approaches
  7. Manipulating a Shopping Cart Application through BLoC, Provider, and React-Based Approaches
  8. Using GetX, GetIt, and Binder to Update the Cart Application
  9. Comparative State Management Analysis: When to Use What?

Author(s): Waleed Arshad
Edition: 1
Publisher: Packt Publishing
Year: 2021

Language: English
Pages: 246
Tags: Flutter; GUI Toolkit; Flutter State Management;

Cover
Title
Copyright and Credits
Table of Contents
Section 1:The Basics of State Management
Chapter 1: States and State Management Overview
Flutter – a brief introduction
What is a state?
Importance of a state in an application
Different states in a large application
What is state management?
Choosing the best technique for your application
Summary
Chapter 2: The Core Building Blocks of State Management
Technical requirements
Managing states within a widget with setState
The counter application example
Widget rebuilding – widget trees
Passing data to another screen – setState example
Updating the first screen's counter value
Section overview – setState
Optional challenge – setState
Inherited widgets – injecting the state at the root
Inherited widgets – updating the counter variable
Section overview – inherited widgets
Inherited models – optimizing inherited widgets
Remember the optional challenge?
Section overview – inherited models
Summary
Section 2:Types, Techniques, and Approaches
Chapter 3: Diving into Advanced State Management Approaches
Technical requirements
Provider – using less boilerplate code than InheritedWidget
Adding a Provider dependency in a sample application
Consuming Provider using the ChangeNotifierProvider class
Section overview – Provider
Riverpod – enhancing Provider
Adding a Riverpod dependency in a sample application
Using the simplest version of Riverpod to update the counter value
Using a custom class as a state in Riverpod
Section overview – Riverpod
BLoC – writing business logic separately
Adding a BLoC dependency in your application
Creating a counter example application using BLoC
Optional challenge – BLoC
Section overview – BLoC
Cubit – simplified BLoC
Creating a counter example application using Cubit
Section overview – Cubit
Summary
Chapter 4: Adopting State Management Approaches from React
Technical requirements
Redux – using unidirectional data flow
Adding a Redux dependency to a sample app
Consuming Redux using StoreProvider in code
Section overview – Redux
MobX – using observables with the fewest lines of code
Adding MobX, Build Runner, and Codegen dependencies to the sample app
Using code generation to create boilerplate code through build runner
MobX – section overview
Summary
Chapter 5: Executing Distinctive Approaches Like GetX, GetIt, and Binder
Technical requirements
GetX – simplified reactions
Adding a GetX dependency in a sample application
Example of a counter application using GetBuilder
Exploring more in GetX
Section overview – GetX
Optional challenge – GetX
GetIt – no BuildContext required
Adding a GetIt dependency in a sample application
Counter example application using GetIt
Section overview – GetIt
Binder – using scopes to separate business logic
Adding a Binder dependency in a sample application
Counter example application using Binder
Section overview – Binder
Summary
Section 3:Code-Level Implementation
Chapter 6: Creating a Shopping Cart Application Using Basic Approaches
Technical requirements
Creating a shopping cart application with setState
Section overview
Optional challenge
Creating a shopping cart application with InheritedWidget
Section overview
Optional challenge
Creating a shopping cart application with InheritedModel
Section overview
Summary
Chapter 7: Manipulating a Shopping Cart Application through BLoC, Provider, and React-Based Approaches
Technical requirements
Creating a shopping cart application with BLoC
Creating a shopping cart application with Cubit
Creating a shopping cart application with Provider
Creating a shopping cart application with Riverpod
Creating a shopping cart application with Redux
Creating a shopping cart application with MobX
Summary
Chapter 8: Using GetX, GetIt, and Binder to Update the Cart App
Technical requirements
Creating a cart app with GetX
Optional challenge – GetX
Creating a cart app with GetIt
Creating a cart app using Binder
Summary
Chapter 9: Comparative State Management Analysis: When to Use What?
Technical requirements
Revisiting the techniques
setState
InheritedWidget and InheritedModel
Provider
Riverpod
BLoC and Cubit
Redux
MobX
GetX
GetIt
Binder
Mapping different techniques to different application ideas
setState
InheritedWidget/InheritedModel
Provider/Riverpod
BLoC/Cubit
Distinctive approaches
Redux
MobX
Creating a good architecture
Author's choice of state management technique – a hybrid approach
A short overview of state management decision-making
Summary
Index