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

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

flutter - Waiting for getLinksSteam before continue

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)


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

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...