0

Begins an asynchronous calls the function and multiple.

However, the response to the second call is always null.

I want to update it to the screen when I get all the results.

sometimes invoked Error msg like this :

type 'List' is not a subtype of type 'Map<dynamic, dynamic>'

class _HomePageState extends State<Home> {
  final _formKey = GlobalKey<FormState>();
  final _formKey2 = GlobalKey<FormState>();
  aboutRes about; // delete

  var _callStack = [Gateway.Instance.about(), Wifi.Instance.ssidInfo(0)];

   @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body : Padding(
        padding: const EdgeInsets.all(15.0),
        child: Column(children: [
          Expanded(
            child: FutureBuilder(
              future : Future.wait(_callStack),
              key : _formKey,
              builder: (context, snapshot) {
                if (snapshot.hasError) {
                  return Text('Invoked Error is ${snapshot.error}');

                } else if (snapshot.hasData) {
                  return ListView (
                    padding: const EdgeInsets.all(0.8),
                    children: [
                      Container(
                        child : Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            InformationItem(about: snapshot.data[0]),
                            WirelessItem(ssid: snapshot.data[1]),
                          ],
                        ),
                      )
                    ]
                  );
                } else {
                  return CircularProgressIndicator();
                }
              }
            )
          ),
        ]),
      )
    );
  }
}
  Future<aboutRes> about() async {
    aboutRes res;

    ApiResponse response = await get(GATEWAY_ABOUT);
    // for jsonSerialization
    Map resMap = jsonDecode(response.body);
    res = aboutRes.fromJson(resMap);
    return res;
  }
hello_ey
  • 11
  • 1
  • In what line the "type 'List' is not a subtype of type 'Map'" exception occurs? – enzo May 07 '21 at 05:15
  • Here : Text('Invoked Error is ${snapshot.error}'); I modified the code a little bit and the above error did not occur, but the response value for the second request was null. – hello_ey May 07 '21 at 05:55
  • That's because if `response.body` is `"[1, 2, 3]"` for example, it will return a `List`, not a `Map`. You can either (1) change `Map` to `List` or (2) check the type of `response.body`. – enzo May 07 '21 at 06:00

0 Answers0