Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index' Problem Dart & flutter - flutter

I have this variables problem
this is my getdata function
Future <List <Deal>> getData() async{
String myUrl = "http://10.25.20.27:5000/api/all";
var response = await http.get(myUrl,
headers: {
'Accept':'application/json',
});
var jsonData = json.decode(response.body);
List<Deal> deals =[];
var u;
for( u in jsonData){
Deal deal = Deal(u["id"],u["name"],u["adress"],u["photo"],u["Description"],u["discount"]);
}
return deals;
}
And I got this error
Performing hot reload...
Reloaded 14 of 594 libraries in 902ms.
E/flutter ( 4211): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
E/flutter ( 4211): #0 DatabaseHelper.getData (package:flutter_app/databasehelper.dart:116:25)
E/flutter ( 4211):
E/flutter ( 4211): #1 _HomeePageState.build. (package:flutter_app/homee_page.dart:100:80)
E/flutter ( 4211): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
E/flutter ( 4211): #3 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:729:32)
E/flutter ( 4211): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 4211): #5 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter ( 4211): #6 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
E/flutter ( 4211): #7 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)

I think you can create "Deal" class like below:-
class Deal {
String id;
String name;
String adress;
String photo;
String Description;
String discount;
Deal(
this.id,
this.name,
this.adress,
this.photo,
this.Description,
this.discount,
);
}
Then you can use loop like below :-
var u;
for (u in jsonData) {
Deal deal = Deal(
u["id"].toString(),
u["name"].toString(),
u["adress"].toString(),
u["photo"].toString(),
u["Description"].toString(),
u["discount"].toString());
}

Related

Unsupported operation: Cannot modify an unmodifiable list

I need help.
I'm trying to extract files from an archive.
var byteData = await rootBundle.load('assets/res.zip');
var buffer = byteData.buffer;
var archive = ZipDecoder().decodeBytes(buffer.asUint8List(),
verify: true, password: '123');
for (final file in archive) {
final filename = file.name;
if (file.isFile) {
final data = file.content as List<int>;
File('$tempPath/files/$filename')
..createSync(recursive: true)
..writeAsBytesSync(data);
} else {
Directory('$tempPath/files/$filename').create(recursive: true);
}
}
But I'm getting this error..................
E/flutter ( 8813): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Unsupported operation: Cannot modify an unmodifiable list
E/flutter ( 8813): #0 _UnmodifiableUint8ArrayView.[]= (dart:typed_data-patch/typed_data_patch.dart:5391:5)
E/flutter ( 8813): #1 ZipFile._decodeZipCrypto (package:archive/src/zip/zip_file.dart:192:12)
E/flutter ( 8813): #2 ZipFile.content (package:archive/src/zip/zip_file.dart:129:27)
E/flutter ( 8813): #3 ZipDecoder.decodeBuffer (package:archive/src/zip_decoder.dart:32:41)
E/flutter ( 8813): #4 ZipDecoder.decodeBytes (package:archive/src/zip_decoder.dart:16:12)
E/flutter ( 8813): #5 _HomePageState.dataWriteToLocal (package:mytest/Pages/home_page.dart:417:36)
E/flutter ( 8813): <asynchronous suspension>

Unhandled Exception: NoSuchMethodError: The method '[]' was called on null. - Flutter

This is the error I get when request data from api -
Performing hot restart...
Syncing files to device sdk gphone x86 64 arm64...
Restarted application in 777ms.
E/flutter (21101): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
E/flutter (21101): Receiver: null
E/flutter (21101): Tried calling:
E/flutter (21101): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
E/flutter (21101): #1 new Recipe.fromJson (package:food_recipe_app_1/models/recipe.dart:16:19)
E/flutter (21101): #2 Recipe.recipesFromSnapshot. (package:food_recipe_app_1/models/recipe.dart:25:21)
E/flutter (21101): #3 MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
E/flutter (21101): #4 ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
E/flutter (21101): #5 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
E/flutter (21101): #6 new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
E/flutter (21101): #7 new List.of (dart:core-patch/array_patch.dart:51:28)
E/flutter (21101): #8 ListIterable.toList (dart:_internal/iterable.dart:213:44)
E/flutter (21101): #9 Recipe.recipesFromSnapshot (package:food_recipe_app_1/models/recipe.dart:26:8)
E/flutter (21101): #10 RecipeApi.getRecipe (package:food_recipe_app_1/models/recipe.api.dart:26:19)
E/flutter (21101):
E/flutter (21101): #11 _HomePageState.getRecipes (package:food_recipe_app_1/views/home.dart:25:16)
E/flutter (21101):
E/flutter (21101):
class Recipe {
final String name;
final String images;
final double rating;
final String totalTime;
Recipe({
this.name,
this.images,
this.rating,
this.totalTime,
});
factory Recipe.fromJson(dynamic json) {
return Recipe(
name: json['name'] as String,
images: json['images'][0]['hostedLargeUrl'] as String,
rating: json['rating'] as double,
totalTime: json['totalTime'] as String
);
}
static List<Recipe> recipesFromSnapshot(List snapshot) {
return snapshot.map((data) {
return Recipe.fromJson(data);
}).toList();
}
#override
String toString() {
return 'Recipe {name: $name, image: $images, rating: $rating, totalTime: $totalTime}';
}
}
Either json is null, or json['images'] returns null. There are other ways to do it, here is one option if you don't want to allow null values:
factory Recipe.fromJson(dynamic json) {
if (json == null) return Recipe.empty();
return Recipe(
name: json['name'] ?? '',
images: json['images']?[0]['hostedLargeUrl'] ?? '',
rating: json['rating'] ?? 0,
totalTime: json['totalTime'] ?? ''
);
}
factory Recipe.empty() => Recipe(name: '', images: '', rating: '', totalTime: '');
You haven't included enough code to be sure of where your error is exactly, but here is an example of what is happening so you can find it:
List<String>? _list;
right now _list is null.
If I call String _string = _list[0];
I will get the error you are experiencing. So your list is null somewhere.

Flutter Api call Unhandled Exception

i have a problem with api call,
in the project i have another call and it work, this call doesn't work in any way
// file meteo.dart
class Meteo {
int id;
double temperatura;
String name;
Meteo(this.id, this.temperatura, this.name);
Meteo.fromMap(Map<String, dynamic> mappa){
this.id = mappa['id'];
this.temperatura = mappa['main']['temp'];
this.name = mappa['name'].toString();
}
}
This is the model of the response
Future ferentinoGet() async {
var dio = Dio();
Response response = await
dio.get('https://api.openweathermap.org/data/2.5/weather?q=ferentino&appid=****************');
final resJson = response.data;
datiFerentino = resJson
.map<Meteo>((mappa) => Meteo.fromMap(mappa))
.toList();
print(response.data);
}
This is the api call
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'map' with matching arguments.
Receiver: _LinkedHashMap len:13
Tried calling: map<Meteo>(Closure: (dynamic) => Meteo)
Found: map<K2, V2>((K, V) => MapEntry<K2, V2>) => Map<K2, V2>
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _HomeScreenState.ferentinoGet (package:ferentino/main.dart:223:10)
<asynchronous suspension>
#2 _HomeScreenState.initState (package:ferentino/main.dart:43:5)
#3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4765:58)
#4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
#5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
#6 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
#7 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14)
#8 Element.<…>
this is the error.
Can you help me?
Thank you
I think you process your JSON response as a List but it looks resJson is a Map. But map method for Map has different prototype.

SQFLite (Flutter) Insert fails for Map containing Maps

Can someone confirm if SQFLite supports maps containing maps? I did run across the following post on this site and possibly this is the answer?
Flutter sqflite insert List<String>
In my situation, I have a two model classes I am working with.
House
Dog
House includes a field called pets which is a List
I have a constructor and factory method in each of these classes which takes care of converting to/from map/object as needed for sending to and retrieving information from SQFLite.
Model classes
Dog
class Dog {
final int id;
final String breed;
final String name;
final int age;
Dog({this.id, this.breed, this.name, this.age});
// Used when inserting a row into the db, including the id field
Map<String, dynamic> toMap() {
final map = Map<String, dynamic>();
map['id'] = id;
map['breed'] = breed;
map['name'] = name;
map['age'] = age;
return map;
}
// Used when returning a row from the DB and converting into an object
factory Dog.fromMap(Map<String, dynamic> data) => Dog(
id: data['id'],
breed: data['breed'],
name: data['name'],
age: data['age']
);
}
House
import 'dog.dart';
class House{
final int id;
final String name;
final String color;
final List<Dog> pets;
House({this.id, this.name, this.color, this.pets});
// Will be used when inserting a row into the database
Map<String, dynamic> toMap() {
final map = Map<String, dynamic>();
map['id'] = id;
map['name'] = name;
map['color'] = color;
if (this.pets != null) {
map['pets'] = this.pets.map((pet) => pet.toMap()).toList();
}
return map;
}
// Used when returning a row from the DB and converting into an object
factory House.fromMap(Map<String, dynamic> data) {
return House(
id: data['id'],
name: data['name'],
color: data['color'],
pets: data['pets'] != null
? (data['pets'] as List).map((pet) => Dog.fromMap(pet)).toList()
: null,
);
}
}
Method for inserting a new house
Future<int> addNewHome(House house) async {
// Attempt to add the house to the DB
var client = await database.db;
int result = await client.insert(HomesSchema.tblHomes, house.toMap(), conflictAlgorithm: ConflictAlgorithm.replace);
_homes.add(house);
return result;
}
When I attempt to perform the insert, I get the following error.
E/flutter ( 586): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: DatabaseException(java.util.HashMap cannot be cast to java.lang.Integer) sql 'INSERT OR REPLACE INTO homes (id, name, color, pets) VALUES (?, ?, ?, ?)' args [1, Smith, Green, [{name: Mackie, id: 1, breed: Rottweiler, age: 8}, {name: Tanner, id: 2, breed: Mastiff, age: 8}]]}
E/flutter ( 586): #0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:12:7)
E/flutter ( 586): <asynchronous suspension>
E/flutter ( 586): #1 SqfliteDatabaseFactoryImpl.wrapDatabaseException (package:sqflite/src/factory_impl.dart:25:7)
E/flutter ( 586): #2 SqfliteDatabaseMixin.safeInvokeMethod (package:sqflite/src/database_mixin.dart:188:15)
E/flutter ( 586): #3 SqfliteDatabaseMixin.txnRawInsert.<anonymous closure> (package:sqflite/src/database_mixin.dart:363:14)
E/flutter ( 586): #4 SqfliteDatabaseMixin.txnSynchronized.<anonymous closure> (package:sqflite/src/database_mixin.dart:307:22)
E/flutter ( 586): #5 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:32:26)
E/flutter ( 586): #6 SqfliteDatabaseMixin.txnSynchronized (package:sqflite/src/database_mixin.dart:303:43)
E/flutter ( 586): #7 SqfliteDatabaseMixin.txnWriteSynchronized (package:sqflite/src/database_mixin.dart:325:7)
E/flutter ( 586): #8 SqfliteDatabaseMixin.txnRawInsert (package:sqflite/src/database_mixin.dart:362:12)
E/flutter ( 586): #9 SqfliteDatabaseExecutorMixin.rawInsert (package:sqflite/src/database_mixin.dart:49:15)
E/flutter ( 586): #10 SqfliteDatabaseExecutorMixin.insert (package:sqflite/src/database_mixin.dart:59:12)
E/flutter ( 586): #11 Homes.addNewHome (package:search_list_view/providers/homes.dart:19:31)
E/flutter ( 586): <asynchronous suspension>
E/flutter ( 586): #12 _MyAppState.build.<anonymous closure> (package:search_list_view/main.dart:95:26)
E/flutter ( 586): #13 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter ( 586): #14 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter ( 586): #15 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 586): #16 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter ( 586): #17 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter ( 586): #18 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199:7)
E/flutter ( 586): #19 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:467:9)
E/flutter ( 586): #20 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter ( 586): #21 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117:9)
E/flutter ( 586): #22 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter ( 586): #23 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115:18)
E/flutter ( 586): #24 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:7)
E/flutter ( 586): #25 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 586): #26 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 586): #27 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 586): #28 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 586): #29 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 586): #30 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter ( 586): #31 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter ( 586): #32 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter ( 586): #33 _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter ( 586): #34 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
E/flutter ( 586):
If the answer is to change my DB schema so I have a table which joins dogs and houses and then do a custom query to pull back the information I'm after, then fine, I will do that. It doesn't seem too far fetch that a nosql db should be able to handle this... yes/no?
Any assistance would be much appreciated.
Thank you,
Bob
For storing any kind of value in the SQLite Database you can simply serialize the object into a JSON string and later deserialize the object.
lets say you have a class called Menu. (I am using JSON serializable here)
class Menu {
#JsonKey(name: "status")
String status;
#JsonKey(name: "data")
MenuListData menuListData;
Menu(this.status, this.menuListData);
factory Menu.fromJson(Map<String,dynamic>
json)=>_$MenuFromJson(json);
Map<String, dynamic> toJson() => _$MenuToJson(this);
}
Here is how to encode it in JSON and store it(in your bloc).
Menue menuList =
await getIt<LiveMenuRepository>().getMenuResponse(menuPost);
//decode the response to String format
String menuResponseString = jsonEncode(menuList);
//convert the string to Map of <String,dynamic> format
Map<String, dynamic> menuResponseMap = {"menu": menuResponseString};
//store this Map response in to local database
int menuStored = await getIt<LocalMenuRepository>().insertMenuResponseData(menuResponseMap);
Your DB insertion method
Future<int> insertMenuResponseData(Map<String,dynamic> menuResponse) async {
final db = await dbProvider.database;
var result = db.insert(menuTable, menuResponse);
return result;
}
Later retrieve your object using this
final Map<String, dynamic> menuList = await getIt<LocalMenuRepository>().getMenuResponseString();
// if(menuList!=null) {
menuList.forEach((key, value) {
if (key == "menu") {
storedMenu = value ;
}
});
//decode the string back to Map Object
final dynamic menuMap = jsonDecode(storedMenu);
//getting the Menu object using fromJson method
final Menu menuListNameResponse = Menu
.fromJson(menuMap as Map<String,dynamic>);
//getMenuResponseString method in db
Future<Map<String,dynamic>> getMenuResponse() async {
final db = await dbProvider.database;
List<Map<String, dynamic>> result;
result = await db.rawQuery('SELECT * FROM $menuTable');
// print(result[0]);
if (result.length > 0) {
return result[0];
}
return null;
}
Supported types are listed here (num, String or Uint8List): https://github.com/tekartik/sqflite/blob/master/sqflite/doc/supported_types.md
Nested content is not supported, Map and List should be encoded in a supported type for example as json string.

Unable to retrieve fetch ID data from API. How to fix?

I want to fetch details of a product by retrieving its ID and by accessing its Id to load the details needed but I keep getting an error that I dont quite understand?
here is my provider data:
class AddCar {
int id;
String name;
String city;
String country;
String currencyT;
double price;
String date;
int sponsNum;
String category;
String company;
String model;
String year;
String engine;
double distanceCovered;
String transmission;
String oilT;
String outColor;
String inColor;
String description;
File image;
PlaceLocation location;
bool isFavorite;
AddCar({
this.id,
this.name,
this.city,
this.country,
this.currencyT,
this.price,
this.date,
this.sponsNum,
this.category,
this.company,
this.model,
this.year,
this.engine,
this.distanceCovered,
this.transmission,
this.oilT,
this.outColor,
this.inColor,
this.description,
this.image,
this.location,
this.isFavorite = false,
});
}
class PlaceLocation {
final double latitude;
final double longitude;
final String address;
const PlaceLocation({
this.address,
this.latitude,
this.longitude,
});
}
Here is how im fetching the data (i have a link to a custome ID that im clicking on to lead to that product):
Future<void> fetchAndSetCarDetails() async {
const url = 'customLink/Detail?Id=204';
final response = await http.get(url);
final extractedData = json.decode(response.body) as Map<String, dynamic>;
List<AddCar> loadedCars = [];
extractedData.forEach((carId, carData) {
loadedCars.add(AddCar(
id: int.parse(carId),
name: carData['adTitle'],
sponsNum: carData['adNumber'],
price: carData['adPrice'],
date: carData['adDate'],
model: carData['brandModel'],
year: carData['modelYear'],
distanceCovered: carData['kilometer'],
transmission: carData['gearType'],
oilT: carData['fuelType'],
location: carData['adLocation'][PlaceLocation(
address: carData['adAddress'],
latitude: carData['lath'],
longitude: carData['lang'],
)],
description: carData['adDetails'],
country: carData['country'],
city: carData['cityName'],
category: carData['category'],
company: carData['brand'],
engine: carData['cylinder'],
outColor: carData['exteriorColor'],
inColor: carData['interiorColor'],
));
});
_cars = loadedCars;
print(response.body);
notifyListeners();
}
Here is the print data I get:
I/flutter (13626): {"id":204,"adTitle":null,"adDate":"2019-11-07T11:52:40.0156875","adPrice":25.0,"adNumber":195,"adAddress":"AdAddressssssss","adLocation":{"lath":"40.959028921030104","lang":" 30.992774628906318"},"adDetails":null,"country":227,"cityName":"Stockholm","category":"car child 1","categoryId":7,"brand":"mercedes","brandId":1,"brandModelId":6,"brandModel":"M300","cylinder":"6C","kilometer":300.0,"modelYear":"2010","fuelType":"benz","gearType":"automatic","exteriorColor":"red","interiorColor":"yellow","carType":1,"image":[],"isFavorite":false,
Here is the error I get when I click on the product to access its details:
E/flutter (13626): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: FormatException: Invalid radix-10 number (at character 1)
E/flutter (13626): id
E/flutter (13626): ^
E/flutter (13626):
E/flutter (13626): #0 int._throwFormatException (dart:core-patch/integers_patch.dart:131:5)
E/flutter (13626): #1 int._parseRadix (dart:core-patch/integers_patch.dart:142:16)
E/flutter (13626): #2 int._parse (dart:core-patch/integers_patch.dart:100:12)
E/flutter (13626): #3 int.parse (dart:core-patch/integers_patch.dart:63:12)
E/flutter (13626): #4 Cars.fetchAndSetCarDetails.<anonymous closure>
package:flutter_app/providers/car_provider.dart:88
E/flutter (13626): #5 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter (13626): #6 Cars.fetchAndSetCarDetails
package:flutter_app/providers/car_provider.dart:86
E/flutter (13626): <asynchronous suspension>
E/flutter (13626): #7 _MyCarDetailsState.initState.<anonymous closure>
package:flutter_app/details/car_details.dart:23
E/flutter (13626): #8 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (13626): #9 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (13626): #10 _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
E/flutter (13626): #11 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
E/flutter (13626): #12 Future._propagateToListeners (dart:async/future_impl.dart:707:32)
E/flutter (13626): #13 Future._complete (dart:async/future_impl.dart:512:7)
E/flutter (13626): #14 new Future.delayed.<anonymous closure> (dart:async/future.dart:313:16)
E/flutter (13626): #15 _rootRun (dart:async/zone.dart:1120:38)
E/flutter (13626): #16 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (13626): #17 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (13626): #18 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter (13626): #19 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (13626): #20 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (13626): #21 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
E/flutter (13626): #22 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:21:15)
E/flutter (13626): #23 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
E/flutter (13626): #24 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
E/flutter (13626): #25 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
E/flutter (13626):
You have several problems.
1 - your forEach closure looks like you are expecting the JSON to include a list of cars that you are going to add to loadedCars but it does not - there's just one car. That's why extractedData is a Map<String, dynamic> not a List<Map<String, dynamic>>.
2 - that means that the forEach closures is iterating over the members of the map so gets called once with carId='id' and carData=204 and then again with carId='adPrice' and carData=25.0 etc. This is clearly not what you're expecting! The exception happens when you try to parse 'id' into an int.
Given that there's only one car in your current json you can dispense with the loop. You should extract that one car like:
final response = await http.get(url);
final extractedData = json.decode(response.body) as Map<String, dynamic>;
var theOneCar = AddCar(
id: extractedData['id'], // no need for parse either - id is already an int
name: extractedData['adTitle'],
// etc
// etc
print (theOneCar);