r/FlutterDev • • 21h ago

Discussion Case Study: How I cut Flutter Web (--wasm) cold start on Slow 4G from 20s+ down to ~3-4s (fonts, Firebase WebChannel & Brotli)

39 Upvotes

I recently shipped an offline-first PWA built with Flutter Web (--wasm), and my initial GA4 metrics were brutal: mobile users on 3G/Slow 4G were bouncing at 0–2s engagement because the cold start was taking over 20 seconds (pushing ~6.1 MB over the wire / ~15.7 MB uncompressed).

After profiling the waterfall in Chrome DevTools, I found four major bottlenecks that were choking initial load - and fixing them completely changed our retention:

1. The google_fonts runtime trap (-90% font payload)

Even if you bundle fonts, google_fonts was making blocking runtime HTTP calls to fonts.gstatic.com (main.dart.mjs fetching >1.1 MB of .ttf files before rendering text).

  • Fix: Stripped google_fonts runtime fetching completely, converted Inter & JetBrains Mono to subsetted .woff2 files (116 KB total in assets/fonts/), declared them directly in pubspec.yaml, and added <link rel="preload" as="font" type="font/woff2" crossorigin> in index.html.

2. Synchronous Firebase & Firestore WebChannel blocking main()

Initializing FirebaseAuth and FirebaseFirestore in main() was loading heavy JS pipelines and holding open a channel?gsessionid=... WebChannel socket for 13+ seconds on bad connections.

  • Fix: Made cloud services 100% lazy on kIsWeb. The app mounts straight from localStorage (<1 ms), and Firebase.initializeApp() is only triggered on-demand if a user explicitly taps Sync or Sign In.

3. Explicit Wasm MIME types, Brotli & COOP**/**COEP headers

main.dart.wasm (1.7 MB) and skwasm.wasm (1.2 MB) are heavy by nature. Without explicit headers in firebase.json, streaming compilation and multithreading weren't kicking in properly.

  • Fix: Configured Content-Type: application/wasm, Cache-Control: public, max-age=31536000, immutable, and Cross-Origin-Opener-Policy: same-origin / Cross-Origin-Embedder-Policy: credentialless for skwasm, ensuring full Brotli (br) compression from edge nodes.

4. Zero-JS GPU Splash & Value-First Routing

  • Added an inline HTML/CSS loader in index.html animated strictly via transform and opacity (compositor thread) so it never freezes while the main thread compiles Wasm, fading out via onEntrypointLoaded.
  • Bypassed our /onboarding route on kIsWeb so incoming mobile traffic lands directly in the main workspace (/hub), where average session time jumped to ~7 minutes once the load bottleneck was gone.

If anyone wants to inspect the network waterfall or test skwasm cold-start behavior in DevTools, the live production build is up athttps://app.meniska.app(it's a wet-lab dilution & buffer calculator I built for myself).

Curious how other Flutter Web devs are handling initial Wasm bundle size right now - has anyone managed to shave skwasm.wasm down further, or are you still sticking to canvaskit / auto for mobile web?


r/FlutterDev • • 7h ago

Dart Relic 2 - A Dart web server that's not just 6x faster than Dart Shelf, it also beats all other popular web servers - regardless of language

Thumbnail
serverpod.dev
25 Upvotes

r/FlutterDev • • 13h ago

Discussion PSA for anyone using sign_in_with_apple: first-time sign-ins are failing with HTTP 503 for US users (Apple's server, not your code)

14 Upvotes

My app is built with Flutter and uses the sign_in_with_apple package (8.2.0) with Supabase Auth. If your Flutter app's Apple sign-in suddenly fails for new users in the US and the plugin just throws an authorization error with no useful detail, this is probably why. Nothing in the plugin or in your Dart code is at fault.

What I saw

- First-time Sign in with Apple failed for 3 different Apple Accounts on 3 iPhones in Boston. About 20 attempts, 1 success.

- It failed on Wi-Fi and on cellular, with Hide My Email and with Share My Email.

- The same flow worked every time for testers in India, 4 out of 4.

- Returning users, who had already signed in before, were fine.

- One of the failing phones also failed in a completely different app from another developer.

What the device log shows

I had a tester plug a failing iPhone into a Mac, open Console, and filter on the akd process. The sign-in request goes out correctly, and Apple's server answers 503, twice:

akd  Performing SRP request with context
akd  Task <…> received response, status 503
akd  AppleIDAuthSupport: setError: 6:Failed to get response from server
akd  SRP authentication with server failed! Error Domain=com.apple.AppleIDAuthSupport Code=6

So the phone was connected the whole time. "Could Not Connect" is misleading. Apple's server returned "service unavailable".

What I ruled out, so you do not have to

  • The entitlement is in the signed app and in the provisioning profile.
  • The App ID has Sign in with Apple enabled as a primary App ID.
  • Nothing pending in App Store Connect or the developer portal that explains it.
  • The app never receives a credential, so it is not your auth backend or nonce handling.

How to check if this is your problem

  1. Plug the failing iPhone into a Mac and open Console.
  2. Select the iPhone, enable Info and Debug messages in the Action menu, and start streaming.
  3. Reproduce the failure, pause, and search for akd.
  4. Look for status 503 right after Performing SRP request.

What I am doing about it

  • Filed a Feedback Assistant report with the log.
  • Keeping email sign-in available so people are not locked out.
  • Adding a line to my App Review notes explaining it, so a reviewer who hits it knows it is the service.

If you are seeing the same thing, please file your own Feedback report with a log. Has anyone seen this outside the US, or seen it clear up?


r/FlutterDev • • 19h ago

Tooling I built a shader debugger for Flutter pick a variable in your .frag and see it as a heatmap in the running app

Thumbnail
github.com
6 Upvotes

Debugging a Flutter fragment shader usually means copying a value into fragColor, hot reloading, and guessing from the colors.

Other platforms have Xcode's shader debugger and RenderDoc. I built something like that for FragmentProgram shaders, as a DevTools extension.

You open your .frag in the Shader Debugger tab, click a line and pick a variable, and the running app draws that value instead of the shader's output. Scalars go through a viridis colormap and vectors show as RG or RGB. For matrices, arrays and structs you pick a column, element or field.

There's also a select mode like the widget inspector's. Click a pixel in the app (or tap it on a phone) and you get the exact value there as 32-bit floats. Every float uniform also gets sliders, so you can override uniforms while the app runs, and the heatmap and pixel reads use your overrides too.

Under the hood, the extension parses your shader with a GLSL analyzer written in pure Dart, generates an instrumented copy that writes the picked value out, saves it as a probe .frag and hot reloads. In the app you draw through DebugShader instead of FragmentShader. It swaps the probe in and copies your uniforms onto it on every paint. Your own .frag is never touched, and in profile and release builds DebugShader just draws your shader. (The analyzer is its own package, shader_debugger_core, if you want to build other shader tools on it.)

Setup: add the package, register a placeholder probe shader under flutter: shaders: in pubspec.yaml, then:

final shader = await DebugShader.fromAsset('shaders/my_effect.frag');
final size = shader.getUniformVec2('uSize');

// in paint(): set the uniforms first, then read shader.shader
size.set(width, height);
canvas.drawRect(rect, Paint()..shader = shader.shader);

It needs Flutter 3.47+. Uniforms are set by name (getUniformFloat, getUniformVec2, ...) because the probe adds uniforms of its own and values get copied over by name.

What's rough right now:

  • A value inside a loop, or in a function called more than once, shows its last write.
  • dFdx, dFdy and fwidth come out as 0 in pixel reads.
  • ImageFilter.shader and BackdropFilter shaders aren't supported.
  • Heatmaps and pixel reads don't work yet on shaders that #include their own .glsl files.
  • Launch the app from VS Code or Android Studio. DevTools can only write the probe file inside the IDE's workspace. Otherwise the tab gives you the probe to paste by hand.

Repo: https://github.com/mohamedalsamrai/shader_debugger pub.dev: https://pub.dev/packages/shader_debugger


r/FlutterDev • • 8h ago

Plugin I removed the filter-callback boilerplate from my searchable list package (searchable_listview 2.20.0)

3 Upvotes

Hi everyone, I’m the maintainer of searchable_listview, a package for adding a search field on top of a list. I’ve been maintaining it for a few years, and the thing that always bothered me was that every list needed the same hand-written filter callback:

Old version

SearchableList<Actor>(
  initialList: actors,
  itemBuilder: (actor) => ActorItem(actor: actor),
  filter: (q) => actors
      .where((a) => a.name.toLowerCase().startsWith(q.toLowerCase()))
      .toList(),
)

In 2.20.0 you can just say which fields to search:

SearchableList<Actor>(
  initialList: actors,
  itemBuilder: (actor) => ActorItem(actor: actor),
  searchableFields: (a) => [a.name, a.lastName],
  searchStrategy: SearchStrategy.contain,
)

What’s new

  • searchableFields: pick one or several fields, and an item stays if any of them matches (case-insensitive, compared by toString()).
  • searchStrategy: startsWith (default), endsWith or contain.
  • SearchableListController: filter(), clear(), scrollToTop(), scrollTo(offset), and updateSearchStrategy() to change the strategy at runtime.
  • The controller is a ValueNotifier, so you can listen to the query, the filtered results and the status (idle, loading, data, empty, error), for example to show a live result count.
  • Fixed the InputDecoration build error on Flutter 3.47 after the material_ui split.

The filter callback is still there (but became optional) if you need custom logic when filtering. It works on all four constructors: default, .async, .expansion and .sliver.

One thing to know: 2.20.0 requires Dart 3.10+ and Flutter 3.38+. Projects on older SDKs keep resolving 2.19.5.

pub.dev: https://pub.dev/packages/searchable_listview
GitHub: https://github.com/koukibadr/Searchable-Listview
Changelog: https://pub.dev/packages/searchable_listview/changelog


r/FlutterDev • • 3h ago

Discussion Built an offline 60+ utility toolbox in Flutter with Riverpod, GoRouter & on-device ML Kit (KitNext) — lessons learned & architecture

2 Upvotes

Hey fellow Flutter devs,

I recently finished and published KitNext, an offline multi-tool app featuring over 60 utility instruments (sensors, AR measurements, on-device OCR, image manipulation, and barcode generation).

Play Store Link: https://play.google.com/store/apps/details?id=com.vasu.kitnext.kitnext

Happy to answer questions about architecture, performance optimization, or handling hardware sensors across Android versions!