Building a Todo/CRUD Application In Flutter With Redux - Part 2

in #utopian-io6 years ago (edited)

Repository

https://github.com/flutter/flutter

What Will I Learn?

  • You will learn about Redux Middleware
  • You will learn how to use the Flutter Redux Dev Tools
  • You will learn how to use modular design to expand a Redux application
  • You will learn how to add actions which dispatch to and from middleware
  • You will learn about the StoreBuilder Widget

Requirements

System Requirements:
OS Support for Flutter:
  • Windows 7 SP1 or later (64-bit)
  • macOS (64-bit)
  • Linux (64-bit)

Required Knowledge

  • A basic knowledge of Redux
  • A fair understanding of Mobile development and Imperative or Object Oriented Programming
  • Basic knowledge of CRUD

Resources for Flutter and this Project:

Sources:

Flutter Logo (Google): https://flutter.io/

Difficulty

  • Intermediate

Outline and Overview

In this Flutter Tutorial, we expand upon the last tutorial entry and take a look at how we can create side effects in a Redux application by using Middleware. The original application allows us to create items in a list and remove those items either one at a time or all at once. In this version of the application, we add functionality that allows us to save these entries into a shared preferences key-value store. This includes serializing and deserializing the data into JSON format to store and retrieve from the key-value store. To create this side effect we make use of middleware which sits between the user interface and the pure reducer functions. We also add the Redux Flutter developer tools so that we can see how all of this is working in real time and have the ability to walk backwards through the state changes.

Description

The Expanded Cycle of Redux

As we know from the last video, Redux follows a cycle when creating state changes. Actions are dispatched from the user interface to the pure reducer functions. These reducer functions then add new data to the store which then propagates changes back to the User interface. The missing element in this cycle of events is the ability to interface and interact with outside systems and events. Because the Reducers are pure functions, they are not allowed to create side effects. This prohibits our applications from reading from APIs and writing to Databases. This is where the Redux Middleware comes in.

In the image above, we have an amended graph of events that represents this new redux life cycle. By adding a step between where the actions are dispatched and the reducer functions we can keep our system pure and not sacrifice these types of functionalities. In this project, we demonstrate this by creating an action which is dispatched from the UI which then loads the data from a saved preferences key-value store and pushes that data into a reducer. The middleware almost acts like the UI in that it is also able to dispatch its own actions back to the reducers.

Time traveling through State using Redux Dev Tools

Because our Store is Immutable and our reducers are pure, the state changes in our application are predictable. The state changes only one way in accordance to a dispatched action and we can see how these actions were applied to the data in a series. This also allows us to make use of tools that are common in functional programming languages such as a time traveling debugger. A time traveling debugger allows us to step forward and backward through the state changes made by our application in real-time.

redux-time-travel.png

In the Flutter Redux econsystem, this time traveling Debugger comes in the form of the Flutter Redux Dev Tool library. This tool is extremely easy to implement and it allows us to look at our state in real time. Using this debugger we can also save the state in our application and transplant it to another instance of a similar or same application. As long as the Redux logic of the application is the same and the model of the application is similar, then we have the ability to re-create the state in this way.

The source code for this project can be found here

Video Tutorial

Related Videos

Projects and Series

Stand Alone Projects:
Building a Calculator
Movie Searcher Application

Minesweeper Game

Weather Application

Curriculum

Proof of Work Done

https://github.com/tensor-programming

Sort:  

Great work @tensor. Very interesting series. I appreciate your thorough approach. Good work. Looking forward to the next piece.

Time travelling ;) Who knew

Bucky

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @buckydurddle!

So far this week you've reviewed 2 contributions. Keep up the good work!

Thanks again bucky. Always a pleasure to see your comments on my content.

Loading...

Hey, @tensor!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.29
TRX 0.11
JST 0.033
BTC 63945.57
ETH 3135.76
USDT 1.00
SBD 4.00