I am working with Android Studio and Flutter . When using await or async I get the following error:
error: The function 'await' isn't defined. (undefined_function at [support] lib\main.dart:6)
I did some research and tried using async , since I saw that it was used everywhere, I thought that would solve the problem but it didn't.
The small piece of code where the error occurs is as follows:
import 'package:flutter/material.dart';
import 'package:connectivity/connectivity.dart';
import 'package:async/async.dart';
var wifiBSSID = await (Connectivity().getWifiBSSID());
var wifiIP = await (Connectivity().getWifiIP());
var wifiName = await (Connectivity().getWifiName());
and my pubspec.yaml file (dependencies):
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
connectivity: ^0.4.8+2
path: ^1.6.4
async: ^2.3.1
What dependency should I import or what should I do to be able to use async or await .
You have to use the
await
within methods, you can't use it as variables, it would look like this:And you can call the method
conectar()
inside theinitState
eg.