Skip to content

InternalStoragePathHandler still unusable on stable: toMap() recurses into itself (fixed on master, never released) #2886

Description

@issadicko

Is there an existing issue for this?

  • I have searched the existing issues

Closest prior report is #2451, which was auto-closed as stale (Dec 2025) and locked without triage. The bot's closing message asks to open a new bug, so here it is — with the added information that the fix already exists on master but has never been released on a stable channel.

Current Behavior

InternalStoragePathHandler is unusable on the current stable release. Using it in a WebViewAssetLoader throws StackOverflowError the first time the InAppWebView is built, before any request is served.

AndroidInternalStoragePathHandler.toMap() calls itself instead of super.toMap().

flutter_inappwebview_android-1.1.3/lib/src/webview_asset_loader.dart, lines 196-199:

  @override
  Map<String, dynamic> toMap() {
    return {...toMap(), 'directory': directory};   // ← recurses into itself
  }

It should spread super.toMap(), which the AndroidPathHandler mixin provides ({"path": path, "type": type, "id": _id}).

This is already fixed on master — the same line now reads {...super.toMap(), 'directory': directory} — and the fix ships in the pre-release flutter_inappwebview_android 1.2.0-beta.3. But no stable release has been cut since 1.1.3 (2024-10-02), and flutter_inappwebview: ^6.1.5 depends on flutter_inappwebview_android: ^1.1.3, which pub does not resolve to a pre-release. So every project on the stable channel still gets the broken version.

Expected Behavior

InternalStoragePathHandler serves files from the app's internal storage through WebViewAssetLoader, as documented.

Steps with code example to reproduce

Steps with code example to reproduce
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:path_provider/path_provider.dart';

void main() => runApp(const MaterialApp(home: Repro()));

class Repro extends StatefulWidget {
  const Repro({super.key});
  @override
  State<Repro> createState() => _ReproState();
}

class _ReproState extends State<Repro> {
  Directory? _directory;

  @override
  void initState() {
    super.initState();
    getApplicationSupportDirectory().then((base) async {
      final directory = Directory('${base.path}/bundle')..createSync(recursive: true);
      File('${directory.path}/index.html').writeAsStringSync('<html><body>hello</body></html>');
      setState(() => _directory = directory);
    });
  }

  @override
  Widget build(BuildContext context) {
    final directory = _directory;
    if (directory == null) {
      return const Scaffold(body: Center(child: CircularProgressIndicator()));
    }
    return Scaffold(
      // Throws StackOverflowError while building, before any request is served.
      body: InAppWebView(
        initialUrlRequest: URLRequest(
          url: WebUri('https://appassets.androidplatform.net/index.html'),
        ),
        initialSettings: InAppWebViewSettings(
          webViewAssetLoader: WebViewAssetLoader(
            domain: 'appassets.androidplatform.net',
            pathHandlers: [
              InternalStoragePathHandler(path: '/', directory: directory.path),
            ],
          ),
        ),
      ),
    );
  }
}

Stacktrace/Logs

Stacktrace/Logs
The following StackOverflowError was thrown building InAppWebView(dirty, state: _InAppWebViewState#99182):
Stack Overflow

#0      AndroidInternalStoragePathHandler.toMap (package:flutter_inappwebview_android/src/webview_asset_loader.dart:196:3)
#1      AndroidInternalStoragePathHandler.toMap (package:flutter_inappwebview_android/src/webview_asset_loader.dart:198:16)
#2      AndroidInternalStoragePathHandler.toMap (package:flutter_inappwebview_android/src/webview_asset_loader.dart:198:16)
#3      AndroidInternalStoragePathHandler.toMap (package:flutter_inappwebview_android/src/webview_asset_loader.dart:198:16)
...
#113957 _drawFrame (dart:ui/hooks.dart:413:31)

Flutter version

3.47.0 (stable)

Operating System, Device-specific and/or Tool

Android 14 emulator (sdk_gphone64_arm64), host macOS 26.5.2.

Plugin version

flutter_inappwebview 6.1.5 → flutter_inappwebview_android 1.1.3

Additional information

Nothing needs to be written — the patch is already on master. What is missing is a stable release carrying it. Two things would help users today:

  1. Cutting a stable flutter_inappwebview_android release with the fix (or a 1.1.4 patch), so ^6.1.5 picks it up.
  2. Until then, documenting that InternalStoragePathHandler requires pinning the pre-release.

For anyone hitting this meanwhile: a CustomPathHandler subclass that reads the files itself is a working substitute on the stable channel, and it also lets you set the status code and MIME type yourself.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions