body: FutureBuilder(
future: determinePosition(),
builder: (context, snapshot) //error here{
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text("Error ");
}else if(snapshot.hasData){
return Column(
children: [
Text(currentAddress),
The body might complete normally, causing ‘null’ to be returned, but the return type, ‘Widget’, is a potentially non-nullable type. why it is wrong ? help me
2
Answers
The potential solution is remove last else if (which is snapshot.hasData) and directly return the the column same as below
The problem is that you’re using
else if
instead ofelse
. By using else if, you’re telling Dart to follow this set of conditions, but what if there’sanother
condition? that won’t be handled, and will returnnull
.To fix the issue, use
else
instead of else if in the last clause: