Fixing an App with a Deprecated Library and API - Weather App Part 5

Words
1431
Reading
7 min
8y
Listen to this post
~10 min

Repository

https://github.com/flutter/flutter

What Will I Learn?

  • How to update libraries for Flutter
  • How to find and implement a new library
  • How to deal with Deprecated Libraries
  • How to deal with Deprecated APIs
  • How to update RxCommand and RxWidgets
  • How to resolve Dependency issues
  • How to update to Dart 2.0 and Flutter 1.0 from Dart 1.x

Requirements

System Requirements:
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 dependencies

Resources for Flutter and this Project:

Sources:

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

Difficulty

  • Advanced

Description

In this flutter video tutorial, we take a look at one of the older projects; the geolocation weather application. In the nine months since this application was initially built, the main Geolocation flutter library was depreciated and dropped by its maintainer. As a result it has become completely incompatible with Dart 2.0 and Flutter's release candidate. Along with finding a new geolocation based Library for this application, we update the other dependencies, which includes removing old deprecated APIs.

Finding a replacement for Geolocation

When a library is abandoned by it's maintainer, there are a few options that a developer can take: they can replace the library, build their own replacement or fork the original library. Since the main idea of this application is centered around being able to determine the user's location a library like Geolocation is mandatory. The Dart community is fairly prolific and its ecosystem is rapidly changing therefore it makes sense to find a new library. We want this new library to have a similar API to the old Geolocation Library so that we don't have to make a large amount of changes to the business logic of our application. To locate a new library, we can make use of the Dart Packages website.

dart-geo.png

The new library that was chosen for this particular application is called Geolocator. This library has a very similar API to the other Geolocation library. It has the ability to give us location data via streams and futures. We also have the ability to modify the location accuracy along with a few other important options. The library gives us access to longitude and latitude values which is precisely what we need in this case. Above is the main logic for finding the GPS status and location using this library. As with before, we want to determine whether or not the application has access to location services. Afterwards, we also want to be able to then get a future with the new positional data inside of it.

Updating a Deprecated API

When this application was originally built, the RxCommand and RxWidget libraries were in their infancy. RxCommand featured a large amount of functions which determined the type of RxCommand that the user could create based on the input function. These originaly functions had names like async1 or sync3 based on whether or not the input function was asynchronous, had parameters, and had return values. After nine months and the release of Flutter 1.0, the API for this library has changed with the older functions being replaced.

rxCommand.png

In the above image, we can see some of the new RxCommand constructor names. Rather then name the constructors by number, there are more descriptive names. For example, if the input function doesn't contain any parameters, has a return type and is asynchronous, then the RxCommand constructor would be called createAsyncNoParam. Also, each RxCommand function now features an optional canExecute field to allow the developer to combine boolean observable with the resulting command stream. This new feature along with a plethora of other optional parameters gives the developer fine grain control over the RxCommands in a way that simply wasn't possible with the original API.

The Source Code for this video may be found here: https://github.com/tensor-programming/Weather_Tutorial/tree/tensor-programming-patch-4

Video Tutorial

Curriculum

Related Videos

Projects and Series

Stand Alone Projects:
Utopian Rocks Example
Building a Calculator
Movie Searcher Application

Minesweeper Game

Redux Todo App

Curriculum

Proof of Work Done

https://github.com/tensor-programming

Fixing an App with a Deprecated Library and API - Weather App Part ... | Ecency