Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(package_info_plus): add support for file scheme on web #3345

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

alvarobcprado
Copy link
Contributor

Description

Web apps using file scheme cannot retrieve version.json, PackageInfoPlusWebPlugin.versionJsonUrl calls Uri.origin which throws StateError if scheme is not http or https

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

@miquelbeltran
Copy link
Member

Hey! thanks for the contribution.

Do you mean when calling fromPlatform with a file:// scheme, right? e.g. PackageInfo.fromPlatform(baseUrl: 'file://....')

@alvarobcprado
Copy link
Contributor Author

alvarobcprado commented Nov 7, 2024

Yes @miquelbeltran , when calling fromPlatform with a file:// scheme, a Bad state: Origin is only applicable to schemes http and https error is throwed from baseUri._origin inside the PackageInfoPlusWebPlugin.versionJsonUrl method.

   /// Get version.json full url.
  Uri versionJsonUrl(String baseUrl, int cacheBuster) {
    final baseUri = Uri.parse(baseUrl);
    final regExp = RegExp(r'[^/]+\.html.*');
    final String originPath =
        '${baseUri._origin}${baseUri.path.replaceAll(regExp, '')}';

...

extension _UriOrigin on Uri {
  /// Get origin.
  ///
  /// This is different from [Uri.origin] because that has checks to prevent
  /// non-http/https use-cases.
  String get _origin {
    if (isScheme('chrome-extension')) {
      return '$scheme://$host';
    }
    return origin;
  }
}

@miquelbeltran
Copy link
Member

Got it! thanks for the clarification

@miquelbeltran miquelbeltran merged commit 2d69758 into fluttercommunity:main Nov 7, 2024
19 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants