'MissingPluginException(No implementation found for method share on channel plugins.flutter.io/share)

i found error when i use flutter_share: ^1.0.2+1

    MissingPluginException(No implementation found for method share on channel plugins.flutter.io/share)


   E/flutter ( 3361): MissingPluginException(No implementation found for method share on channel plugins.flutter.io/share)
E/flutter ( 3361): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:278:7)
E/flutter ( 3361): <asynchronous suspension>
E/flutter ( 3361): #1      Share.share (package:share/share.dart:44:20)
E/flutter ( 3361): #2      SignalCard.build.<anonymous closure> 


Solution 1:[1]

The share plugin works as intended. The error probably appears because the addition of the plugin was followed by hot restart or hot reload rather than full restart. This means the plugin's platform-specific code is not built into the app.

Work around: stop the app and restart it after adding a plugin.

source: https://github.com/flutter/website/pull/1038

Solution 2:[2]

If you use share plugin in web project, this error will appear permanently. As write here, you must use share_plus plugin

But this plugin (share_plus), can't share files

  /// Share files
  @override
  Future<void> shareFiles(
    List<String> paths, {
    List<String>? mimeTypes,
    String? subject,
    String? text,
    Rect? sharePositionOrigin,
  }) {
    throw UnimplementedError('shareFiles() has not been implemented on Web.');
  }

And share message (text + subject) only by mail

  // see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
  final uri = Uri(
    scheme: 'mailto',
    query: queryParameters.entries
        .map((e) =>
            '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
        .join('&'),
  );

Solution 3:[3]

When you add a plugin to your app which contains native code you have to restart the app in order to be loaded. So hot restart etc. is not enough.

Solution 4:[4]

NOTE: flutter_share and share packages have discontinued.

Now I am using official share_plus plugin, you can find it at

https://pub.dev/packages/share_plus

I hope, this will solve your issue. Thanks.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jessica
Solution 2
Solution 3 Bauroziq
Solution 4 Kamlesh