I know how the dart future,async and await works. To await a invoking function it must be of type Future else await wont work. I will show two code snippets which produces the same output. I think the second code snippet doesn't need to be of the type Future i think its redundant to add it to the main function. In dart documentation also Future is used in main function.

Code snippet 1

 import 'dart:async';

import 'package:http/http.dart';
void main() async {
  final result = await getPost();
  print(result.body);
}

Future<Response> getPost() async {
  final parsedUrl = Uri.parse("https://jsonplaceholder.typicode.com/posts/1");
  final result = Client().get(parsedUrl);
  return result;
}

code snippet 2

import 'dart:async';

import 'package:http/http.dart';
Future<void> main() async {
  final result = await getPost();
  print(result.body);
}

Future<Response> getPost() async {
  final parsedUrl = Uri.parse("https://jsonplaceholder.typicode.com/posts/1");
  final result = Client().get(parsedUrl);
  return result;
}


Solution 1: casraf

That's because void means the output is not expected to be returned. It wouldn't matter if you return nothing now or later in the Future, as it will never matter anyway.

If you had wanted to return a value, like you did in getPost, you would have to mark it as Future - else it won't work.

void main() async {
  final result = await getPost();
  print(result.body);
}

// will not work
Response getPost() async {
  final parsedUrl = Uri.parse("https://jsonplaceholder.typicode.com/posts/1");
  final result = Client().get(parsedUrl);
  return result;
}