An HTTP request in Flutter is the standard way for an app to communicate with a backend server to fetch or send data, most often in JSON format. It is used for loading lists, submitting forms, authentication, or syncing remote content.
Flutter itself does not include networking APIs, so external packages are required.
Incorrect handling of HTTP requests is one of the main reasons Flutter apps become unstable or hard to maintain. Problems such as frozen UI, duplicated logic, or missing error handling usually come from poor networking structure.
In commercial projects, networking must be predictable, testable, and separated from UI code.
HTTP requests in Flutter are asynchronous and return Future objects. This means the request runs in the background and does not block the UI thread.
Most examples use the http package, which provides basic methods like get, post, put, and delete.
For simple use cases, the http package is enough.
final response = await http.get(
Uri.parse('https://api.example.com/users'),
);Always validate the response and handle failures before parsing data.
Query parameters should be built using Uri, not string concatenation.
final uri = Uri.https(
'api.example.com',
'/users',
{'page': '1', 'limit': '20'},
);
await http.get(uri);This avoids encoding bugs and improves readability.
HTTP requests should never be called directly inside widgets. Widgets are responsible for UI only.
Best practice is to place networking logic inside a dedicated layer, such as:
UserRepository)This separation makes the app easier to test and maintain.
The http package is good for learning and small apps, but it is limited.
In larger projects, dio is often preferred because it supports:
Interceptors are especially important for handling authentication and retries.
The http package does not support real request cancellation.
A common workaround is to ignore the response when a widget is disposed.
If cancellation is required (e.g. search suggestions), use dio, which provides cancel tokens.
build().statusCode == 200 is the only failure case.try-catch blocks.SocketException).Use HTTP requests when your app needs to:
Avoid HTTP requests when:
12 min • Jul 27, 2023
Read about the LeanCode approach to Flutter architecture. We highlight some of the design decisions that should be made when developing a feature in mobile apps. This includes our approach to dependency injection, state management, widget lifecycle, and data fetching.
10 min • Oct 27, 2025
In this article, we’re sharing LeanCode’s 12 practical Flutter and Dart patterns that help you write less boilerplate, make your code cleaner, and catch mistakes earlier. Apply these patterns and you'll find yourself coding faster, communicating more clearly with your teammates, and spending less time debugging issues that the compiler could have caught.