Dart 未处理异常:空值检查运算符用于空值,

时间:2021-07-19 08:57:15

标签: flutter flutter-dependencies flutter-sharedpreference

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;
}
 }

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

0 个答案:

没有答案