Skip to content
सन्देशSandesh Rimal
← Outbox
Message #007 · /notes/flutter4 min read
From
Sandesh Rimal <rimal.sandesh11@gmail.com>
To
You
Sent
Subject

Building Flutter apps that stay usable on slow and unreliable networks

By Sandesh Rimal, full-stack Flutter developer in Kathmandu ·

An app tested on office Wi-Fi in Kathmandu behaves very differently on mobile data on a bus, in a basement shop or in a town far from the Valley. Connections slow down, switch networks and drop for a few seconds at a time. Users in Nepal meet this every day, so an app built for it feels better than one that only works on a fast connection.

These are the habits that help most, in the order I would add them to a new project.

1. Set timeouts on purpose

Without timeouts, a stalled request leaves the user watching a spinner for a minute or more. Set them yourself.

final dio = Dio(BaseOptions(
  baseUrl: 'https://api.example.com',
  connectTimeout: const Duration(seconds: 10),
  receiveTimeout: const Duration(seconds: 20),
));

Ten seconds to connect and twenty to receive is a reasonable start. Tune them against your slowest real screen, not a guess.

2. Retry only what is safe to repeat

Reading data (GET) can be repeated safely. Writing data (placing an order, paying, sending a message) cannot, because the first attempt may have worked even though the response never arrived.

Future<T> withRetry<T>(Future<T> Function() call, {int tries = 3}) async {
  for (var attempt = 0;; attempt++) {
    try {
      return await call();
    } on DioException catch (e) {
      final transient = e.type == DioExceptionType.connectionTimeout ||
          e.type == DioExceptionType.receiveTimeout ||
          e.type == DioExceptionType.connectionError;
      if (!transient || attempt >= tries - 1) rethrow;
      await Future.delayed(Duration(milliseconds: 400 * (1 << attempt)));
    }
  }
}

// Use it for reads only.
final products = await withRetry(() => dio.get('/products'));

The delay doubles each time (400 ms, 800 ms, 1.6 s) so a struggling network gets room to recover.

For writes, send an idempotency key with the request. The server stores it and returns the first result if the same key arrives twice. After a timeout, ask the server for the order's status instead of sending the order again.

3. Show the last good data first

The best loading state is no loading state. Save the last successful response and show it immediately, then refresh in the background.

  • Keep small lists (home feed, categories, profile) in a local store such as Hive, Isar or sqflite.
  • On launch, draw from the cache, then replace it when the fresh response arrives.
  • Show a small "updated 5 minutes ago" label so the data is never silently stale.

This also makes the app feel instant on a slow first request, which is when users decide whether it is any good.

4. Make images lighter

Images are usually the heaviest part of a screen.

  • Serve WebP and size images for the screen they appear on. A 2000 px photo in a 100 px thumbnail wastes data.
  • Use cached_network_image so each image downloads once.
  • Show a fixed-size placeholder so the layout does not jump when the image arrives.
  • Load long lists in pages of 10 to 20 items instead of everything at once.

5. Do not block the whole screen

A full-screen spinner makes a slow network feel broken. Prefer to:

  • Show the screen's structure straight away, with skeletons where data is loading.
  • Let users scroll, search and go back while a request is running.
  • Show an inline message with a Retry button when a request fails, instead of an error that replaces the screen.
  • Treat "offline" as a normal state, not a crash.

6. Test on a bad connection, not just a good one

Most network bugs never show up on a fast desktop emulator.

  • Use the Android emulator's network speed and latency settings, or a throttling tool on a real phone.
  • Switch airplane mode on in the middle of a request.
  • Test the first launch with an empty cache, and a launch with a full cache.
  • Try the same checkout flow with a 3-second delay on every response.

A short checklist

  • Timeouts set on every client.
  • Retries on reads only, with growing delays.
  • Idempotency keys on writes, and a status check after a timeout.
  • Last good data shown first, with a "last updated" label.
  • Images in WebP, sized to the screen and cached.
  • Inline retry instead of full-screen errors.
  • Tested with throttled data and airplane mode.

Takeaways

  • A slow network is the normal case for many users, so design for it first.
  • Retry reads, never blind-retry writes.
  • Cached data and light images do more for perceived speed than any code trick.
  • Test on the worst connection you can find.

Building an app for users on mobile data? See Services or get in touch. Also in the Outbox: JWT login with refresh tokens in Flutter and NestJS and the app-store rejection checklist. See the work: Chynabazar and Najik Services.

End of message

Sandesh

Reply to this message

Questions, corrections or a better way? Replies go straight to my inbox.

Reply →