Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to store response to object in flutter using dio

I am using dio by using this I am passing form data and getting response but I am unable to store data to object. Please help me It is giving response when I am printing response.data but I am not getting how to store the response to object.

class MainActivityGrid extends StatefulWidget {
  @override
  _MainActivityGridState createState() => _MainActivityGridState();
}

class _MainActivityGridState extends State<MainActivityGrid> {
  // List<ImageModel>images= [];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: new Scaffold(
        appBar: AppBar(
          title: new Text("IPTV"),
        ),
        body: new Center(
          child: new RaisedButton(
              child: new Text("Button"), onPressed: fetchImage),
        ),
      ),
    );
  }

  Future<String> fetchImage() async {
    String url = "http://xxxxxx:xxx/onnet_api/mediaList.php";
    Response response;
    Dio dio = new Dio();

    FormData formData = new FormData.from(
        {"publisherid": 102, "tag": "media", "subtag": "list"});
    // counter ++;
    response = await dio.post(url, data: formData);
    // dio.interceptors.add(LogInterceptor(responseBody: fa));
    //int status = response.data["status"]["data"];
    //Map responseBody = response.data;
    //loginResponse = new LoginResponse.fromJson(json.decode(response.data));
    print(response.data["data"][0]);
    //ImageModel imageModel = new ImageModel.fromJson(json.decode(response.data[]));
    //print('response media: $status');
    /*  setState(() {
      //images.add(imageModel);
    });*/
  }
}

my JSON response for my API is showing like this below: please try to help me in this.

{
    "status": 1,
    "data": [
        {
            "id": "0_314t2peg",
            "name": "Countdown",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_314t2peg/version/100002",
            "plays": 12,
            "categories": "News>BBC,News>CNBC,News>PublicTV,News>TV9,Shows>Thriller,Shows>Regional",
            "categoriesIds": "19,20,18,17,13,16",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_314t2peg/format/url/protocol/http",
            "duration": 13,
            "createdAt": "28/11/18 11:26:39",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_joyzmp2z",
            "name": "voice 4k",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_joyzmp2z/version/100002",
            "plays": 14,
            "categories": "News>BBC,News>CNBC,News>PublicTV,News>TV9,Shows>Thriller,Shows>Regional",
            "categoriesIds": "19,20,18,17,13,16",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_joyzmp2z/format/url/protocol/http",
            "duration": 20,
            "createdAt": "28/11/18 11:25:56",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_yndwskxv",
            "name": "news",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_yndwskxv/version/100012",
            "plays": 6,
            "categories": "News>BBC,News>TV9,Shows>Regional",
            "categoriesIds": "19,17,16",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_yndwskxv/format/url/protocol/http",
            "duration": 17,
            "createdAt": "28/11/18 11:24:12",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_jd7hul0b",
            "name": "GB10Sec",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_jd7hul0b/version/100002",
            "plays": 8,
            "categories": "Shows>Thriller,Shows>Action,Shows>Sci-Fi",
            "categoriesIds": "13,15,14",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_jd7hul0b/format/url/protocol/http",
            "duration": 10,
            "createdAt": "28/11/18 11:14:40",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_bz9qlkle",
            "name": "Thugs Of Hindostan",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_bz9qlkle/version/100002",
            "plays": 0,
            "categories": null,
            "categoriesIds": null,
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_bz9qlkle/format/url/protocol/http",
            "duration": 218,
            "createdAt": "28/11/18 11:08:45",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_swm5unow",
            "name": "Shivaay",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_swm5unow/version/100002",
            "plays": 0,
            "categories": null,
            "categoriesIds": null,
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_swm5unow/format/url/protocol/http",
            "duration": 230,
            "createdAt": "28/11/18 11:08:23",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_1n1qg0hq",
            "name": "Rocky Handsome",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_1n1qg0hq/version/100012",
            "plays": 9,
            "categories": "Movies>Drama,Movies>Sci-Fi",
            "categoriesIds": "22,24",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_1n1qg0hq/format/url/protocol/http",
            "duration": 184,
            "createdAt": "28/11/18 11:08:03",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_3vk4o4ie",
            "name": "Genius",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_3vk4o4ie/version/100012",
            "plays": 5,
            "categories": "Movies>Drama,Movies>Sci-Fi",
            "categoriesIds": "22,24",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_3vk4o4ie/format/url/protocol/http",
            "duration": 200,
            "createdAt": "28/11/18 11:07:46",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_jb8en5kn",
            "name": "Commando",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_jb8en5kn/version/100012",
            "plays": 2,
            "categories": "Movies>Thriller,Movies>Drama,Movies>Sci-Fi",
            "categoriesIds": "23,22,24",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_jb8en5kn/format/url/protocol/http",
            "duration": 162,
            "createdAt": "28/11/18 11:07:25",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_es5vzzca",
            "name": "Action Jackson",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_es5vzzca/version/100002",
            "plays": 0,
            "categories": "Movies>Thriller,Movies>Drama,Movies>Sci-Fi",
            "categoriesIds": "23,22,24",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_es5vzzca/format/url/protocol/http",
            "duration": 175,
            "createdAt": "28/11/18 11:06:13",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_2tfugvsm",
            "name": "jellyfish-25-mbps-hd-hevc",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_2tfugvsm/version/100002",
            "plays": 0,
            "categories": null,
            "categoriesIds": null,
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_2tfugvsm/format/url/protocol/http",
            "duration": 30,
            "createdAt": "22/11/18 09:05:26",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_z5i5fmiw",
            "name": "small (3)",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_z5i5fmiw/version/100022",
            "plays": 1,
            "categories": null,
            "categoriesIds": null,
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_z5i5fmiw/format/url/protocol/http",
            "duration": 6,
            "createdAt": "22/11/18 06:41:15",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_0i4hbs9o",
            "name": "dolbycanyon",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_0i4hbs9o/version/100012",
            "plays": 1,
            "categories": null,
            "categoriesIds": null,
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_0i4hbs9o/format/url/protocol/http",
            "duration": 38,
            "createdAt": "22/11/18 06:38:13",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_wbd3wu38",
            "name": "Mary and little lamb",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_wbd3wu38/version/100002",
            "plays": 3,
            "categories": "Shows>Sci-Fi,Shows>Regional,Movies>Action",
            "categoriesIds": "14,16,21",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_wbd3wu38/format/url/protocol/http",
            "duration": 184,
            "createdAt": "12/11/18 10:36:17",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_k4unuqi2",
            "name": "Johny Johny",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_k4unuqi2/version/100002",
            "plays": 2,
            "categories": "Shows>Sci-Fi,Movies>Action",
            "categoriesIds": "14,21",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_k4unuqi2/format/url/protocol/http",
            "duration": 186,
            "createdAt": "12/11/18 10:36:17",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_3w4xjt5x",
            "name": "One Little Flower",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_3w4xjt5x/version/100012",
            "plays": 7,
            "categories": "TV>Entertainment",
            "categoriesIds": "25",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_3w4xjt5x/format/url/protocol/http",
            "duration": 83,
            "createdAt": "12/11/18 10:20:14",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_w64yjfen",
            "name": "I'm A Little Teapot",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_w64yjfen/version/100012",
            "plays": 9,
            "categories": "Shows>Action,TV>Shows",
            "categoriesIds": "15,11",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_w64yjfen/format/url/protocol/http",
            "duration": 104,
            "createdAt": "12/11/18 10:20:14",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_591qnfyf",
            "name": "Little Jack Horner",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_591qnfyf/version/100002",
            "plays": 93,
            "categories": "Shows>Regional,Movies>Action,TV>Shows",
            "categoriesIds": "16,21,11",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_591qnfyf/format/url/protocol/http",
            "duration": 87,
            "createdAt": "12/11/18 10:18:49",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_n1wvco0o",
            "name": "My School",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_n1wvco0o/version/100012",
            "plays": 21,
            "categories": "TV>Shows",
            "categoriesIds": "11",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_n1wvco0o/format/url/protocol/http",
            "duration": 75,
            "createdAt": "12/11/18 10:18:49",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_srtxu635",
            "name": "Hop a little",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_srtxu635/version/100012",
            "plays": 24,
            "categories": "Movies>Thriller,Movies>Action,TV>Shows",
            "categoriesIds": "23,21,11",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_srtxu635/format/url/protocol/http",
            "duration": 108,
            "createdAt": "12/11/18 10:18:49",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_uuu7jii2",
            "name": "Come Little Children",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_uuu7jii2/version/100002",
            "plays": 4,
            "categories": "Movies>Sci-Fi,Movies>Action,TV>Shows",
            "categoriesIds": "24,21,11",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_uuu7jii2/format/url/protocol/http",
            "duration": 94,
            "createdAt": "12/11/18 10:16:00",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_9ld6kzph",
            "name": "story telling",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_9ld6kzph/version/100002",
            "plays": 2,
            "categories": "Movies>Drama,Movies>Action",
            "categoriesIds": "22,21",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_9ld6kzph/format/url/protocol/http",
            "duration": 73,
            "createdAt": "12/11/18 10:16:00",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_cz6egmc9",
            "name": "Tenali Raman In English",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_cz6egmc9/version/100002",
            "plays": 1,
            "categories": "Movies>Action,Shows>Thriller",
            "categoriesIds": "21,13",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_cz6egmc9/format/url/protocol/http",
            "duration": 151,
            "createdAt": "12/11/18 10:16:00",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_pj8ansdd",
            "name": "The two frogs",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_pj8ansdd/version/100002",
            "plays": 1,
            "categories": "News>TV9,Movies>Action",
            "categoriesIds": "17,21",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_pj8ansdd/format/url/protocol/http",
            "duration": 141,
            "createdAt": "12/11/18 10:16:00",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_7wy5icdl",
            "name": "Twinkle Twinkle",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_7wy5icdl/version/100002",
            "plays": 1,
            "categories": "News>CNBC",
            "categoriesIds": "20",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_7wy5icdl/format/url/protocol/http",
            "duration": 181,
            "createdAt": "12/11/18 10:16:00",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_0l7xkwee",
            "name": "Two little hands",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_0l7xkwee/version/100002",
            "plays": 5,
            "categories": "Movies>Action,News>BBC",
            "categoriesIds": "21,19",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_0l7xkwee/format/url/protocol/http",
            "duration": 59,
            "createdAt": "12/11/18 10:16:00",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_58md9gkm",
            "name": "amazoneco",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_58md9gkm/version/100002",
            "plays": 0,
            "categories": "News>PublicTV",
            "categoriesIds": "18",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_58md9gkm/format/url/protocol/http",
            "duration": 36,
            "createdAt": "05/11/18 12:01:44",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_f90klu3n",
            "name": "arunicecream",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_f90klu3n/version/100012",
            "plays": 2,
            "categories": null,
            "categoriesIds": null,
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_f90klu3n/format/url/protocol/http",
            "duration": 15,
            "createdAt": "05/11/18 12:01:44",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_hmr8atha",
            "name": "bahubalitrailer",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_hmr8atha/version/100012",
            "plays": 11,
            "categories": "TV>Songs,Shows>Thriller,Shows>Regional",
            "categoriesIds": "12,13,16",
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_hmr8atha/format/url/protocol/http",
            "duration": 21,
            "createdAt": "05/11/18 12:01:44",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        },
        {
            "id": "0_kzwqw8eq",
            "name": "BigData",
            "thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_kzwqw8eq/version/100012",
            "plays": 1,
            "categories": null,
            "categoriesIds": null,
            "dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_kzwqw8eq/format/url/protocol/http",
            "duration": 93,
            "createdAt": "05/11/18 12:01:44",
            "status": 2,
            "statusc": 2,
            "mediaType": 1
        }
    ],
    "totalRecord": 30
}
like image 569
Mounika Avatar asked Dec 07 '22 12:12

Mounika


1 Answers

No need to use Json Decode for Dio. You can do something like below:

Response responseval=await dio.post(url,options: Options(headers: headers));
var name=responseval.data['username'];
var id=responseeval.data['id'];
like image 66
NBM Avatar answered Dec 11 '22 10:12

NBM