I have made a helper function which is a task to fetch data from the server and return it as a promise-based response. Btw. I am a Flutter newbie :)
Helper function:
import 'dart:convert';
import 'package:http/http.dart' as http;
class FetchModules {
void fetchAllModules() async {
var url = Uri.parse('https://jsonplaceholder.typicode.com/todos/');
var response = await http.get(url);
if (response.statusCode == 200) {
String data = response.body;
var decodedData = jsonDecode(data);
return decodedData;
}
}
}
Widget where I want to get a response:
void initState() {
super.initState();
FetchModules().fetchAllModules().then((){});
}
VSCode Error:
This expression has a type of 'void' so its value can't be used.
Try checking to see if you're using the correct API;
there might be a function or call that returns void you didn't expect.
Also check type parameters and variables which might also be void.dart(use_of_void_result)
So, how to fix this?
Thanks!