Making Your Flutter App Launch Faster: Tips for Using Services
FlutterPulseThis article was translated specially for the channel FlutterPulseYou'll find lots of interesting things related to Flutter on this channel. Don't hesitate to subscribe!🚀

Make Flutter App Launch Faster
Some tips to make a Flutter App with vendor services launch faster.
If you are a member, please continue, otherwise, read the full story here.
I. Introduction
As your Flutter app grows, you may need various vendor services such as Adapty, AppsFlyer, Sentry, Amplitude, and others to track analytics, debug issues, and improve a Flutter app. However, developers often don't plan for these needs when designing an app's architecture. This can lead to major refactoring in the future, affecting an entire project or significant parts of it due to slow app startup.
Below are some tips on how to make a Flutter app launch faster when using vendor services.
II. Understanding the Problem
It is important to understand that launching a Flutter app can be divided into two stages:
- a Flutter app is started by an operating system (Android, iOS, and others).
- Execution of code within a project.
The first stage depends on many factors, such as battery level, processor performance, available memory, and other device parameters.Flutter developers have little control over this process, so we will focus on the second stage.
During the second stage, a Flutter app can initialize services such as Adapty, AppsFlyer, Sentry, Amplitude, and others, and some of them attempt to connect to their servers to retrieve or transmit data for further operation.
There are two issues with the service initialization process:
- Connection to a server — Any interaction with a server takes time.
- Slow or unstable user connection — If a user's connection to a server is slow or unstable, service initialization may take longer than expected. This can slow down or even prevent a Flutter app from starting, depending on how the project code is written..
For example, if a Flutter app initializes services like this:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await serviceInitialiazation();
runApp(const YourAppWidget());
}Or like this example:
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
serviceInitialiazation();
super.initState();
}
@override
Widget build(BuildContext context) {
// a service initialization listener here
}
}The examples above can slow down a Flutter app's startup since services need time to connect to their servers and exchange data during initialization. If there is no connection to a service server on a user's side at all, a Flutter app may fail to start.
III. Tips
III.1 If a service has servers in multiple regions and its SDK allows configuring the connection by region, determine the user's region and connect the user to the nearest server.
Future<void> someServiceInitialization() async {
// NOTE: Different services may use different standards
// for region identification,
// so the logic for determining a user's region may vary.
final userRegion = getUserRegion();
// NOTE: A server may not be available in the user's exact region.
// Implement logic to select the nearest available region
// if necessary.
final baseUrl = getBaseUrl(userRegion);
await SomeService.initialize(
apiKey: someApiKey,
backendConfiguration: BackendConfiguration(
baseUrl: baseUrl,
),
);
}III.2 If a service needs to be initialized when a Flutter app starts to immediately work with loaded and sent data, reduce initialization time by sending and loading only essential data. The remaining data can be sent and loaded asynchronously.
Retrieving:
/// Service initialization for immediate data processing
Future<void> someServiceInitialization() async {
await SomeService.initialize();
// Fetch critical data required at app startup
final essentialData = await SomeService.getSomeData();
// Load non-essential data in the background
// to avoid blocking the app launch
GetRemainingDataAsynchronously();
}
Uploading:
/// Service initialization for uploading critical data before app startup
Future<void> someServiceInitialization() async {
await SomeService.initialize();
// Upload only the essential data required before the app starts
await SomeService.uploadSomeData(someData);
// Upload non-essential data in the background
// to prevent delays in app launch
UploadRemainingDataAsynchronously();
}
III.3 Initialize services asynchronously if the retrieved data is not required immediately after a Flutter app starts. Before using services in different parts of a Flutter app, ensure they have been successfully initialized. This approach makes a Flutter app startup independent of a service initialization process.
bool isSomeServiceInitialized = false;
/// Asynchronous service initialization
Future<void> someServiceInitialization() async {
SomeService.initialize().then((_) {
isSomeServiceInitialized = true;
});
}
/// Service initialization does not stop a Flutter app startup
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
servicesInitialiazation();
runApp(const YourAppWidget());
}
/// Checking initialization before using a service
void someFunction() async {
if(isSomeServiceInitialized) {
doSomethingWithService();
}
}
IV. Conclusion
Issues Affecting App Launch Speed Related to Services:
- Some services such as Adapty, AppsFlyer, Sentry, Amplitude, and others try to connect to their servers and exchange data during initialization, which increases a Flutter app's launch time.
- If a service fails to initialize due to a lack of connectivity or an unstable connection, it may slow down or even interrupt a Flutter app's launch.
Ways to Speed Up and Improve the Stability of App Launch:
- Connect services to their closest servers to the user.
- If data retrieval and processing from servers are necessary, request only the minimum required data for a Flutter app's operation, and fetch the rest after the app has started.
- If immediate data processing from servers is not required, initialize services asynchronously. This ensures that a Flutter app's launch remains independent of service initialization.