Giter Club home page Giter Club logo

flutter-andreab-archs's Introduction

andreab_archs

I created this project to show how I'd refactor some excellent work done by Andrea Bizzotto. He created a demo of 4 different state management techniques with flutter. There are some similar demonstrations out there, but this one is right on for being simple and showing the differences. (Although, I do like my updates shared in this project.)

Please see his work that this work is built on:

Refactorings of Andrea's project

  • Using the Firebase FireStore rather than the Realtime database. Greatly simplified data access.
  • Remove Future's from data access. Not really needed because all updates come through stream.
  • Abstract Database class has more meaningful CRUD method names and ALL access is via this interface.
  • Rename class Counter to class CounterData and remove id to use auto generated Firebase DocumentId.
  • bottom_navigation no longer depends on scoped_model and redux packages. That code has been moved to the respective pages.

REQUIRED SETUP TO USE THIS CODE

You must create and reference a FireStore database. Please see this other Most Excellent Video by Tensor Programming

Description of differences between Implementations

SetState Example - ListItemsBuilder

  • Stateful Widget
  • Listens to Stream of Counters (CounterValues) triggered by Firestore
  • Subscribe and call setState() when triggered
  • Uses ListItemsBuilder

Streams Example - StreamBuilder

  • Stateless Widget
  • Uses StreamBuilder that will automatically build based on snapshot of stream
  • Fairly similar to above SetState, but no longer need to manage subscriptions and call SetState
  • No state management required.

ScopedModel Example - ScopedModel

  1. Create Model (part of ScopedModel library) that holds data list
  2. On update to list, call notifyListeners(). In this case, the stream from firestore is used both to get the current data list, and to determine when there are updates.
  3. The ScopedModel(Widget) is created with a reference to the Model and with UI (ScopedModelWidget).
  • Now when the model sees and update, it calls notifyListeners() which will trigger the UI to rebuild.
  • This allows you to remove model state out of the widget.

Redux Example

  • Made to work, but discussion is beyond scope of this effort.

flutter-andreab-archs's People

Contributors

eelfner avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.