https://github.com/flutter/flutter
Flutter Logo (Google): https://flutter.io/
In this Flutter Tutorial, we finish implementing the original Utopian Rocks application by adding the Bot Vote Count Down Timer and the bot Vote Power widget to the bottom bar. This process involves creating a third BLoC which makes use of StreamControllers and Periodic Observables. We also need to use another API; the steemit API, to obtain the information that we need to derive these values.
Up until now, when we've implemented out BLoCs, we've mainly separated the StreamSinks and the Streams from one another. In this example, we make use of the StreamController Object; an abstraction over top of the normal StreamSink which contains its own stream. There are some obvious pros and cons to decoupling the Sink and Stream from one another but combining them also gives rise to a set of pros and cons.
In this image, we have some diagrams of two different BLoCs and a StreamController. The StreamController contains a Sink and some methods. The StreamController's Stream that can be listened on and it allows us to add Data and Streams via an .add or .addStream method. In BloC-A, we use the StreamController and are able to add data either from inside of the BLoC or from an external source to this StreamController. The StreamController is then able to serve this data out to the user interface like any other Stream. In BloC-B, the external stream comes into a decoupled Sink. It is then pushed through some kind of transformer; which represents the business logic and then served via a decoupled Stream. The Sink in BloC-B is optional but we don't have the ability to close the decoupled Stream since it doesn't include a Close method. A StreamController however, can be closed just like any other StreamSink.
The Data that we are serving through this third BLoC needs to be almost real-time; however, the API doesn't give us a Websocket. As a result of this, we need to use a concept called Polling. Polling is when a http client calls a get method on an API after a specified period of time. This get method then pulls in a new response which then updates the data based on any changes that have occurred on the API's server. The downside to polling is that the server can not push changes without the client first requesting the data like with a websocket.
The two pieces of data that we are obtaining through polling are the vote power of the Utopian-io account and an approximate countdown to when the bot will vote on the next batch of contributions. In our application, the polling occurs every 120 seconds and this is done to conserve data and memory. If the application polled the data every second, the amount of data used would be problematic for users of this mobile application. We are able to maintain an illusion of a realtime countdown timer despite this by using a Observable.periodic observable. This observable gives us an incrementer at an set interval of time. In our case, this incrementor, changes its value every second. The counter is subtracted from the computed duration of the countdown. When two minutes pass, the counter is reset and the Countdown Timer and Vote Power are recalculated from the API.
The Source Code for this video may be found here: https://github.com/tensor-programming/utopian-rocks-demo/tree/tensor-programming-part-6
Stand Alone Projects:
- Dart Flutter Cross Platform Chat Application Tutorial
- Building a Temperature Conversion Application using Dart's Flutter Framework
- Managing State with Flutter Flux and Building a Crypto Tracker Application with Dart's Flutter Framework
Building a Calculator
- Building a Calculator Layout using Dart's Flutter Framework
- Finishing our Calculator Application with Dart's Flutter Framework
Movie Searcher Application
- Building a Movie Searcher with RxDart and SQLite in Dart's Flutter Framework (Part 1)
- Building a Movie Searcher with RxDart and SQLite in Dart's Flutter Framework (Part 2)
- Building a Movie Searcher with RxDart and SQLite in Dart's Flutter Framework (Part 3, Final)
Minesweeper Game
- Building a Mine Sweeper Game using Dart's Flutter Framework (Part 1)
- Building a Mine Sweeper Game using Dart's Flutter Framework (Part 2)
- Building a Mine Sweeper Game using Dart's Flutter Framework (Part 3)
- Building a Mine Sweeper Game using Dart's Flutter Framework (Part 4, Final)
Weather Application
- Building a Weather Application with Dart's Flutter Framework (Part 1, Handling Complex JSON with Built Code Generation)
- Building a Weather Application with Dart's Flutter Framework (Part 2, Creating a Repository and Model)
- Building a Weather Application with Dart's Flutter Framework (Part 3, RxCommand (RxDart) and Adding an Inherited Widget)
- Building a Weather Application with Dart's Flutter Framework (Part 4, Using RxWidget to Build a Reactive User Interface)
- Localize and Internationalize Applications with Intl and the Flutter SDK in Dart's Flutter Framework
Redux Todo App