Building a Weather Application with Dart's Flutter Framework (Part 4, Using RxWidget to Build a Reactive User Interface)

in #utopian-io6 years ago (edited)

flutter-logo.jpg

What Will I Learn?

  • You will learn about the RxWidget Plugin
  • You will learn how to access RxCommands from the User interface
  • You will learn how to use an RxLoader Widget
  • You will learn about the WidgetSelector Widget
  • You will learn about the PopupMenu Widgets

Requirements

System Requirements:
OS Support for Flutter:
  • Windows 7 SP1 or later (64-bit)
  • macOS (64-bit)
  • Linux (64-bit)

Required Knowledge

  • A basic understanding of APIs
  • A fair understanding of Mobile development and Imperative or Object Oriented Programming
  • Information from the first three parts of this series

Resources for Flutter and this Project:

Sources:

Flutter Logo (Google): https://flutter.io/

Difficulty

  • Intermediate

Description

This video tutorial is the finale of the Flutter Mobile Weather Application tutorial series detailed in these video articles: Part 1, Part 2, Part 3

Outline and Overview

General Overview

The goal of this Video Tutorial Series is to showcase how you can build out a Reactive application using the Dart's Flutter Framework. The Example application used in this tutorial series is a Weather Geolocation Application that makes use of various ReactiveX libraries and concepts. The application uses RxWidget and RxCommands which allows us to make a reactive user interface and model. The logic fetches the GPS data from the mobile device and then that data is fed into a function which fetches data from Open Weather Map's API. Both of these functions are wrapped in RxCommand abstractions so that they produce Observables. The response from the API is serialized from JSON into Dart objects using the JSON annotation and JSON serialization plugins. With these plugins, we are able to select the fields that we want to display onto the view of our application.

Outline of this Tutorial

In this video tutorial, we finish the Weather Application by importing the RxWidget library and using some of its special reactive widgets to build out a fluid user interface. The application features a button and menu in the app bar. It also uses a list view to present the weather data to the user and it has a button with a switch on the bottom bar. The button on the top, allows us to check to see if the GPS location services are active on the device. The button on the button allows us to fetch the JSON data. The switch on the bottom of the application lets the user shut off data and stop the application from fetching data or GPS coordinates.

Item 1: RxWidgets

The Flutter SDK has a fair amount of widgets which are able to directly interface with streams and stream based data. These widgets are the basis for the reactive widgets that are in the RxWidgets library. We are able to use these widgets in tandem with our defined RxCommands to create a specific rule-set that our User Interface must follow. In this way, we can have widgets change based on various events from the back-end of the application.
click-button.gif
loading_data.gif

Here you can see two of the main reactive widgets in action. On the left (top) is the GPS button which checks to GPS to see if it is turned on. If it is not turned on then the button on the bottom will not activate. On the right (bottom), we have the bottom button fetching data from the API. When the user presses this button, they are then unable to press the button again until the data has been fetched.

Item 2: Interfacing with RxCommand

RxCommand is an abstraction that sits atop of the functions that make up the business logic of our application. The outputs of these functions can be modified by other Observables and directly accessed through our User Interface widgets. With the inherited widget that was implemented in the last video, we are able to easily pass these functions around to different areas of our application.

main-func.jpg

This picture shows the main implementation of the inherited widget at the base of our widget tree. We build out the repository which is used to instantiate the Model Command object. This object is then passed into our inherited widget and any widget below it on the widget tree will have direct access to the commands.

Item 3: RxLoader and Widget Selector

The two main widgets that we use to deal with the reactive logic are the RxLoader and the Widget Selector widgets. The RxLoader widget is a widget that acts like Stream Builer widget but it has special features to help it interface with Observables. The RxLoader will show a spinner when the stream attached to it is currently in the process of loading a piece of data. Once the stream returns data, the RxLoader inflates the widget that is attached to its data builder property.

The Widget Selector widget lets you choose between two widgets based on a boolean event. In a way, its a bit like a more generalized RxLoader widget. We use the Widget Selector to verify when a command is able to execute using the command's canExecute property.

widget-selector.jpg

In this image, you can see the widget selector that was used in this tutorial. The selector chooses which widget to inflate based on whether or not the updateWeatherCommand.canExecute observable comes back as true or false. In this case, we have two buttons one which is active and another which is inactive.

Project GitHub Repository:

The Source Code for this project can be found here

Video Tutorial

Projects and Series

Related Videos

Stand Alone Projects:
Building a Calculator
Movie Searcher Application

Minesweeper Game

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

The contribution has been reviewed and scored.

Hi @tensor, I see great improvement in the presentation. With the added images focusing on the important points plus the fonts are bigger on the screen, this certainly gets people more engaged and focused as they study your tutorial.

Thank you for taking extra time to post high quality contribution for this video tutorial category.

Great work and keep them coming,
Rosa


Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

No, thank you for giving me those pointers and encouraging me to do so. I am still working on my video editing skills and looking into potential visual aids (I used slides in my last tutorial); I just didn't feel that the slides would work that well for this particular video in the series (especially since I had to cover so much). Thanks as always for moderating my content.

Yes, visual aids help learners see everything in one flash. Your technical skills are great so I am just helping you a bit on the 'teacher' side to help your learners stay engaged in your video tutorial. You are doing great. I saw your last video with all those beautiful slides. Yes, they help! But it is also true that we only have so much time in a day ..... and doing those extra slides are very time consuming. On the other hand, this will help you shine as an 'extraordinary' teacher, especially if you are in the steemit education channel.

Again an excellent work @tensor, your flutter series is very good for the open source community.

I am glad you are finding them useful. I enjoy making them so if people are learning then I am happy.

Hey @tensor! Thank you for the great work you've done!

We're already looking forward to your next contribution!

Fully Decentralized Rewards

We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.me/utopian-io

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.034
BTC 63900.40
ETH 3140.82
USDT 1.00
SBD 3.98