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

getInitialSharedMedia don't works #73

Open
Reymai opened this issue Oct 27, 2023 · 3 comments
Open

getInitialSharedMedia don't works #73

Reymai opened this issue Oct 27, 2023 · 3 comments

Comments

@Reymai
Copy link

Reymai commented Oct 27, 2023

Hi!
In my code didn't work getInitialSharedMedia function. I can get shared media by the sharedMediaStream, but initial shared media I can't get.

share handler:

import 'dart:async';
import 'dart:developer';

import 'package:share_handler/share_handler.dart';

abstract class IShareToHandler {
  Future<void> initPlatformState();
  SharedMedia? get sharedMedia;
  Stream<SharedMedia> get sharedMediaStream;
}

class ShareToHandler implements IShareToHandler {
  SharedMedia? _sharedMedia;
  final StreamController<SharedMedia> _sharedMediaStreamController =
      StreamController();

  ShareToHandler() {
    initPlatformState();
  }

  @override
  Future<void> initPlatformState() async {
    final handler = ShareHandlerPlatform.instance;
    _sharedMedia = await handler.getInitialSharedMedia();

    handler.sharedMediaStream.listen((SharedMedia media) {
      log('Shared media: ${media.toString()}');
      _sharedMedia = media;
      _sharedMediaStreamController.add(media);
    });
  }

  @override
  SharedMedia? get sharedMedia => _sharedMedia;
  @override
  Stream<SharedMedia> get sharedMediaStream =>
      _sharedMediaStreamController.stream.asBroadcastStream();
}

main:

final getIt = GetIt.I;

Future<void> singletonRegister() async {
  getIt.registerSingleton<IShareToHandler>(ShareToHandler());
  // ...
}

Future<void> bootstrap() async {
  WidgetsFlutterBinding.ensureInitialized();
  // ...
  singletonRegister();
  getIt.get<IShareToHandler>().initPlatformState();
}

void main() async {
  await bootstrap();
  runApp(
    MainApp(),
  );
}

flutter doctor:

[✓] Flutter (Channel stable, 3.13.6, on macOS 14.0 23A344 darwin-arm64, locale en-LV)
    • Flutter version 3.13.6 on channel stable at /Users/raimondsmakars/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ead455963c (4 weeks ago), 2023-09-26 18:28:17 -0700
    • Engine revision a794cf2681
    • Dart version 3.1.3
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/raimondsmakars/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Users/raimondsmakars/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/raimondsmakars/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.4)
    • IntelliJ at /Users/raimondsmakars/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 232.10072.19

[✓] VS Code (version 1.83.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.74.0

[✓] VS Code (version 1.84.0-insider)
    • VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
    • Flutter extension version 3.74.0

[✓] Connected device (3 available)
    • Pixel 6 (mobile) • 26211FDF60055U • android-arm64  • Android 14 (API 34)
    • macOS (desktop)  • macos          • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
    • Chrome (web)     • chrome         • web-javascript • Google Chrome 118.0.5993.117

[✓] Network resources
    • All expected network resources are available.

• No issues found!

@tmratwork
Copy link

I am running the example code, cannot get app working in iOS. it builds, but the event handler does not get called. share_handler: ^0.0.19

@Reymai
Copy link
Author

Reymai commented Nov 1, 2023

I am running the example code, cannot get app working in iOS. it builds, but the event handler does not get called. share_handler: ^0.0.19

You mean initPlatformState? It calls in main in bootstrap function.
In initPlatformState calls getInitialSharedMedia too, but it's return null. It's return null when start application on "cold" without sharing, when start application on "cold" by sharing something to app, and, obviously, null, when share something in app, when app already is running

@tmratwork
Copy link

I re-installed the plugin to get more information before replying, and now it works as expected. only thing I did different was use default instead of custom group id.

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

No branches or pull requests

2 participants