An example app that demonstrates how to handle some common network tasks in Flutter.
This example project is used in Devera Flutter course to demonstrate some practical sample of various networking tasks (incl. fetching data,...) in your Flutter app.
In today’s world, smartphones have become the primary source of entertainment, banking, photo/videography and shopping. To do many of the things their users request, from ordering food to booking movie tickets, apps on your smartphone needs Internet access.
If you plan to develop apps that fetch data from the Internet, you’ll need to know how to make network requests and how to handle the responses properly.
Before you start coding, take a moment to be sure that you understand some important terminology
In simple terms, when you open an app like Whatsapp, Instagram or Twitter on your smartphone, the app tries to fetch the latest data from a remote location, usually called a Server. It then displays that information to the user. A server is a centralized place that stores most user data. The app that you’re using is called the Client.
So a network request is a request for data from a client to a server.
REST stands for REpresentational State Transfer. It’s an application program interface (API) that uses HTTP requests to get or send data between computers.
Communication between a client and a server mostly happens through RESTful APIs.
The most basic form of a REST API is a URL that the client uses to make a request to the server. Upon receiving a successful request, the server checks the endpoint of the URL, does some processing and sends the requested data or resource back to the client.
There are 4 main HTTP methods that you use in REST APIs. Here’s what each of them does:
- GET: Requests a representation of the specified resource. Requests using GET only retrieve data – they should have no other effect on the data.
- POST: Submits data to the specified resource. You use this method to send data to the server, such as customer information or file uploads.
- DELETE: Deletes the specified resource.
- PUT: Replaces all current representations of the target resource with the uploaded content. Now that you have some theory under your belt, you can move on to exploring the starter project.
Now that you have some theory under your belt, you can move on to exploring the project.
| Package | Usage |
|---|---|
| HTTP | A composable, multi-platform, Future-based API for HTTP requests. |
| Dio | A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc. |
| Path Provider | Flutter plugin for getting commonly used locations on host platform file systems, such as the temp and app data directories. |
| Provider | State management and context based DI |
| JSON Serializable | Automatically generate code for converting to and from JSON by annotating Dart classes. |
| JSON Annotation | Classes and helper functions that support JSON code generation via the json_serializable package. |
| Build Runner | A build system for Dart code generation and modular compilation. |
A few resources to get you started if this is your first Flutter project:
For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.
Also, visit the Devera Academy website or Facebook fanpage to find out more about the courses.