Unsupported operation: Cannot modify an unmodifiable list - flutter

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>

Related

How to execute write method in function that changes value in slidebar?

When the slide bar value changes, it tries to write a packet.
I am using the example,
I made a function and tried it, but a null error occurs. (discoverService, characteristic.., etc.)
How can I solve this?
I'm using flutter_blue
In the flutter_blue example, write works fine.
I'm flutter beginer.
I need your help. thank you.
https://pub.dev/packages/flutter_blue
onWriteData
var data = [0x80, 0x80, 0xF0, 0x7D, 0x05, 0x00, 0x0E, 0x01, 60, 100, 00,0x80, 0xF7];
FlutterBlue flutterBlue = FlutterBlue.instance;
BluetoothDevice device;
BluetoothService service;
onWriteData() async {
List<BluetoothService> services = await device.discoverServices();
services.forEach((service) {
});
var characteristics = service.characteristics;
for(BluetoothCharacteristic c in characteristics) {
List<int> value = await c.read();
print(value);
await c.write(data);
}
}
slideBar class
class slidecontrollerr extends State<slidecontroller> {
static double volumeValue = 60;
void onVolumeChanged(double value) async { **// I want to execute the write function here**
setState(() {
volumeValue = value;
});
onWriteData(); **//error**
}
#override
Widget build(BuildContext context) {
return Scaffold(
.
.
.
[Error Code][1]
E/flutter ( 5640): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: NoSuchMethodError: The method 'discoverServices' was called on null.
E/flutter ( 5640): Receiver: null
E/flutter ( 5640): Tried calling: discoverServices()
E/flutter ( 5640): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
E/flutter ( 5640): #1 onWriteData (package:auto_humidity/main.dart:467:48)
E/flutter ( 5640): #2 slidecontrollerr.onVolumeChanged (package:auto_humidity/main.dart:1489:5)
E/flutter ( 5640): #3 RenderRadialAxisParent.createPointerValueChangedArgs (package:syncfusion_flutter_gauges/src/radial_gauge/axis/radial_axis_parent_widget.dart:584:43)
E/flutter ( 5640): #4 RenderRadialAxisParent._setCurrentPointerValue (package:syncfusion_flutter_gauges/src/radial_gauge/axis/radial_axis_parent_widget.dart:548:5)
E/flutter ( 5640): #5 RenderRadialAxisParent._updateDragValue (package:syncfusion_flutter_gauges/src/radial_gauge/axis/radial_axis_parent_widget.dart:527:7)
E/flutter ( 5640): #6 RenderRadialAxisParent._updatePointerValue (package:syncfusion_flutter_gauges/src/radial_gauge/axis/radial_axis_parent_widget.dart:452:7)
E/flutter ( 5640): #7 RenderRadialAxisParent._handleDragUpdate (package:syncfusion_flutter_gauges/src/radial_gauge/axis/radial_axis_parent_widget.dart:339:5)
E/flutter ( 5640): #8 DragGestureRecognizer._checkUpdate.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:436:55)
E/flutter ( 5640): #9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 5640): #10 DragGestureRecognizer._checkUpdate (package:flutter/src/gestures/monodrag.dart:436:7)
E/flutter ( 5640): #11 DragGestureRecognizer.handleEvent (package:flutter/src/gestures/monodrag.dart:289:9)
E/flutter ( 5640): #12 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:93:12)
E/flutter ( 5640): #13 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:138:9)
E/flutter ( 5640): #14 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:397:8)
E/flutter ( 5640): #15 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:136:18)
E/flutter ( 5640): #16 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:122:7)
E/flutter ( 5640): #17 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:439:19)
E/flutter ( 5640): #18 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:419:22)
E/flutter ( 5640): #19 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:287:11)
E/flutter ( 5640): #20 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:374:7)
E/flutter ( 5640): #21 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:338:5)
E/flutter ( 5640): #22 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:296:7)
E/flutter ( 5640): #23 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:279:7)
E/flutter ( 5640): #24 _rootRunUnary (dart:async/zone.dart:1370:13)
E/flutter ( 5640): #25 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter ( 5640): #26 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter ( 5640): #27 _invoke1 (dart:ui/hooks.dart:182:10)
E/flutter ( 5640): #28 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:282:7)
E/flutter ( 5640): #29 _dispatchPointerDataPacket (dart:ui/hooks.dart:96:31)
You need to connect to a specific service and characteristics of your BLE device
Here is a piece of code that I am using
final String serviceUUID = "0000ffe0-0000-1000-8000-00805f9b34fb";
final String characteristicWriteUUID = "0000fff1-0000-1000-8000-00805f9b34fb";
final String characteristicReadUUID = "0000fff2-0000-1000-8000-00805f9b34fb";
These services and characteristics must be set in the module itself by default or by you manually
discoverServices(BluetoothDevice device) async {
if (device == null) return;
List<BluetoothService> services = await device.discoverServices();
services.forEach((service) {
// do something with service
if (service.uuid.toString().toLowerCase() == serviceUUID) {
service.characteristics.forEach((characteristic) {
if (characteristic.uuid.toString().toLowerCase() == characteristicReadUUID) {
targetReadCharacteristic = characteristic;
_readData(targetReadCharacteristic);
}
if (characteristic.uuid.toString().toLowerCase() == characteristicWriteUUID) {
targetWriteCharacteristic = characteristic;
writeData(targetWriteCharacteristic, [0x49, 0x44, 0x02]);
}
});
}
});
}
Future<void> writeData(characteristic, data) async{
if (characteristic == null) return;
try {
List<int> bytes = data;
await characteristic.write(bytes, withoutResponse: true );
print("data: Send: $data");
} catch (e) {
print('Data Error ${e.message} | $data');
}
}
_readData(characteristic) async {
if (!characteristic.isNotifying) {
await characteristic.setNotifyValue(true);
}
readSubScription = characteristic.value.listen((value) {
List<int> readData = new List.from(value);
if(readData.isNotEmpty && readData != []){
print('BLE read data: $readData');
}
});
}

Null Check operator used on a null value on flutter with Sqflite

I'm studying flutter with Sqflite and trying to make a small app, but I'm getting this error when I run the code, I've looked literaly everywhere to findout what it could be.
Here the code code who use the Sqflite package:
Future<Database> getDatabase() async {
final String path = join(await getDatabasesPath(), 'bytebank.db');
return openDatabase(path, onCreate: (db, version) {
db.execute('CREATE TABLE contacts'
'(id INTEGER PRIMARY KEY, '
'name TEXT, '
'account_number INTEGER)');
}, version: 1);
}
Future<int> save(Contact contact) async {
final Database db = await getDatabase();
final Map<String, dynamic> contactMap = Map();
contactMap['name'] = contact.name;
contactMap['account_number'] = contact.account;
contactMap['id'] = contact.id;
return db.insert('contacts', contactMap);
}
Future<List<Contact>> findAll() async {
final Database db = await getDatabase();
final List<Map<String, dynamic>> result = await db.query('contacts');
final List<Contact> contacts = [];
for (Map<String, dynamic> row in result) {
final Contact contact = Contact(
row['id'],
row['name'],
row['account_number'],
);
contacts.add(contact);
}
return contacts;
}
And here is the only one place where I use This functions:
void main() {
save(Contact('William', 2, 13456)).then((id) {
findAll().then((contacts) => print(contacts));
});
runApp(ByteBankApp());
}
Model Class:
class Contact {
final String name;
final int account;
final int id;
Contact( this.id,
this.name,
this.account,
);
#override
String toString() {
return 'Contact{name: $name, account: $account}';
}
}
Error Trace back:
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:52296/07rtnvW9tlQ=/ws
Syncing files to device sdk gphone x86 arm...
E/flutter (28649): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value
E/flutter (28649): #0 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:142:86)
E/flutter (28649): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:148:36)
E/flutter (28649): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:331:12)
E/flutter (28649): #3 invokeMethod (package:sqflite/src/sqflite_impl.dart:17:13)
E/flutter (28649): #4 SqfliteDatabaseFactoryImpl.invokeMethod (package:sqflite/src/factory_impl.dart:82:7)
E/flutter (28649): #5 SqfliteDatabaseFactoryMixin.safeInvokeMethod.<anonymous closure> (package:sqflite_common/src/factory_mixin.dart:41:38)
E/flutter (28649): #6 wrapDatabaseException (package:sqflite/src/exception_impl.dart:7:32)
E/flutter (28649): #7 SqfliteDatabaseFactoryImpl.wrapDatabaseException (package:sqflite/src/factory_impl.dart:78:7)
E/flutter (28649): #8 SqfliteDatabaseFactoryMixin.safeInvokeMethod (package:sqflite_common/src/factory_mixin.dart:41:7)
E/flutter (28649): #9 SqfliteDatabaseFactoryMixin.getDatabasesPath (package:sqflite_common/src/factory_mixin.dart:153:26)
E/flutter (28649): #10 getDatabasesPath (package:sqflite/sqflite.dart:161:54)
E/flutter (28649): #11 getDatabase (package:bytebank/database/app_database.dart:6:34)
E/flutter (28649): #12 save (package:bytebank/database/app_database.dart:16:29)
E/flutter (28649): #13 main (package:bytebank/main.dart:7:3)
E/flutter (28649): #14 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:142:25)
E/flutter (28649): #15 _rootRun (dart:async/zone.dart:1354:13)
E/flutter (28649): #16 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (28649): #17 _runZoned (dart:async/zone.dart:1789:10)
E/flutter (28649): #18 runZonedGuarded (dart:async/zone.dart:1777:12)
E/flutter (28649): #19 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:138:5)
E/flutter (28649): #20 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter (28649): #21 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter (28649):
I am not sure if will help, but I was running into a similar issue when initializing a database in an async "main" method. Adding the following:
WidgetsFlutterBinding.ensureInitialized();
inside the method before the code initializing the database solved the problem.

Unhandled Exception: NoSuchMethodError: The method 'call' was called on null

I upgraded the flutter sdk by flutter upgrade --force. The project was working fine before upgrade but I am getting error after upgrade. I am currently working in lastest stable version of flutter.
E/flutter (17687): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: NoSuchMethodError: The method 'call' was called on null.
E/flutter (17687): Receiver: null
E/flutter (17687): Tried calling: call()
E/flutter (17687): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
E/flutter (17687): #1 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:31:24)
E/flutter (17687): #2 SembastDatabase.flush (package:sembast/src/database_impl.dart:593:27)
E/flutter (17687): #3 SembastDatabase.open (package:sembast/src/database_impl.dart:879:11)
E/flutter (17687): <asynchronous suspension>
E/flutter (17687): #4 DatabaseOpenHelper.openDatabase.<anonymous closure> (package:sembast/src/database_factory_mixin.dart:80:7)
E/flutter (17687): <asynchronous suspension>
E/flutter (17687): #5 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33:16)
E/flutter (17687): <asynchronous suspension>
E/flutter (17687): #6 DaoDatabase._openDatabase (package:kitabyatra/db/DaoDatabase.dart:43:26)
E/flutter (17687): <asynchronous suspension>
I have implemented as follows:
class DaoDatabase {
DaoDatabase();
static final DaoDatabase _singleton = DaoDatabase();
static DaoDatabase get instance => _singleton;
Completer<Database> _dbOpenCompleter;
Future<Database> get database async {
if (_dbOpenCompleter == null) {
_dbOpenCompleter = Completer<Database>();
_openDatabase();
}
return _dbOpenCompleter.future;
}
Future<dynamic> _openDatabase() async {
final Directory appDocumentDir = await getApplicationDocumentsDirectory();
final String dbPath = join(appDocumentDir.path, Strings.appDbName);
final Database database = await databaseFactoryIo.openDatabase(dbPath); //--> Getting error here
_dbOpenCompleter.complete(database);
}
}

Uploading Screenshots to Firebase with Flutter

I want to upload the screenshot image to Firestore, but I am having some null errors,
Future uploadImagetoFirebase() async {
await screenshotController.capture().then((value) => (File image) {
_screenshot = image;
});
String fileName = _screenshot.path;
Reference firebaseStorageRef =
FirebaseStorage.instance.ref().child('orders/$fileName');
UploadTask uploadTask = firebaseStorageRef.putFile(_screenshot);
TaskSnapshot taskSnapshot = await uploadTask;
taskSnapshot.ref.getDownloadURL().then((value) => print('Done: $value'));
}
I am calling it with button like this:
onPressed: () async {
await uploadImagetoFirebase(); }
This is the error stack:
flutter ( 5143): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The getter 'path' was called on null.
E/flutter ( 5143): Receiver: null
E/flutter ( 5143): Tried calling: path
E/flutter ( 5143): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter ( 5143): #1 _CartState.uploadImagetoFirebase
package:CWCFlutter/model/cart.dart:88
E/flutter ( 5143): <asynchronous suspension>
E/flutter ( 5143): #2 _CartState.build.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure>
package:CWCFlutter/model/cart.dart:310
E/flutter ( 5143): #3 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:993
E/flutter ( 5143): #4 _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:1111
E/flutter ( 5143): #5 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:183
E/flutter ( 5143): #6 TapGestureRecognizer.handleTapUp
package:flutter/…/gestures/tap.dart:598
E/flutter ( 5143): #7 BaseTapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:287
E/flutter ( 5143): #8 BaseTapGestureRecognizer.handlePrimaryPointer
package:flutter/…/gestures/tap.dart:222
E/flutter ( 5143): #9 PrimaryPointerGestureRecognizer.handleEvent
package:flutter/…/gestures/recognizer.dart:476
E/flutter ( 5143): #10 PointerRouter._dispatch
package:flutter/…/gestures/pointer_router.dart:77
E/flutter ( 5143): #11 PointerRouter._dispatchEventToRoutes.<anonymous closure>
package:flutter/…/gestures/pointer_router.dart:122
E/flutter ( 5143): #12 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter ( 5143): #13 PointerRouter._dispatchEventToRoutes
package:flutter/…/gestures/pointer_router.dart:120
E/flutter ( 5143): #14 PointerRouter.route
package:flutter/…/gestures/pointer_router.dart:106
E/flutter ( 5143): #15 GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:358
E/flutter ( 5143): #16 GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:338
E/flutter ( 5143): #17 RendererBinding.dispatchEvent
package:flutter/…/rendering/binding.dart:267
E/flutter ( 5143): #18 GestureBinding._handlePointerEvent
package:flutter/…/gestures/binding.dart:295
E/flutter ( 5143): #19 GestureBinding._flushPointerEventQueue
package:flutter/…/gestures/binding.dart:240
E/flutter ( 5143): #20 GestureBinding._handlePointerDataPacket
package:flutter/…/gestures/binding.dart:213
E/flutter ( 5143): #21 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 5143): #22 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5143): #23 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5143): #24 _invoke1 (dart:ui/hooks.dart:265:10)
E/flutter ( 5143): #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)
I am not sure how path was called on null, any ideas? Basically I await for the app to take a screenshot, then add that image in _screenshot File variable, then try to store it in 'orders' folder in Firestore. I have searched for answers, and they say you need to initialize Firestore somewhere, but I am not sure where that would be, I have only worked with older versions, and not sure how to do all things in the newer ones. Thank you!
I have tried setting the state as well, but getting the same error:
Future uploadImagetoFirebase() async {
await screenshotController.capture().then((value) => (File image) {
setState(() {
_screenshot = image;
});
});
What I came up with that seems to work as a solution
Future<String> uploadImagetoFirebase2() async {
File img = await screenshotController.capture();
setState(() {
_screenshot = img;
});
//change filename not to be path, but something else short
String fileName = img.path;
Reference firebaseStorageRef =
FirebaseStorage.instance.ref().child('orders/$fileName');
UploadTask uploadTask = firebaseStorageRef.putFile(_screenshot);
TaskSnapshot taskSnapshot = (await uploadTask);
String uri = await taskSnapshot.ref.getDownloadURL();
print(uri);
return uri;
}
flutter ( 5143): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The getter 'path' was called on null.
E/flutter ( 5143): Receiver: null
E/flutter ( 5143): Tried calling: path
your path is null,
you can solve this in two ways
1. setstate
Future uploadImagetoFirebase() async {
await screenshotController.capture().then((value) => (File image) {
setState(() {
_screenshot = image;
});
});
//... your fireabase upload function
2 return from future
Future <File> uploadImagetoFirebase() async {
File myImage=await screenshotController.capture();
retun myImage
);
//get image onPress btn
onPressed: () async {
var myFile= await uploadImagetoFirebase();
//check if path is null using if ...
print(myFile.path);
// firebase function
Reference firebaseStorageRef =
FirebaseStorage.instance.ref().child('orders/${myFile.path}');
UploadTask uploadTask = firebaseStorageRef.putFile(myFile);
TaskSnapshot taskSnapshot = (await uploadTask);
String uri = await taskSnapshot.ref.getDownloadURL();
print(uri);
return uri;
}
try this;
Future<String> uploadImagetoFirebase() async {
File img = await screenshotController.capture();
String fileName = img.path;
Reference firebaseStorageRef =
FirebaseStorage.instance.ref().child('orders/$fileName');
UploadTask uploadTask = firebaseStorageRef.putFile(_screenshot);
TaskSnapshot taskSnapshot = (await uploadTask);
String uri = await taskSnapshot.ref.getDownloadURL();
print(uri);
return uri;
}

Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index' Problem Dart & 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());
}