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

Convert Future<int> to int in Flutter #23084

Closed
marj29 opened this issue Oct 15, 2018 · 6 comments
Closed

Convert Future<int> to int in Flutter #23084

marj29 opened this issue Oct 15, 2018 · 6 comments

Comments

@marj29
Copy link

marj29 commented Oct 15, 2018

How to convert Future int to int in flutter?

Example: I have a function that return a Future int and I want to compare if the return output is greater than or equal to zero.

Thanks in advance

@tomkowz
Copy link

tomkowz commented Oct 15, 2018

@marj29 in order to get value out of the Future you have to use async/await.

import 'dart:async';

class A {
  Future<int> getInt() {
    return Future.value(10);
  }
}

class B {
  checkValue() async {
    final val = await A().getInt();
    print(val == 10 ? "yes" : "no");
  }
}

You can find more on that in the dart lang tutorials.

@zoechi
Copy link
Contributor

zoechi commented Oct 15, 2018

Please consider asking support questions in one of the other channels listed at http://flutter.io/support .

@zoechi zoechi closed this as completed Oct 15, 2018
@marj29
Copy link
Author

marj29 commented Oct 15, 2018

@tomkowz thank you so much for your response

@langaro
Copy link

langaro commented Jun 20, 2019

@tomkowz Thank you. Just what I need.

@hekmatnajafi
Copy link

hekmatnajafi commented Apr 3, 2020

Late but might be useful for others.

suppose you have a function called getCount() that returna a Future value.
simply do this:
int count = await getCount();
now you can use count variable any where needed.

@lock
Copy link

lock bot commented Apr 19, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock bot locked and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants