Git Product home page Git Product logo

multiple-counters-flutter's Introduction

Flutter State Management

This is a sample app showing four different approaches to managing state in Flutter:

setState vs StreamBuilder vs scoped_model vs redux

Use case: manage multiple counters, synced with Firebase Database.

Watch my video for a full overview of the differences and tradeoffs between these techniques:

Supported tasks:

  • Show a list of counters
  • Add new counters
  • Increment or decrement existing counters
  • Remove counters (swipe left to dismiss)

Database

The app uses Firebase as a source of truth for the state of the counters. This allows the data to be easily synced across multiple clients. Realtime Database and Cloud Firestore are both supported (see database.dart class).

NOTE: For simplicity, the whole database has public read/write access, and counters can't be set per-user. For a production app it would be more appropriate to set user access rules.

State management

The same functionality is replicated in four different pages accessible via the bottom navigation bar, using different state management techniques:

Running the project

You need to register the project with your own Firebase account.

  • Use com.musevisions.multipleCountersFlutter as your bundle / application ID when generating the Firebase project.

  • Download the ios/Runner/GoogleService-Info.plist and android/app/google-services.json files as needed.

For more articles and video tutorials, check out Coding With Flutter.

License: MIT

multiple-counters-flutter's People

Contributors

bizz84 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

multiple-counters-flutter's Issues

FAILURE: Build failed with an exception.

registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugGoogleServices'.
> File google-services.json is missing. The Google Services Plugin cannot function without it. 
   Searched Location:
  R:\multiple-counters-flutter-master\android\app\src\nullnull\debug\google-services.json
  R:\multiple-counters-flutter-master\android\app\src\debug\nullnull\google-services.json
  R:\multiple-counters-flutter-master\android\app\src\nullnull\google-services.json
  R:\multiple-counters-flutter-master\android\app\src\debug\google-services.json
  R:\multiple-counters-flutter-master\android\app\src\nullnullDebug\google-services.json
  R:\multiple-counters-flutter-master\android\app\google-services.json

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org
BUILD FAILED in 31s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

What should I do about this?

Can the firestore stream only return changes?

Hi Andrea,

I love your videos and your coding style. It is very clean and easy to follow.

I have a question about this app. I noticed that all of the counters are sent to and from Firestore when only one changes. This could use a lot of wireless data usage as the collection grows (i.e. 1MB) and only a single field changes. Is there a way to only send changes through the stream.

I put the following print statement in database.dart at line 133 to see what was being sent/received:
print(documentSnapshot['value']);

Thanks for your help.

Project failing to build

Hello,
First many thanks for this excellent tutorial.

I have forked this project, created the required Google Service to support it, using the package name com.musevisions.multipleCountersFlutter. However, when I try to run the app I see the following errors:

java.lang.IllegalStateException: Dex archives: setting .DEX extension only for .CLASS files
at com.google.common.base.Preconditions.checkState(Preconditions.java:456)
at com.android.builder.dexing.ClassFileEntry.withDexExtension(ClassFileEntry.java:64)
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.removeDeletedEntries(DexArchiveBuilderTransform.java:274)

I am attempting to build using VSCode.

Plus many more of a similar nature.

Can you help to resolve this?
Sid

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.