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

in #utopian-io6 years ago (edited)

Repository

https://github.com/flutter/flutter

What Will I Learn?

  • You will learn how to use Redux in Flutter
  • You will learn about Actions and Reducers
  • You will learn how to properly use Immutable state
  • You will learn about View-Models in Redux
  • You will learn how to make handlers and callbacks to call to your store and reducers
  • You will learn how to properly structure a Redux application in a Modular way

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 state and state management
  • 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 revisit the Flutter Redux library to fully flesh out the concepts and abstractions. In the original Flutter Redux tutorial, found here, the application was much smaller and only had a single action which gave the user the ability to add items to a small list. In this tutorial, we rebuild our application in a much more idiomatic and modular way so that we can expand upon it with middleware, thunks, and epics in the coming videos.

We add multiple actions which gives the application much more functionality; the user now has the ability to remove items either one at a time or all at once. This also means that the reducer used to create this application is more complex which will lead into the ability to talk about combined reducers and typed reducers. The tutorial spends more time explaining the concepts to properly setup the expanded abstractions which will be demoed in this series.

Description

Revisiting Redux - A General Overview of Redux in Flutter

The Redux pattern is a design pattern that was originally introduced by developers over at facebook. It is an extension of the already popular and powerful state management concepts introduced in Flux. Flutter follows a similar structure to React which makes the Redux pattern an obvious choice for managing state in a Flutter application.

Redux follows three simple tenets which have fairly far reaching implications:

  • There is a single source of truth; in other words, your application state is kept in a single place called a store.
  • The application state must be read only. When you change the state of your application, you create new state rather than mutate old state.
  • These state changes committed through pure functions or functions with no side effects.

By constraining how we write the logic for our application using these ideas, we gain quite a lot of control over our application's state. Gaining this type of control over our state also leads to a more cleanly structured code-base. The pure reducer functions are also easier to test then non-pure logic functions. All of these benefits make Redux well suited for larger more complex applications.

redux-reducer.png

The above image highlights the main reducer used in this stage of our application. This reducer is responsible for adding and removing our items based on the action dispatched to the store. The reducer is pure and predictable which makes debugging and testing fairly simple.

The Redux Circle of Application Life

Any Redux application follows a specific pattern which makes reading the code and working with the code fairly predictable. The user interacts with the UI through a ViewModel and this ViewModel then dispatches an Action to a Reducer. The Reducer then follows the action and decides how the store will change the state. The store then updates the UI with the new ViewModel that it generates and then this process repeats. With more complex applications, another step is added before the Action is pushed to the Reducer in the form of middleware. Middleware is required when you want to have a side effecting behavior in our application. Middleware handles state persistence, calling APIs, dispatching data to other systems and other behaviors that occur outside of the system.

redux-circle.png

Above you can see the simple version of the Redux circle that we are using in this particular application at the moment. As we add more features and behavior to our application, we will also be adding middleware to this graph.

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:  

Excellent work @tensor. I do appreciate that you self-evaluate your work and supplement with alternative explanations and examples as you did here.

Looking forward to the next part of this series.

  • 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 bucky, I do appreciate that. I am glad this video went over so well.

Thank you for your review, @buckydurddle!

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

Hey, @tensor!

Thanks for contributing on Utopian.
Congratulations! Your contribution was Staff Picked to receive a maximum vote for the video-tutorials category on Utopian for being of significant value to the project and the open source community.

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!

Loading...

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64029.44
ETH 3157.04
USDT 1.00
SBD 4.02