Monday, April 8, 2024

SQFlite List Json With Api Insert Api result object in flutter

  SQFlite List Json With Api  (Insert Api result object)in flutter

{

"result" : [

{

"id" : 1,

"name" : "Avi",

"age" : 22

},

{

"id" : 2,

"name" : "Avi",

"age" : 22

}

],

"status" : 'ok'

}

ElevatedButton(child: Text("Insert"),
onPressed: ()async{

String sitename="gist.githubusercontent.com";
String path="/Avinashvns/749bdbee6d1d5b4f7e53d3544b63f50c/raw/de596d6c99855f64ffcb201f39aab5f183dd475b/sqlitebook.json";
Map<String,String> map=Map();
final res= await ApiCaller.getApi(sitename, path, map);
print("Res ${res['result']}");

List<dynamic> results = res['result'] as List<dynamic>;
BookModel bookModel = BookModel.fromJson({
"result": results,
"status": "ok",
});

// Iterate over the result list and insert each book into the database
for (Result result in bookModel.result) {
await DbHandler().insertBook(result);
}

// await DbHandler().insertBook(
// Result(
// // id: 2,
// book: nameController.text,
// price: int.parse(ageController.text)
// )
// );
print("Inserted");
print(nameController.text + ageController.text);

},),

No comments:

Post a Comment

Featured post

Compress Image With Show File Size & Resolution in Flutter

 Compress Image With Show File Size & Resolution  1.Multiple File Image Compress with file Size import 'dart:io' ; import 'p...

LightBlog