skip to Main Content
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'int' is not a subtype of type 'double'
E/flutter (27556): #0      new Rating.fromJson (package:flutter_fake_api/model/model.dart:52:17)
E/flutter (27556): #1      ProductService.fetchProducts.<anonymous closure> (package:flutter_fake_api/services/service.dart:25:24)
E/flutter (27556): #2      MappedListIterable.elementAt (dart:_internal/iterable.dart:425:31)
E/flutter (27556): #3      ListIterator.moveNext (dart:_internal/iterable.dart:354:26)
E/flutter (27556): #4      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
E/flutter (27556): #5      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
E/flutter (27556): #6      new List.of (dart:core-patch/array_patch.dart:39:18)
E/flutter (27556): #7      ListIterable.toList (dart:_internal/iterable.dart:224:7)
E/flutter (27556): #8      ProductService.fetchProducts (package:flutter_fake_api/services/service.dart:27:8)
E/flutter (27556): <asynchronous suspension>

output should be in container which contain title, image, price category, description ,rating
when call from api

2

Answers


  1. Chosen as BEST ANSWER
    I use this  
    final List<Products> products = productsJson.map((productJson) => 
    Products.fromJson(productJson)).toList();   
    insteed of 
    return Products(
          id: e["id"],
          title: e["title"],
          price: e["price"],
          description: e["description"],
          category: e["category"],
          image: e["image"],
          rating: Rating.fromJson(e["rating"]),
        );
      }).toList();
    and error gone
    

  2. Your Rating class like this :

    Rating{
    final double xyz;
    }
    

    Change Rating class like this :
    double to int

     Rating{
    final int xyz;
    }
    

    if this is not working then check api response and parameters datatype.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search