Skip to content

Platform instance is cached at class load, blocking desktop and web #45

Description

@developerjamiu
// lib/src/smart_text_flutter.dart:9
static final _smartTextFlutter = SmartTextFlutterPlatform.instance;

This captures the platform instance once, at class load. Any later assignment to SmartTextFlutterPlatform.instance has no effect.

That defeats the override point plugin_platform_interface exists to provide, and it is why the plugin is awkward to fake in tests.

It also blocks desktop and web support. Flutter registers Dart-only platform implementations by calling a static registerWith() that assigns the instance, exactly as package_info_plus does:

static void registerWith() {
  PackageInfoPlatform.instance = PackageInfoPlusLinuxPlugin();
}

If _smartTextFlutter has already captured the default, that assignment does nothing and the Windows, Linux or web implementation is silently ignored.

Fix: read SmartTextFlutterPlatform.instance per call rather than caching it.

Found during the v0.4.0 codebase audit.

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

    bugSomething isn't workingplatform: dartAffects the shared Dart layer

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions