0
String? videoId;
String? sharedText;
String? realLink;

void initState() {
super.initState();
WidgetsBinding.instance!.addObserver(this);

intentReceiver(sharedText, videoId, realLink);
}

Future<String?> intentReceiver(
  String? _sharedText, String? videoId, String? realLink) async {
if (_sharedText != null) {
  videoId = YoutubePlayer.convertUrlToId(_sharedText)!;
  setState(() {
    realLink = videoId;
    print('realLink $realLink');
  });
}
return realLink;
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
 super.didChangeDependencies();
if (state == AppLifecycleState.inactive ||
    state == AppLifecycleState.detached) return;
final isBackground = state == AppLifecycleState.paused;
print('isBackground $isBackground');
if (isBackground) {
  ReceiveSharingIntent.getTextStream().listen((String? value) {
    setState(() {
      sharedText = value!;
      print("Shared ram: $sharedText");
    });
  }, onError: (err) {
    print("getLinkStream error: $err");
  });
} else {
  print(isBackground);
  sharedText = null;
}
 }

我得到一个用于空值的空检查运算符。我的任务只是等待接收来自另一个应用程序的文本。我想我使用异步或未来,但我不知道如何在这里使用它。

4

0 回答 0