Is there any difference between just returning a value and by using Future.value(); in Dart?

Viewed 87

For example, is there any difference between those two code snippets? In dartpad, they return the same thing at the same time.

Does the function itself infer the returning value as bool from the function declaration (Future<bool>) so that using just 'return' is okay or is there any specific situation that make difference?

A:

Future<bool> anyFunction() async {
 print('start');
 var temp = Future.delayed(Duration(seconds: 5));
 bool result = await getSomeResult();
 print('end');

 return result;
}

B:

Future<bool> anyFunction() async {
 print('start');
 var temp = Future.delayed(Duration(seconds: 5));
 bool result = await getSomeResult();
 print('end');

 return Future<bool>.value(result);
}
0 Answers
Related