1

Within my app i av a section to search from network, I have used future and futureBuilder to display result but it happen that on a real device the outcome is not what is expected (Unknown result) but on emulator the block of code is working as expected.

Bellow is the code

      Expanded(
        child: Container(
          width: double.infinity,
          height: double.infinity,
          child: FutureBuilder<dynamic>(
            future: myHelper.fetchFromServer (params), //JSON from network
            builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
              List<Widget> children;
              if (snapshot.hasData) {
                var result = snapshot.data;
                if(result['type']=='success') {
                  List <Widget> list = new List();
                  List<dynamic> feedback = result['feedback'];
                  for(var i=0; i<feedback.length; i++){
                    var bus = feedback[i];
                    list.add(SharedBusCard (
                        name:bus['bus_name'],
                        rate:bus['bus_rate'],
                        seats:bus['bus_seats'],
                        onTap: () {
                          //When taped
                        }
                    ));
                    list.add(SizedBox(height: 15));
                  }
                  children = list;
                  return ListView(children: children);
                }
                else{
                  children = <Widget>[
                    Icon(
                      Icons.info_outline,
                      color: Colors.green,
                      size: 60,
                    ),
                    Padding(
                      padding: const EdgeInsets.only(top: 16),
                      child: Text('No result found'),
                    )
                  ];
                }
              } else if (snapshot.hasError) {
                children = <Widget>[
                  Icon(
                    Icons.error_outline,
                    color: Colors.red,
                    size: 60,
                  ),
                  Padding(
                    padding: const EdgeInsets.only(top: 16),
                    child: Text('There was an error, try again'),
                  )
                ];
              } else {
                children = <Widget>[
                  SizedBox(
                    child: CircularProgressIndicator(),
                    width: 60,
                    height: 60,
                  ),
                  const Padding(
                    padding: EdgeInsets.only(top: 16),
                    child: Text('Searching.....'),
                  )
                ];
              }

              return Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: children,
                ),
              );


            },
          ),
        ),
      ),

Output on phone

Error outcome

and the output on emulator

enter image description here

Please help me to sort this out, i don't know where am going wrong am fairly new to flutter. Thanks for your help.

James in code
  • 73
  • 1
  • 6
  • Does this answer your question? [Why can't a Flutter application connect to the Internet when installing "app-release.apk"? But it works normally in debug mode](https://stackoverflow.com/questions/55603979/why-cant-a-flutter-application-connect-to-the-internet-when-installing-app-rel) – Christopher Moore May 02 '21 at 20:14
  • No @ChristopherMoore i have internet permission in AndroidManifest.xml , Am able to retrieve all other data as necessary on the phone from the internet expect the result i av shown here. When i search for a file which doesnt exists on the server it's able to reply but when the result exists that's when am getting that faded blank card. I believe something is not right with the rendering. – James in code May 02 '21 at 20:23
  • No, it's not a rendering issue. The grey widget in release mode means there is an exception stemming from that widget. If you're absolutely sure it's not related to networking, create a minimal, reproducible example illustrating your issue. – Christopher Moore May 02 '21 at 20:25
  • @ChristopherMoore Alright "The grey widget in release mode means there is an exception stemming from that widget." thanks for that i didnt know. i sort the problem it was a casting error – James in code May 02 '21 at 23:59

1 Answers1

1

did you set internet permission? on debug mode you have internet permission on emulator but for phone you have to set internet permission for both android and iOS devices.

https://flutter.dev/docs/development/data-and-backend/networking