Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter Unhandled Exception:type'_InternalLinkedHashMap<String,dynamic>' is not a subtype of type 'List<dynamic>'

im tryin to display data from json api inside my flutter app ,
My Error :

E/flutter ( 2248): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>'

My Method:

Future<void> _fetchDataAkhbarGbeli() async {
    const apiUrl = 'data screen below';
    HttpClient client = HttpClient();
    client.autoUncompress = true;
        final HttpClientRequest request = await client.getUrl(Uri.parse(apiUrl));
    request.headers
        .set(HttpHeaders.contentTypeHeader, "application/json; charset=UTF-8");
    final HttpClientResponse response = await request.close();
        final String content = await response.transform(utf8.decoder).join();
    final List data = json.decode(content);
        setState(() {
      _loadedAkhbarGbeli = data as List;
    });
  }

View:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 Expanded(
                child:ListView.builder(
                  scrollDirection: Axis.vertical,
                  itemCount: _loadedAkhbarGbeli.length,
                  itemBuilder:(BuildContext ctx, index) {
                      return ListTile(
                        title: Text(_loadedAkhbarGbeli[index]["gbeli"]["title"]),
                      );
                    },
                    )
                )

screen

how can i solve this problem, Thanks

>Solution :

The content is actually a map. You can get list directly like

 final List? data = json.decode(content)["gbeli"] as List?;

Now on use case it will

Text("${_loadedAkhbarGbeli[index]["title"]}")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading