Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

my problem is that my app won't wait for getLinksStream to be ready. In my case i want to login with OAuth2 and i need the responses after logging in. I'm trying to get these responses with the command getUriLinksStream() after the Browser is closed because i need the responses as an Uri. After pressing the button for the first time it shows null and after pressing the button once more it gives a result.

My Code:

    await redirect(authorizationUrl.toString());
    WidgetsBinding.instance.addObserver(APIService());

  }

  Future<Null> didChangeAppLifecycleState(AppLifecycleState state) async {
    switch (state) {
      case AppLifecycleState.resumed:
        await listen(redirectUrl.toString());
        print(responseUrl);
        break;
      case AppLifecycleState.inactive:
      case AppLifecycleState.paused:
      case AppLifecycleState.detached:
    }
  }
  Future<void> redirect(String authorizationUrl) async {
    if (await canLaunch(authorizationUrl)) {
      await launch(authorizationUrl);
    }
  }

  Future<void> listen(String redirectUrl) async {
    await getUriLinksStream().listen((Uri uri) async {
      if (uri.toString().startsWith(redirectUrl)) {
        responseUrl = uri;
      }
    });
  }

Can somone help me here? (And sorry for my english. Its not my main language)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
245 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...