Home > OS >  Flutter error occurred when adding some JSON files from "Random User"
Flutter error occurred when adding some JSON files from "Random User"

Time:11-18

I tried to excute this code in my android mobile. it has not any error. when app start show "waiting" massage, after that body only displayed "true".

      **body: FutureBuilder(
        future: getUser(),
        builder: (BuildContext context,AsyncSnapshot snapshot) {
          if(snapshot.connectionState == ConnectionState.waiting){
            return const Center(
              **child: Text('waiting')**,
            );
          }else{
            if(snapshot.hasError){
              return Text(snapshot.hasError.toString());
            }else{
              return ListView.builder(
                itemCount: snapshot.data.length,
                itemBuilder: (BuildContext context,int index){
                  return ListTile(
                    leading: CircleAvatar(
                      backgroundImage: NetworkImage(snapshot.data[index].avatar),
                    ),
                    title: Text(snapshot.data[index].name),
                    subtitle: Text(snapshot.data[index].email),
                    onTap: (){},**


i want to show user information getting from the 'https://randomuser.me/api/?results=20' this json file.

CodePudding user response:

There is an error in the code. So that's why it is "true". if you hover over " hasError " you will see the data type is boolean. so when you wrote

if(snapshot.hasError){
          return Text(snapshot.hasError.toString());

by " tostring " you just presnted the error in string form. so.

  • Related