skip to Main Content
  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


  1. The potential solution is remove last else if (which is snapshot.hasData) and directly return the the column same as below

      body: FutureBuilder(
      future: determinePosition(),
      builder: (context, snapshot) //error here{
      if (snapshot.connectionState == ConnectionState.waiting) {
      return CircularProgressIndicator();
      } else if (snapshot.hasError) {
      return Text("Error ");
      }
    return Column(
    children: [
    Text(currentAddress),
    
    Login or Signup to reply.
  2. The problem is that you’re using else if instead of else. By using else if, you’re telling Dart to follow this set of conditions, but what if there’s another condition? that won’t be handled, and will return null.

    To fix the issue, use else instead of else if in the last clause:

    FutureBuilder(
                future: determinePosition(),
                builder: (context, snapshot) {
                  if (snapshot.connectionState == ConnectionState.waiting) {
                    return CircularProgressIndicator();
                  } else if (snapshot.hasError) {
                    return Text("Error ");
                  } else {
                    return Column(
                      children: [
                        Text('test'),
                      ],
                    );
                  }
                })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search