简体   繁体   中英

Future<int> to int in flutter, dart

I'm using flutter moor to store data in my flutter app. And I get data from the database and it returns a Future. I broke down the list to get a single value and now I have a Future. What I need to do is convert Future to int for comparing the value of Future with a static int value. Does anyone know how to do this? Thanks in advance.

A future is an object rapresenting a potential value (or an error) that could be available in the future. It is a common object if you are working with asyncronous programming.

Read here: https://api.flutter.dev/flutter/dart-async/Future-class.html

You could simply prepare a callback for when the value will be available by using:

Future<int> future = Future(foo);  // Result of foo() as a future.
future.then((int value) => bar(value))
      .catchError((e) => 499);

Or use await operator.

If you need to modify the graphics according to the result, you could use a FutureBuilder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM