简体   繁体   中英

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

I am trying to set the response in the _dataFromAPI but it show exception: InternalLinkedHashMap<String, dynamic> is not a subtype of type List<dynamic

class _CryptoCurrencyScreenState extends State<CryptoCurrencyScreen> {
    
      var _dataFromAPI;
      var list;
      var refreshKey = GlobalKey<RefreshIndicatorState>();
    
      Future<List<Data>> getCurrencies() async {
        var url =
            Uri.parse("https://pro-api.coinmarketcap.com/v1/cryptocurrency/map");
        final response = await http.get(url);
        if (response.statusCode == 200) {
            List _dataFromAPI = json.decode(response.body);
            return _dataFromAPI.map((data) => new Data.fromJson(data)).toList();
          }
        }
      
      @override
      void initState() {
        super.initState();
        refreshListData();
      }
    
      Future<Null> refreshListData() async {
        refreshKey.currentState?.show(atTop: false);
        setState(() {
          list = getCurrencies();
        });
        return null;
      }
    }

How could I fix it?

Replace List with List<String, dynamic> , like this: List<String, dynamic> _dataFromAPI = json.decode(response.body);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM