2

I am fetching data from api and just printing the snapshot data in Futurebuilder widget but its showing me this error

type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'FutureOr<List<dynamic>>'

This is how i am calling API

 Future<List> dosomestuff() async {

      http.Response res = await http.get(
        'http://api-uat.thelunchbox-restaurant.com/api/orders/admin/4',
      );
      var data = json.decode(res.body);
      print(data);
      print(data["Orders"]);
      return data;
  }

MY future builder code

FutureBuilder(
                      future: dosomestuff(),
                      builder: (BuildContext context, AsyncSnapshot<List> snapshot) {
                        if (snapshot.connectionState == ConnectionState.done) {
                          if (snapshot.hasData) {
                            print('working');
                            print(snapshot);
                            return Center(
                              child: Text("done ...!!"),
                            );
                          }
                        }
                        return Center(
                          child: Text("Loading ...!!"),
                        );
                      })

its printing data in Future function like this

I/flutter (16288): {Orders: [{OrderID: 208, CustomerID: 2, TransactionNo: 80, OrderNo: 1, OrderType: 1, OrderDate: 2020-10-28T13:13:44.99, OrderPreparedDate: null, OrderOFDDate: null, OrderDoneDate: null, StatusID: 101, SessionID: POS-KXCBSH636794256705513894, OrderTakerID: null, DeliverUserID: null, LastUpdateBy: 2, LastUpdateDT: 2020-10-28T13:13:44.99, LocationID: 4, BrandID: 1, BrandName: The LunchBox, BrandLogo: http://dashboard-uat.thelunchbox-restaurant.com/assets/Upload/Brand/b8642f71-685a-4ff3-9045-abcbc5cd01ea.jpg, Remarks: null, OrderCheckouts: {OrderCheckoutID: 207, OrderID: 208, PaymentMode: 1, AmountPaid: 17.3, AmountTotal: 17.3, ServiceCharges: 0.0, GrandTotal: 2.0, Tax: 0.3, CheckoutDate: 2020-10-28T13:13:42.96, SessionID: null, StatusID: 101, LastUpdateBy: null, LastUpdatedDate: null}, CustomerOrders: {CustomerOrderID: 205, Name: null, Email: [email protected], Mobile: 0544916463, Description: , Address: Paris, France, Longitude: 46.6753, Latitude: 24.7136, LocationURL: null, StatusID: 1, LastUpdatedBy: 2, LastUpd

And its not showing full i think this is showing in a string or something. How can i fix the error in futurebuilder?

1 Answer 1

1

Issue is your data is still in String format not in List and in Future Widget its define as a list. So you need to convert your API response in a list. As you show your data print you can do like this

  Future<List> dosomestuff() async {

      http.Response res = await http.get(
        'http://api-uat.thelunchbox-restaurant.com/api/orders/admin/4',
      );

      Map<String, dynamic> map = json.decode(res.body);
      List<dynamic> data = map["Orders"];
      print(data);
      return data;
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.