Search code examples
androidflutterdartvisual-studio-codesnapshot

i get this error when i try to use Future builder and snapshot even the Json File is ok


future builder not work and receive null value even I test my PHP file and everything is ok

the value return null I don not know why that I test The Function getnote() also it give me "fail"


Solution

  • Almost surely the first snapshot will contain do data because the future is still running. Check if the snapshot has data, and also check for errors:

    builder: (context, snapshot) {
      if (snapshot.hasData) {
        // now you can be sure that snapshot.data is not null
      } else if (snapshot.hasError) {
        // manage errors
      }
      // otherwise show a progress indicator while the future is running
      return const Center(child: CircularProgressIndicator());
    }