Issue with runtime type information

Viewed 32

I'm trying to get an rss feed (in xml) , with the function :

import 'dart:convert';
import 'dart:developer' as developer;
import 'package:flutter/material.dart';
import 'package:xml2json/xml2json.dart';
import 'package:http/http.dart' as http;

Future<List> rssToJson(String category, {String baseUrl = 'https://www.hindustantimes.com/feeds/rss/'}) async {
     var client = http.Client();
     final myTranformer = Xml2Json();
     var response = await client.get(Uri.parse(baseUrl + category +  '/rssfeed.xml'));
     myTranformer.parse(response.body);
     var json = myTranformer.toGData();
     var result = jsonDecode(json)['rss']['channel']['item'].toList();
     developer.log("result runtimeType: ${result.runtimeType}");
     return result;
}

I'm having 2 problems that i don't understand.

The 1st is the following error :

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

The second is when I want to get the runtime type like this: developer.log("result runtimeType: ${result.runtimeType}");

then I get 3 different types : List<dynamic,>, _InternalLinkedHashMap<String, dynamic> and null ,

which gives this in the console :

[log] result runtimeType: Null
[log] result runtimeType: _InternalLinkedHashMap<String, dynamic>
[log] result runtimeType: List<dynamic>
[log] result runtimeType: List<dynamic>
[log] result runtimeType: List<dynamic>
[log] result runtimeType: List<dynamic>
[log] result runtimeType: List<dynamic>
[log] result runtimeType: List<dynamic>
[log] result runtimeType: List<dynamic>
[log] result runtimeType: _InternalLinkedHashMap<String, dynamic>
[log] result runtimeType: List<dynamic>
0 Answers
Related