Flutter Rest Api Crash Build A Coronavirus App

Build a Coronavirus Tracking App, and learn how to use REST APIs in Flutter

Last updated 2022-01-10 | 4.3

- Build a simple
- yet complete Coronavirus tracking application using REST APIs
- Good app architecture: learn how to structure your code and keep it modular
- Attention to detail and emphasis on writing a production-ready app

What you'll learn

Build a simple
yet complete Coronavirus tracking application using REST APIs
Good app architecture: learn how to structure your code and keep it modular
Attention to detail and emphasis on writing a production-ready app

* Requirements

* Familiarity with the Dart programming language
* Prior Flutter knowledge: stateless and stateful widgets
* common UI widgets
* Flutter installed on the system
* VS Code or Android Studio
* configured for Flutter development

Description

Welcome to this crash course, where you will learn how to use REST APIs with Dart and Flutter.

I created this course because REST APIs are used everywhere in today's web. And if you master the basics of the Dart http library, you can write Flutter apps that can tap into thousands of web APIs.

In this crash course you will build a simple but completely functional Coronavirus tracker application in Flutter.


Included in this course

- Short introduction to REST: what it is and how it works.

- Overview of the nCoV 2019 health API. This is used to fetch global data about the Coronavirus outbreak.

- Api keys & access tokens: what they are and how to use them.

- REST Client: a VSCode extension that you can use to send HTTP requests and view the response directly in VS Code.

- Design a REST API service using the Dart http package.

- Make requests and parse the JSON response data into strongly-typed model classes.

- Build a dashboard UI with nice-looking cards that show the data from the API.

- Combine multiple API requests into a single response by using futures.

- Use a RefreshIndicator to get updated data from the API.

- Error handling, and how to show alert dialogs to the user.

- Data caching with Shared Preferences, so that the data is saved on device for offline use.

Most importantly, you will learn about good app architecture as a way to structure our code and keep it modular.

This course is all about mastering the basics. It covers many important topics, with attention to detail, and emphasis on how to write a production-ready app.

By the end of this course, you will be able to build Flutter apps that connect with any other REST API that you want to use.


Course organization

The course follows a linear structure, and shows how to build a fully functional application from scratch.

The content is divided into multiple sections, each covering a specific topic in detail.

Full source code is provided for each lesson, and the entire project is available on GitHub.


Premium Support

Beyond all the video content, premium support is included, so that you can ask questions if you get stuck. I'll do my best to answer all questions within 24 hours - but please keep them relevant to the course material.


Prerequisites

This course is NOT for absolute beginners.

- You should already be familiar with the Dart Language. If you are not, you can follow my introduction to Dart, which is available for free on my YouTube channel.

- You should already have Flutter installed on your system, and Visual Studio Code or Android Studio configured for Flutter development.

- You should already have some knowledge of the most common Flutter widgets, and understand the difference between stateful and stateless widgets.


Teaching style

This is a fast-paced crash course. We will build a full application from scratch, but I will not explain every single step in detail. Instead, I will focus on the most important concepts, and always explain what we're going to build and why, and then how to do it.


Enroll Today

If you want to learn how to build maintainable Flutter apps using REST APIs, and become a better software engineer, then this course is for you.

I'm very excited to share this course with you, so enroll now to get started.

Who this course is for:

  • Beginner and intermediate-level Flutter developers (this course is NOT for absolute beginners)

Course content

7 sections • 50 lectures

RESTful APIs: The Basics Preview 03:24

The nCoV 2019 Coronavirus API: Setup instructions, API Keys and Access Tokens Preview 04:51

REST Client for VS Code: Initial setup & sending requests Preview 05:10

Using Environment Variables and excluding sensitive data with .gitignore Preview 04:28

REST Client: Adding the remaining requests Preview 04:25

Useful Links & Resources Preview 00:04

App Architecture Overview Preview 02:48

Installing the http package Preview 01:14

Saving the API key + GitHub source code + the Error Lens extension Preview 02:37

The API class Preview 03:32

The APIService class: requesting an access token Preview 04:04

Important note about Android Release apk builds.

Some students have reported that running requests with the APIService implemented in this video leads to SocketException errors in release mode.

Here's a relevant StackOverflow thread:

Flutter Http error SocketException: OS Error: Connection refused

To fix this, follow these two steps:

  • Ensure that the AndroidManifest.xml file contains the Internet permission: uses-permission android:name="android.permission.INTERNET"

  • Add an 'Accept': 'application/json' header when making the request:

final response = await http.post( api.tokenUri().toString(), headers: { 'Accept': 'application/json', 'Authorization': 'Basic ${api.apiKey}' }, );

Parsing the http response and retrieving the access token Preview 02:47

Using the API Service to show the access token Preview 03:14

Adding the remaining endpoints to the API class Preview 02:01

Requesting and parsing data from the remaining endpoints Preview 05:21

Using the APIService class to show endpoint data Preview 03:51

Recap on the APIService class Preview 02:19

Useful Links & Resources Preview 00:18

The Data Repository Preview 02:44

Loading and refreshing the access token when needed Preview 02:50

Adding a Provider for the DataRepository Preview 02:58

Creating a basic dashboard UI Preview 03:47

Creating a custom card widget to show endpoint data Preview 04:01

Loading the initial endpoint data from the API Preview 02:28

Adding a refresh indicator Preview 02:25

Useful Links & Resources Preview 00:07

Loading data from multiple endpoints with Future.wait Preview 02:44

The EndpointsData class Preview 02:19

Improving the DataRepository class with generics and function arguments Preview 04:20

Showing all the cards Preview 02:56

Adding the icon assets to the project Preview 01:38

Update the cards layout, image and color Preview 06:17

Useful Links & Resources Preview 00:10

Showing when the data was last updated: client vs server approach Preview 01:10

Parsing date information from the API response data Preview 01:59

Creating a new data model to hold the date and value from the API Preview 03:19

Showing the last updated date in the UI Preview 02:30

Formatting dates with the intl package Preview 05:08

Add thousands' separators with the NumberFormat class Preview 02:14

Useful Links & Resources Preview 00:08

Error handling overview, and understanding the call stack Preview 06:17

Showing an alert dialog to the user Preview 05:21

Completing the error handling code Preview 03:19

Introduction to data persistence with Shared Preferences Preview 01:46

Writing a DataCacheService Preview 08:32

Integrating the DataCacheService in the DataRepository Preview 03:14

Injecting the DataCacheService in main.dart Preview 04:15

Hot fix: The getter 'date' was called on null Preview 05:08

Useful Links & Resources Preview 00:06