Advanced Flutter Project - Third BLoC, StreamControllers and Periodic Observables - Part Six
Repository
https://github.com/flutter/flutter
What Will I Learn?
- You will learn how to use StreamControllers
- You will learn about Periodic Observables
- You will learn how to delay polling
- You will learn about polling APIs
- You will learn how to create a computation BLoC
- You will learn how to approximate a Steem account's recharge time
- You will learn how to use Intl to format timestamps
Requirements
System Requirements:
- IDEA intellij, Visual Studio Code with the Dart/Flutter Plugins, Android Studio or Xcode
- The Flutter SDK on the latest Master Build
- An Android or iOS Emulator or device for testing
OS Support for Flutter:
- Windows 7 SP1 or later (64-bit)
- macOS (64-bit)
- Linux (64-bit)
Required Knowledge
- A basic knowledge Programming
- A fair understanding of Mobile development and Imperative or Object Oriented Programming
- Basic knowledge of the BLoC
Resources for Flutter and this Project:
- Flutter Website: https://flutter.io/
- Flutter Official Documentation: https://flutter.io/docs/
- Flutter Installation Information: https://flutter.io/get-started/install/
- Flutter GitHub repository: https://github.com/flutter/flutter
- Flutter Dart 2 Information: https://github.com/flutter/flutter/wiki/Trying-the-preview-of-Dart-2-in-Flutter
- Flutter Technical Overview: https://flutter.io/technical-overview/
- Dart Website: https://www.dartlang.org/
- Flutter Awesome GitHub Repository: https://github.com/Solido/awesome-flutter
- The Flutter Provider Library: https://github.com/rrousselGit/provider
Sources:
Flutter Logo (Google): https://flutter.io/
Difficulty
- Advanced
Description
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.
Using StreamControllers in BLoCs
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.
Periodic Observables and API Polling
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
Video Tutorial
Curriculum
Related Videos
- Advanced Flutter Project - Setting Up the Basic Structure - Part One
- Advanced Flutter Project - Adding a Second BloC - Part Two
- Advanced Flutter Project - Best Practices - Generic BLoC Providers - Part Three
- Advanced Flutter Project - Adding Fonts and Fuzzy Timestamps - Part Four
- Advanced Flutter Project - Filtering Contributions and Building Aesthetics - Part Five
Projects and Series
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
Curriculum
- Building a Multi-Page Application with Dart's Flutter Mobile Framework
- Making Http requests and Using Json in Dart's Flutter Framework
- Building Dynamic Lists with Streams in Dart's Flutter Framework
- Using GridView, Tabs, and Steppers in Dart's Flutter Framework
- Using Global Keys to get State and Validate Input in Dart's Flutter Framework
- The Basics of Animation with Dart's Flutter Framework
- Advanced Physics Based Animations in Dart's Flutter Framework
- Building a Drag and Drop Application with Dart's Flutter Framework
- Building a Hero Animation and an Application Drawer in Dart's Flutter Framework
- Using Inherited Widgets and Gesture Detectors in Dart's Flutter Framework
- Using Gradients, Fractional Offsets, Page Views and Other Widgets in Dart's Flutter Framework
- Making use of Shared Preferences, Flex Widgets and Dismissibles with Dart's Flutter framework
- Using the Different Style Widgets and Properties in Dart's Flutter Framework
- Composing Animations and Chaining Animations in Dart's Flutter Framework
- Building a Countdown Timer with a Custom Painter and Animations in Dart's Flutter Framework
- Reading and Writing Data and Files with Path Provider using Dart's Flutter Framework
- Exploring Webviews and the Url Launcher Plugin in Dart's Flutter Framework
- Adding a Real-time Database to a Flutter application with Firebase
- Building a List in Redux with Dart's Flutter Framework
- Managing State with the Scoped Model Pattern in Dart's Flutter Framework
- Authenticating Guest Users for Firebase using Dart's Flutter Framework
- How to Monetize Your Flutter Applications Using Admob
- Using Geolocator to Communicate with the GPS and Build a Map in Dart's Flutter Framework
- Managing the App Life Cycle and the Screen Orientation in Dart's Flutter Framework
- Making use of General Utility Libraries for Dart's Flutter Framework
- Interfacing with Websockets and Streams in Dart's Flutter Framework
- Playing Local, Network and YouTube Videos with the Video Player Plugin in Dart's Flutter Framework
- Building Custom Scroll Physics and Simulations with Dart's Flutter Framework
- Making Dynamic Layouts with Slivers in Dart's Flutter Framework
- Building a Sketch Application by using Custom Painters in Dart's Flutter Framework
- Using Dart Isolates, Dependency Injection and Future Builders in Dart's Flutter Framework
- Looking at the Main Features of the Beta Three Release of Dart's Flutter Framework
Hello @tensor,
Can't believe that we have reached to the end of the series. It has been very educational watching the entire mobile app developing from the beginning. This is going to be so useful.
Again, I don't have any new suggestions to make as the video quality, presentation, outlines, supplementary materials, content etc are all done with superb quality.
Top-Notch!
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]
@rosatravels, this is actually not the end of the series. Still have to add in the new features (contribution ordering, reward percentage etc). I am hoping to finish the series in like one or two more videos though.
As always, thanks for moderating my contribution.
Thank you for your review, @rosatravels! Keep up the good work!
Great @tensor, will look forward to the continuing series. Have a fantastic Christmas.
Posted using Partiko Android
Have a happy holiday as well, @rosatravels.
Hi @tensor!
Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server
Hi, @tensor!
You just got a 7.2% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
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!
Congratulations @tensor! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word
STOP