Get direct Vimeo video url Android - android
I need to play Vimeo viodes in my app having only video id. For example 83342420.
How can I get vimeo video url? Or is there any other way to play video in android?
I tried WebView solution but it doesn't suit.
I also tried the urls like http://vimeo.com/moogaloop/play/clip:7926539/5cd4f7989ee0cb5018c131260aa1fc8c/1309860388/ but I'm getting 404 Not found.
Maybe I need some kind of api key or token?
Thanks.
Ok. For getting direct url for Vimeo video just need to send GET Request to url:
old url - http://player.vimeo.com/v2/video/<video_id>/config
**UPD**: new url - http://player.vimeo.com/video/<video_id>/config
In result you will get such response:
{
"cdn_url": "http://f.vimeocdn.com",
"view": 1,
"request": {
"files": {
"h264": {
"mobile": {
"profile": 116,
"origin": "ns3.pdl",
"url": "http://pdl.vimeocdn.com/84730/904/216566897.mp4?token2=1397407519_8b323701fa08b3531612d6160be9cc5e&aksessionid=01788ff54890a9b2",
"height": 270,
"width": 480,
"id": 216566897,
"bitrate": 547,
"availability": 60
},
"hd": {
"profile": 113,
"origin": "ns3.pdl",
"url": "http://pdl.vimeocdn.com/87179/143/216566895.mp4?token2=1397407519_1d0ef28841fb628c423f9dbeb93168d4&aksessionid=2a0b480300c82ef7",
"height": 720,
"width": 1280,
"id": 216566895,
"bitrate": 3142,
"availability": 60
},
"sd": {
"profile": 112,
"origin": "ns3.pdl",
"url": "http://pdl.vimeocdn.com/57248/568/216566886.mp4?token2=1397407519_395f6cf4e80b98826424e21c8de508d1&aksessionid=598e59776ed0979a",
"height": 360,
"width": 640,
"id": 216566886,
"bitrate": 1198,
"availability": 60
}
},
"hls": {
"all": "http://av20.hls.vimeocdn.com/i/,57248/568/216566886,87179/143/216566895,84730/904/216566897,.mp4.csmil/master.m3u8?primaryToken=1397407519_93cf5d54b3482e3a1e716cf28b9550a7",
"hd": "http://av20.hls.vimeocdn.com/i/,87179/143/216566895,.mp4.csmil/master.m3u8?primaryToken=1397407519_a84194ace821175f0ee0ff9ab8d9241f"
},
"codecs": [
"h264"
]
},
"ga_account": "UA-76641-35",
"timestamp": 1397406594,
"expires": 925,
"prefix": "/v2",
"session": "d85291b3aa5b3e5fbf3ea82d81d7d5e849aa50e5",
"cookie": {
"scaling": 1,
"volume": 1.0,
"hd": null,
"captions": null
},
"cookie_domain": ".vimeo.com",
"referrer": null,
"conviva_account": "c3.Vimeo",
"flags": {
"login": 1,
"preload_video": 1,
"plays": 1,
"partials": 1,
"conviva": 1
},
"build": {
"player": "a30ff35f",
"js": "2.4.7"
},
"urls": {
"zeroclip_swf": "http://f.vimeocdn.com/p/external/zeroclipboard/ZeroClipboard.swf",
"js": "http://f.vimeocdn.com/p/2.4.7/js/player.js",
"proxy": "https://f.vimeocdn.com/p/2.4.7/proxy.html",
"conviva": "http://livepassdl.conviva.com/ver/2.72.0.13589/LivePass.js",
"flideo": "http://f.vimeocdn.com/p/flash/flideo/1.0.3b10/flideo.swf",
"canvas_js": "http://f.vimeocdn.com/p/2.4.7/js/player.canvas.js",
"moog": "http://f.vimeocdn.com/p/flash/moogaloop/6.0.9/moogaloop.swf?clip_id=83342420",
"conviva_service": "http://livepass.conviva.com",
"moog_js": "http://f.vimeocdn.com/p/2.4.7/js/moogaloop.js",
"zeroclip_js": "http://f.vimeocdn.com/p/external/zeroclipboard/ZeroClipboard-patch.js",
"css": "http://f.vimeocdn.com/p/2.4.7/css/player.css"
},
"signature": "09c6bc41e6a7d343748ed3e00420a108"
},
"player_url": "player.vimeo.com",
"video": {
"allow_hd": 1,
"height": 720,
"owner": {
"account_type": "pro",
"name": "Sabian",
"img": "http://i.vimeocdn.com/portrait/2511583_75x75.jpg",
"url": "http://vimeo.com/sabian",
"img_2x": "http://i.vimeocdn.com/portrait/2511583_150x150.jpg",
"id": 8487062
},
"thumbs": {
"1280": "http://i.vimeocdn.com/video/459788805_1280.jpg",
"960": "http://i.vimeocdn.com/video/459788805_960.jpg",
"640": "http://i.vimeocdn.com/video/459788805_640.jpg"
},
"duration": 25,
"id": 83342420,
"hd": 1,
"embed_code": "<iframe src=\"//player.vimeo.com/video/83342420\" width=\"500\" height=\"281\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>",
"default_to_hd": 0,
"title": "Mike Portnoy",
"url": "https://vimeo.com/83342420",
"privacy": "anybody",
"share_url": "http://vimeo.com/83342420",
"width": 1280,
"embed_permission": "public",
"fps": 24.0
},
"build": {
"player": "a30ff35f",
"rpc": "dev"
},
"embed": {
"player_id": null,
"outro": "videos",
"api": 2,
"context": "embed.main",
"time": 0,
"color": "00adef",
"settings": {
"fullscreen": 1,
"byline_badge": {
"url": "http://vimeo.com/sabian",
"type": "pro"
},
"byline": 1,
"like": 1,
"playbar": 1,
"title": 1,
"color": 0,
"branding": 1,
"share": 1,
"scaling": 1,
"logo": 1,
"info_on_pause": 0,
"watch_later": 1,
"portrait": 1,
"embed": 1,
"badge": 0,
"volume": 1
},
"on_site": 0,
"loop": 0,
"autoplay": 0
},
"vimeo_url": "vimeo.com",
"user": {
"liked": 0,
"account_type": "basic",
"logged_in": 1,
"owner": 0,
"watch_later": 0,
"id": 26896968,
"mod": false
}
}
Vimeo does not offer support for any videos play urls. Vimeo only offers 2 methods for playing videos on mobile.
Embeddable videos work in many Android web views.
PRO members have access to direct video file links (including HLS) and can use these in their own mobile apps.
use this url - http://player.vimeo.com/video/video_id/config with GET method, and pass your video_id, you will get the below result. this is latest response is coming from Vimeo, because the change response.
{
"cdn_url": "https://f.vimeocdn.com",
"vimeo_api_url": "api.vimeo.com",
"request": {
"files": {
"dash": {
"separate_av": true,
"streams": [
{
"profile": 164,
"quality": "360p",
"id": 1047687609,
"fps": 30
},
{
"profile": 175,
"quality": "1080p",
"id": 1047687611,
"fps": 30
},
{
"profile": 165,
"quality": "540p",
"id": 1047687607,
"fps": 30
},
{
"profile": 174,
"quality": "720p",
"id": 1047687604,
"fps": 30
}
],
"cdns": {
"akfire_interconnect_quic": {
"url": "https://112skyfiregce-vimeo.akamaized.net/exp=1531572843~acl=%2F279620511%2F%2A~hmac=fc67765d21d06ae32cd69b0fa7a9f229ba5c492a6ea14d14cfee32fce9afb1a2/279620511/sep/video/1047687609,1047687611,1047687607,1047687604/master.json?base64_init=1",
"origin": "gcs"
},
"fastly_skyfire": {
"url": "https://skyfire.vimeocdn.com/1531572843-0xb2b233940673f62145704b412d1469ea2f179a4c/279620511/sep/video/1047687609,1047687611,1047687607,1047687604/master.json?base64_init=1",
"origin": "gcs"
}
},
"default_cdn": "akfire_interconnect_quic"
},
"hls": {
"separate_av": false,
"default_cdn": "akfire_interconnect_quic",
"cdns": {
"akfire_interconnect_quic": {
"url": "https://112skyfiregce-vimeo.akamaized.net/exp=1531572843~acl=%2F279620511%2F%2A~hmac=fc67765d21d06ae32cd69b0fa7a9f229ba5c492a6ea14d14cfee32fce9afb1a2/279620511/video/1047687609,1047687611,1047687607,1047687604/master.m3u8",
"origin": "gcs"
},
"fastly_skyfire": {
"url": "https://skyfire.vimeocdn.com/1531572843-0xb2b233940673f62145704b412d1469ea2f179a4c/279620511/video/1047687609,1047687611,1047687607,1047687604/master.m3u8",
"origin": "gcs"
}
}
},
"progressive": [
{
"profile": 175,
"width": 1920,
"mime": "video/mp4",
"fps": 30,
"url": "https://gcs-vimeo.akamaized.net/exp=1531572843~acl=%2A%2F1047687611.mp4%2A~hmac=90eacf4c4956f322393ac1b5e4d0df91694c5e5af36eabccd2a28780e4364148/vimeo-prod-skyfire-std-us/01/924/11/279620511/1047687611.mp4",
"cdn": "akamai_interconnect",
"quality": "1080p",
"id": 1047687611,
"origin": "gcs",
"height": 1080
},
{
"profile": 164,
"width": 640,
"mime": "video/mp4",
"fps": 30,
"url": "https://gcs-vimeo.akamaized.net/exp=1531572843~acl=%2A%2F1047687609.mp4%2A~hmac=4c90608f99044633906efb33f04e314569cd865266529b96977ee7eeecce4f80/vimeo-prod-skyfire-std-us/01/924/11/279620511/1047687609.mp4",
"cdn": "akamai_interconnect",
"quality": "360p",
"id": 1047687609,
"origin": "gcs",
"height": 360
},
{
"profile": 165,
"width": 960,
"mime": "video/mp4",
"fps": 30,
"url": "https://gcs-vimeo.akamaized.net/exp=1531572843~acl=%2A%2F1047687607.mp4%2A~hmac=a0f28428ec2da33b5501936f32a3bc17aee0446dfbb5f0597c5b51f743cebc65/vimeo-prod-skyfire-std-us/01/924/11/279620511/1047687607.mp4",
"cdn": "akamai_interconnect",
"quality": "540p",
"id": 1047687607,
"origin": "gcs",
"height": 540
},
{
"profile": 174,
"width": 1280,
"mime": "video/mp4",
"fps": 30,
"url": "https://gcs-vimeo.akamaized.net/exp=1531572843~acl=%2A%2F1047687604.mp4%2A~hmac=6a3da45344051eb54196967bebebbd34841f09c049ca377b7f664786f24dfb95/vimeo-prod-skyfire-std-us/01/924/11/279620511/1047687604.mp4",
"cdn": "akamai_interconnect",
"quality": "720p",
"id": 1047687604,
"origin": "gcs",
"height": 720
}
]
},
"lang": "en",
"sentry": {
"url": "https://9e9ab33f1870463393a4a1e85a1280c2#sentry.cloud.vimeo.com/2",
"enabled": false,
"debug_enabled": true,
"debug_intent": 0
},
"ab_tests": {},
"referrer": null,
"cookie_domain": ".vimeo.com",
"timestamp": 1531568943,
"gc_debug": {
"bucket": "vimeo-player-debug"
},
"expires": 3600,
"currency": "USD",
"session": "d2a0f4ba2c4a97b7e59e349e54ee5e4d212a78b01531568943",
"cookie": {
"scaling": 1,
"volume": 1,
"quality": null,
"hd": 0,
"captions": null
},
"build": {
"player": "",
"js": "2.75.6"
},
"urls": {
"zeroclip_swf": "https://f.vimeocdn.com/p/external/zeroclipboard/ZeroClipboard.swf",
"fresnel": "https://fresnel.vimeocdn.com/add/player-stats",
"js": "https://f.vimeocdn.com/p/2.75.6/js/player.js",
"proxy": "https://player.vimeo.com/static/proxy.html",
"chromeless_css": "https://f.vimeocdn.com/p/2.75.6/css/chromeless.css",
"flideo": "https://f.vimeocdn.com/p/flash/flideo/1.0.6/flideo.swf",
"moog": "https://f.vimeocdn.com/p/flash/moogaloop/6.4.5/moogaloop.swf?clip_id=279620511",
"three_js": "https://f.vimeocdn.com/p/external/three.rvimeo.min.js",
"mux_url": "https://f.vimeocdn.com/p/external/mux.js",
"vuid_js": "https://f.vimeocdn.com/js_opt/modules/utils/vuid.min.js",
"chromeless_js": "https://f.vimeocdn.com/p/2.75.6/js/chromeless.js",
"moog_js": "https://f.vimeocdn.com/p/2.75.6/js/moogaloop.js",
"zeroclip_js": "https://f.vimeocdn.com/p/external/zeroclipboard/ZeroClipboard-patch.js",
"css": "https://f.vimeocdn.com/p/2.75.6/css/player.css"
},
"signature": "8544b7e2ca11afdca19cef76f57fed72",
"flags": {
"dnt": 0,
"preload_video": "metadata_on_hover",
"plays": 1,
"webp": 0,
"flash_hls": 1,
"log_to_es": 0,
"partials": 1,
"autohide_controls": 0
},
"country": "IN"
},
"player_url": "player.vimeo.com",
"video": {
"version": {
"current": null,
"available": [
{
"is_current": 1,
"id": 20743507,
"file_id": 1047687416
}
]
},
"height": 1080,
"duration": 543,
"thumbs": {
"640": "https://i.vimeocdn.com/video/712935666_640.jpg",
"960": "https://i.vimeocdn.com/video/712935666_960.jpg",
"1280": "https://i.vimeocdn.com/video/712935666_1280.jpg",
"base": "https://i.vimeocdn.com/video/712935666"
},
"owner": {
"account_type": "pro",
"name": "You Are a CEO",
"img": "https://i.vimeocdn.com/portrait/26028985_60x60.jpg",
"url": "https://vimeo.com/user19222589",
"img_2x": "https://i.vimeocdn.com/portrait/26028985_120x120.jpg",
"id": 19222589
},
"file_codecs": {
"hevc": {
"hdr": [],
"sdr": []
},
"avc": [
1047687611,
1047687609,
1047687607,
1047687604
]
},
"id": 279620511,
"embed_code": "<iframe src=\"https://player.vimeo.com/video/279620511\" width=\"640\" height=\"360\" frameborder=\"0\" allowfullscreen></iframe>",
"title": "DRAFT- MINTSHOW TO UPLIFT",
"share_url": "https://vimeo.com/279620511",
"width": 1920,
"embed_permission": "public",
"fps": 30,
"spatial": 0,
"live_event": null,
"allow_hd": 1,
"hd": 1,
"lang": null,
"default_to_hd": 0,
"url": null,
"privacy": "unlisted",
"unlisted_hash": "1795b097a5"
},
"user": {
"vimeo_api_interaction_tokens": null,
"liked": 0,
"account_type": "none",
"vimeo_api_client_token": null,
"progress": 0,
"owner": 0,
"watch_later": 0,
"logged_in": 0,
"id": 0,
"mod": 0
},
"embed": {
"autopause": 1,
"playsinline": 1,
"settings": {
"fullscreen": 1,
"byline": 1,
"like": 1,
"playbar": 1,
"title": 1,
"color": 0,
"branding": 1,
"watch_later": 1,
"share": 0,
"scaling": 1,
"spatial_compass": 1,
"collections": 0,
"info_on_pause": 0,
"portrait": 1,
"logo": 1,
"embed": 1,
"badge": 0,
"spatial_label": 1,
"speed": 0,
"volume": 1
},
"color": "00adef",
"on_site": 0,
"app_id": "",
"muted": 0,
"dnt": 0,
"player_id": "",
"api": 3,
"editor": false,
"context": "embed.main",
"time": 0,
"outro": "videos",
"log_plays": 1,
"quality": null,
"transparent": 1,
"loop": 0,
"autoplay": 0
},
"view": 1,
"vimeo_url": "vimeo.com"
}
Going off of what Andrew F had commented, I wrote this simple Javascript to handle this process:
function loadVimeoVideo(id) {
'use strict';
var req, json, url;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
req = new XMLHttpRequest();
} else { // code for IE6, IE5
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.onreadystatechange = function () {
if (req.readyState === 4 && req.status === 200) {
json = JSON.parse(req.responseText);
url = json.request.files.h264.sd.url;
document.getElementById(id).getElementsByTagName("source")[0].setAttribute("src",url);
}
};
req.open("GET", ("https://player.vimeo.com/video/").concat(id, "/config"), true);
req.send();
}
The setup in Html looks like this:
<video id="YOURVIMEOIDHERE" controls loop muted preload="auto" autoplay="false" onloadeddata="loadVimeoVideo('YOURVIMEOIDHERE')">
<source src="" type="video/mp4" />
Your browser does not support the video tag, which was introduced in html5.
</video>
Edit: I'm just going to say it, remember to replace YOURVIMEOIDHERE with your Vimeo video's id.
To Play Vimeo Video from the iframe url, use that code. It's working fine.
Use layout with Web view and frame Layout
Create a custom WebViewClient for Both ChromeClient and WebViewClient
and Play video either using Loadurl or LoadBaseUrl .
{
enter code here
webView = (WebView) findViewById(R.id.web_details);
mWebViewClient = new myWebViewClient();
webView.setWebViewClient(mWebViewClient);
mWebChromeClient = new myWebChromeClient();
webView.setWebChromeClient(mWebChromeClient);
WebSetting settings = webView.getSetting();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setMinimumFontSize(10);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
webView.setVerticalScrollBarEnabled(false);
vUrl = changedHeaderHtml(getIntent().getStringExtra("videoUrl"));
webView.loadDataWithBaseURL(null, vUrl, "text/html", "UTF-8", null);
}
public static String changedHeaderHtml(String strUrl) {
return "<head><meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" /></head>" + strUrl + "</body></html>";
}
public boolean inCustomView() {
return (mCustomView != null);
}
public void hideCustomView() {
mWebChromeClient.onHideCustomView();
}
#Override
protected void onPause() {
super.onPause(); //To change body of overridden methods use File | Settings | File Templates.
webView.onPause();
}
#Override
protected void onResume() {
super.onResume(); //To change body of overridden methods use File | Settings | File Templates.
webView.onResume();
}
#Override
protected void onStop() {
super.onStop(); //To change body of overridden methods use File | Settings | File Templates.
if (inCustomView()) {
hideCustomView();
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (inCustomView()) {
hideCustomView();
return true;
}
if ((mCustomView == null) && webView.canGoBack()) {
webView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
class myWebChromeClient extends WebChromeClient {
private Bitmap mDefaultVideoPoster;
private View mVideoProgressView;
#Override
public void onShowCustomView(View view, int requestedOrientation,CustomViewCallback callback) {
onShowCustomView(view, callback); //To change body of overridden methods use File | Settings | File Templates.
}
#Override
public void onShowCustomView(View view,CustomViewCallback callback) {
// if a view already exists then immediately terminate the new one
if (mCustomView != null) {
callback.onCustomViewHidden();
return;
}
mCustomView = view;
webView.setVisibility(View.GONE);
customViewContainer.setVisibility(View.VISIBLE);
customViewContainer.addView(view);
customViewCallback = callback;
}
#Override
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
LayoutInflater inflater = LayoutInflater.from(WebMainActivity.this);
mVideoProgressView = inflater.inflate(R.layout.video_progress, null);
}
return mVideoProgressView;
}
#Override
public void onHideCustomView() {
super.onHideCustomView(); //To change body of overridden methods use File | Settings | File Templates.
if (mCustomView == null)
return;
webView.setVisibility(View.VISIBLE);
customViewContainer.setVisibility(View.GONE);
// Hide the custom view.
mCustomView.setVisibility(View.GONE);
// Remove the custom view from its container.
customViewContainer.removeView(mCustomView);
customViewCallback.onCustomViewHidden();
mCustomView = null;
}
}
class myWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
url =vUrl;
return super.shouldOverrideUrlLoading(view, url);
}
}
}
Related
How to get some Specific data from Restapi [flutter]
I want to get only those item which contain type Lunch `` This is a function where I can fetch data from Rest Api and also ApiResponse added I need to get specific data from a session I send instead of getting the entire array from the response from the Api() method. How do I capture just the only those item which contain type Lunch from the array? { "success": true, "data": [ { "id": 6, "name": "Snack", "type": "breakfast", "detail": "18", "image": "uploads/Screenshot_2022-12-04-13-15-13-27.jpg", "carbs": 6, "proteins": 4, "fats": 8, "cal": 4, "day": 1, "created_at": null, "updated_at": null }, { "id": 7, "name": "Chicken", "type": "lunch", "detail": "White Chicken", "image": "uploads/1670258808164716637219.jpg", "carbs": 15, "proteins": 18, "fats": 10, "cal": 200, "day": 1, "created_at": null, "updated_at": null }, { "id": 8, "name": "546e57rufjvjv", "type": "lunch", "detail": "gdyhj", "image": "uploads/meat.png", "carbs": 6578, "proteins": 2345, "fats": 5678, "cal": 4325, "day": 5, "created_at": null, "updated_at": null }, { "id": 9, "name": "Anda Tikki", "type": "dinner", "detail": "Egg and Daal", "image": "uploads/1670259245043112842388.jpg", "carbs": 10, "proteins": 8, "fats": 12, "cal": 180, "day": 1, "created_at": null, "updated_at": null }, { "id": 10, "name": "Boiled egg and cucumber", "type": "breakfast", "detail": "Egg and cucumber", "image": "uploads/1670259362662817976982.jpg", "carbs": 10, "proteins": 5, "fats": 5, "cal": 100, "day": 2, "created_at": null, "updated_at": null } ], "message": "Food Data retrieved successfully." } Future<List<ProductsModel>> getProducts({String? query}) async { List<ProductsModel> products = []; var data=[]; try { String url = 'https://diet.appetitor.app/Celo/api/user/food/2000.0'; var response = await Dio().get(url, options: Options(headers: { HttpHeaders.contentTypeHeader: "application/json", })); if (response.statusCode == 200) { products.clear(); ProductsModel.fromJson(response.data); products.add(ProductsModel.fromJson(response.data)); if (query != null) { print(products.length); products = products .map((e) { e.data!.where((element) => element.type!.toLowerCase().contains('lunch')); }) .cast<ProductsModel>() .toList(); } } } on DioError catch (e) { print(e.response); } return products; } }
If the response status code returns 200 after making a request with the rest api, assign the data in it to a variable of the type of your model, then you can get it from the variable as you want.
Appium Android PointerInput LongPress code is needed
Faced error: Encountered internal error running command: io.appium.uiautomator2.common.exceptions.InvalidArgumentException: Exception while reading JSON Have coded in java and showed the appium logs here. My code: { "id": "finger", "type": "pointer", "parameters": { "pointerType": "touch" }, "actions": [ { "duration": 0, "type": "pause" }, { "duration": 0, "x": 862, "y": 747, "type": "pointerMove", "origin": "viewport" }, { "button": 0, "type": "pointerUp" } ] } ] [ { "id": "finger", "type": "pointer", "parameters": { "pointerType": "touch" }, "actions": [ { "duration": 0, "type": "pause" }, { "duration": 0, "x": 862, "y": 747, "type": "pointerMove", "origin": "viewport" }, { "button": 0, "type": "pointerUp" } ] } ]
You can use this function for long-press operation for the recent appium version without touch action and javascript. Point element_location = WebElement.getLocation(); //Getting element's location long_press(element_location);// passing the location coordinates to the long_press funcation PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); Sequence longpress = new Sequence(finger, 1); longpress.addAction(finger.createPointerMove(Duration.ofMillis(0),PointerInput.Origin.viewport(), location.x, location.y)); longpress.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); longpress.addAction(finger.createPointerMove(Duration.ofMillis(2000),PointerInput.Origin.viewport(), location.x, location.y)); longpress.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); driver.perform(Collections.singletonList(longpress));
How to extract only One object or array of Json file using Retrofit/Kotlin?
I'm new to oop and android dev and am trying to extract only a small part of this json file.I want to get back only the "heavyweight" rankings, no other weight division.. Any help would be highly appreciated! Here is my model: data class Rankings( #SerializedName("rankings") val rankings: List<Ranking> ) data class Ranking( #SerializedName("competitor_rankings") val competitorRankings: List<CompetitorRanking>, #SerializedName("name") val name: String, #SerializedName("type_id") val typeId: Int, #SerializedName("week") val week: Int, #SerializedName("year") val year: Int ) data class CompetitorRanking( #SerializedName("competitor") val competitor: Competitor, #SerializedName("rank") val rank: Int ) data class Competitor( #SerializedName("abbreviation") val abbreviation: String, #SerializedName("id") val id: String, #SerializedName("name") val name: String ) here is my api interface: #GET("ufc/trial/v2/en/rankings.json") suspend fun getRankings(#Query("api_key") api_key: String): Rankings companion object { fun create(): ApiInterface { val retrofit = Retrofit.Builder() .baseUrl("https://api.sportradar.us/") .addCallAdapterFactory(CoroutineCallAdapterFactory.invoke()) .addConverterFactory(GsonConverterFactory.create()) .build() return retrofit.create(ApiInterface::class.java) } } } here's my api call: lifecycleScope.launch(Dispatchers.IO) { val result = api.getRankings("MY_API_KEY_WILL_GO_HERE") Log.d(TAG,"${result.rankings}") } and here's my json file(I couldn't post the entire thing because of character limit, but it's essentially just 8 more rankings arrays): "rankings": [ { "type_id": 8, "name": "pound_for_pound", "year": 2020, "week": 21, "competitor_rankings": [ { "rank": 1, "movement": 0, "competitor": { "id": "sr:competitor:253371", "name": "Jones, Jon", "abbreviation": "JON" } }, { "rank": 2, "movement": 0, "competitor": { "id": "sr:competitor:250879", "name": "Nurmagomedov, Khabib", "abbreviation": "NUR" } }, { "rank": 3, "movement": 1, "competitor": { "id": "sr:competitor:237684", "name": "Miocic, Stipe", "abbreviation": "MIO" } }, { "rank": 4, "movement": 1, "competitor": { "id": "sr:competitor:410485", "name": "Adesanya, Israel", "abbreviation": "ADE" } }, { "rank": 5, "movement": 1, "competitor": { "id": "sr:competitor:253373", "name": "Cormier, Daniel", "abbreviation": "COR" } }, { "rank": 6, "movement": 1, "competitor": { "id": "sr:competitor:273539", "name": "Usman, Kamaru", "abbreviation": "USM" } }, { "rank": 7, "movement": 1, "competitor": { "id": "sr:competitor:290262", "name": "Volkanovski, Alex", "abbreviation": "VOL" } }, { "rank": 8, "movement": 1, "competitor": { "id": "sr:competitor:237676", "name": "McGregor, Conor", "abbreviation": "MCG" } }, { "rank": 9, "movement": 1, "competitor": { "id": "sr:competitor:237652", "name": "Holloway, Max", "abbreviation": "HOL" } }, { "rank": 10, "movement": 1, "competitor": { "id": "sr:competitor:351762", "name": "Gaethje, Justin", "abbreviation": "GAE" } }, { "rank": 11, "movement": 1, "competitor": { "id": "sr:competitor:261799", "name": "Poirier, Dustin", "abbreviation": "POI" } }, { "rank": 12, "movement": 1, "competitor": { "id": "sr:competitor:237646", "name": "Ferguson, Tony", "abbreviation": "FER" } }, { "rank": 13, "movement": 1, "competitor": { "id": "sr:competitor:253377", "name": "Whittaker, Robert", "abbreviation": "WHI" } }, { "rank": 14, "movement": 1, "competitor": { "id": "sr:competitor:274653", "name": "Woodley, Tyron", "abbreviation": "WOO" } }, { "rank": 15, "movement": 0, "competitor": { "id": "sr:competitor:250145", "name": "Ngannou, Francis", "abbreviation": "NGA" } } ] }, { "type_id": 16, "name": "heavyweight", "year": 2020, "week": 21, "competitor_rankings": [ { "rank": 0, "movement": 0, "competitor": { "id": "sr:competitor:237684", "name": "Miocic, Stipe", "abbreviation": "MIO" } }, { "rank": 1, "movement": 0, "competitor": { "id": "sr:competitor:253373", "name": "Cormier, Daniel", "abbreviation": "COR" } }, { "rank": 2, "movement": 0, "competitor": { "id": "sr:competitor:250145", "name": "Ngannou, Francis", "abbreviation": "NGA" } }, { "rank": 3, "movement": 0, "competitor": { "id": "sr:competitor:542009", "name": "Blaydes, Curtis", "abbreviation": "BLA" } }, { "rank": 4, "movement": 0, "competitor": { "id": "sr:competitor:237636", "name": "Dos Santos, Junior", "abbreviation": "DOS" } }, { "rank": 4, "movement": 1, "competitor": { "id": "sr:competitor:542099", "name": "Lewis, Derrick", "abbreviation": "LEW" } }, { "rank": 6, "movement": 0, "competitor": { "id": "sr:competitor:542143", "name": "Rozenstruik, Jairzinho", "abbreviation": "ROZ" } }, { "rank": 7, "movement": 0, "competitor": { "id": "sr:competitor:542161", "name": "Volkov, Alexander", "abbreviation": "VOL" } }, { "rank": 8, "movement": 0, "competitor": { "id": "sr:competitor:237694", "name": "Overeem, Alistair", "abbreviation": "OVE" } }, { "rank": 9, "movement": 0, "competitor": { "id": "sr:competitor:254231", "name": "Harris, Walt", "abbreviation": "HAR" } }, { "rank": 10, "movement": 0, "competitor": { "id": "sr:competitor:542117", "name": "Oleinik, Aleksei", "abbreviation": "OLE" } }, { "rank": 11, "movement": 0, "competitor": { "id": "sr:competitor:244080", "name": "Abdurakhimov, Shamil", "abbreviation": "ABD" } }, { "rank": 12, "movement": 0, "competitor": { "id": "sr:competitor:542079", "name": "Ivanov, Blagoy", "abbreviation": "IVA" } }, { "rank": 13, "movement": 0, "competitor": { "id": "sr:competitor:542145", "name": "Sakai, Augusto", "abbreviation": "SAK" } }, { "rank": 14, "movement": 0, "competitor": { "id": "sr:competitor:515358", "name": "Pavlovich, Sergey", "abbreviation": "PAV" } }, { "rank": 15, "movement": 0, "competitor": { "id": "sr:competitor:257349", "name": "Werdum, Fabricio", "abbreviation": "WER" } } ] },
You can just use List.first method: lifecycleScope.launch(Dispatchers.IO) { val result = api.getRankings("MY_API_KEY_WILL_GO_HERE") val ranking = result.rankings.first { it.name == "heavyweight" } }
rankings.filter { it.name == "heavyweight" } will give you a list of heavyweight rankings. But it would be much better if your API had a way to filter those results on server side i.e. adding some filtering parameter to your request rather than getting all the results and filtering them on client side.
Suggest a Future builder method for the following json
{ "totalHits": 500, "hits": [ { "largeImageURL": "https://pixabay.com/get/52e3d6414352af14f6da8c7dda79367b153fdee254506c4870277bd3934ec45ebf_1280.jpg", "webformatHeight": 424, "webformatWidth": 640, "likes": 11, "imageWidth": 4456, "id": 4332903, "user_id": 1151065, "views": 697, "comments": 14, "pageURL": "https://pixabay.com/photos/evangelion-mech-unit-02-robot-4332903/", "imageHeight": 2958, "webformatURL": "https://pixabay.com/get/52e3d6414352af14f6da8c7dda79367b153fdee254506c4870277bd3934ec45ebf_640.jpg", "type": "photo", "previewHeight": 99, "tags": "evangelion mech unit 02, robot, fighter", "downloads": 311, "user": "vinsky2002", "favorites": 0, "imageSize": 878944, "previewWidth": 150, "userImageURL": "https://cdn.pixabay.com/user/2019/05/15/02-40-06-911_250x250.png", "previewURL": "https://cdn.pixabay.com/photo/2019/07/12/13/44/evangelion-mech-unit-02-4332903_150.jpg" }, { "largeImageURL": "https://pixabay.com/get/55e7d54b4d51a514f6da8c7dda79367b153fdee254506c4870277bd3934ec45ebf_1280.jpg", "webformatHeight": 359, "webformatWidth": 640, "likes": 18, "imageWidth": 3863, "id": 3708739, "user_id": 10248012, "views": 2696, "comments": 2, "pageURL": "https://pixabay.com/photos/sky-dark-night-moon-moonlight-3708739/", "imageHeight": 2170, "webformatURL": "https://pixabay.com/get/55e7d54b4d51a514f6da8c7dda79367b153fdee254506c4870277bd3934ec45ebf_640.jpg", "type": "photo", "previewHeight": 84, "tags": "sky, dark, night", "downloads": 1036, "user": "Sritam_kumar_Sethy", "favorites": 25, "imageSize": 2027189, "previewWidth": 150, "userImageURL": "https://cdn.pixabay.com/user/2019/09/28/19-27-53-806_250x250.jpeg", "previewURL": "https://cdn.pixabay.com/photo/2018/09/28/08/37/sky-3708739_150.jpg" }, { "largeImageURL": "https://pixabay.com/get/57e2dc4a4c5aaf14f6da8c7dda79367b153fdee254506c4870277bd3934ec45ebf_1280.jpg", "webformatHeight": 360, "webformatWidth": 640, "likes": 14, "imageWidth": 4608, "id": 1299683, "user_id": 1151065, "views": 2932, "comments": 3, "pageURL": "https://pixabay.com/photos/panda-z-panda-toy-children-child-1299683/", "imageHeight": 2592, "webformatURL": "https://pixabay.com/get/57e2dc4a4c5aaf14f6da8c7dda79367b153fdee254506c4870277bd3934ec45ebf_640.jpg", "type": "photo", "previewHeight": 84, "tags": "panda-z, panda, toy", "downloads": 1067, "user": "vinsky2002", "favorites": 7, "imageSize": 1745060, "previewWidth": 150, "userImageURL": "https://cdn.pixabay.com/user/2019/05/15/02-40-06-911_250x250.png", "previewURL": "https://cdn.pixabay.com/photo/2016/04/01/09/56/panda-z-1299683_150.jpg" }, ], "total": 588 } The API I'm fetching returns json value like this. I wrote the following code to extract the data, it works if I code it like this and the widget builds, but with this error before the widget loads Future getJsonData() async{ var response; for(int i=1; i<=5; i++){ response = await http.get( Uri.encodeFull(widget.api+i.toString()), headers: {"Accept": "application/json"} ); setState(() { var toJsonData = json.decode(response.body); item.addAll(toJsonData['hits']); }); } print(response.body); return item; } error image But when I use FutureBuilder method, it fails to create the widget. It would be helpful if someone can tell a possibly working FutureBuilder method for this json data.
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 }
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'];
Convert Bean or Dio form your response like this or you can use this to convert JSON reponse to dart bean import 'dart:convert'; Welcome welcomeFromJson(String str) { final jsonData = json.decode(str); return Welcome.fromJson(jsonData); } String welcomeToJson(Welcome data) { final dyn = data.toJson(); return json.encode(dyn); } class Welcome { int status; List<Datum> data; int totalRecord; Welcome({ this.status, this.data, this.totalRecord, }); factory Welcome.fromJson(Map<String, dynamic> json) => new Welcome( status: json["status"] == null ? null : json["status"], data: json["data"] == null ? null : new List<Datum>.from(json["data"].map((x) => Datum.fromJson(x))), totalRecord: json["totalRecord"] == null ? null : json["totalRecord"], ); Map<String, dynamic> toJson() => { "status": status == null ? null : status, "data": data == null ? null : new List<dynamic>.from(data.map((x) => x.toJson())), "totalRecord": totalRecord == null ? null : totalRecord, }; } class Datum { String id; String name; String thumbnailUrl; int plays; String categories; String categoriesIds; String dataUrl; int duration; String createdAt; int status; int statusc; int mediaType; Datum({ this.id, this.name, this.thumbnailUrl, this.plays, this.categories, this.categoriesIds, this.dataUrl, this.duration, this.createdAt, this.status, this.statusc, this.mediaType, }); factory Datum.fromJson(Map<String, dynamic> json) => new Datum( id: json["id"] == null ? null : json["id"], name: json["name"] == null ? null : json["name"], thumbnailUrl: json["thumbnailUrl"] == null ? null : json["thumbnailUrl"], plays: json["plays"] == null ? null : json["plays"], categories: json["categories"] == null ? null : json["categories"], categoriesIds: json["categoriesIds"] == null ? null : json["categoriesIds"], dataUrl: json["dataUrl"] == null ? null : json["dataUrl"], duration: json["duration"] == null ? null : json["duration"], createdAt: json["createdAt"] == null ? null : json["createdAt"], status: json["status"] == null ? null : json["status"], statusc: json["statusc"] == null ? null : json["statusc"], mediaType: json["mediaType"] == null ? null : json["mediaType"], ); Map<String, dynamic> toJson() => { "id": id == null ? null : id, "name": name == null ? null : name, "thumbnailUrl": thumbnailUrl == null ? null : thumbnailUrl, "plays": plays == null ? null : plays, "categories": categories == null ? null : categories, "categoriesIds": categoriesIds == null ? null : categoriesIds, "dataUrl": dataUrl == null ? null : dataUrl, "duration": duration == null ? null : duration, "createdAt": createdAt == null ? null : createdAt, "status": status == null ? null : status, "statusc": statusc == null ? null : statusc, "mediaType": mediaType == null ? null : mediaType, }; } This method returs you Reponse bean object Future<Welcome> getMediaList() async { String url='http://xxxxxx:xxx/onnet_api/mediaList.php'; http.Response res = await http.get(url); final jsonData = json.decode(res.body); var map=Map<String, dynamic>.from(jsonData); var response=Welcome.fromJson(map); if (res.statusCode == 200) { return response; } else { throw Exception('Failed to load post'); } } Call this method like this getMediaList().then((onValue){// on value is an object ot bean class //here you will be able to get members of your bean class }) and another way is to call your service is FutureBuilder<Welcome>(); You can add header and body in http.post Post url. Future<UserResponse> loginService() async { String qaurl = "https://www.xxxxxxxxx.com/api/loginapi.html"; var body = new Map<String, String>(); //here i defined Map ty body['email'] =_email; // pe body['password'] = _password; body['return'] = 'json'; body['apikey'] = ApiKey; http.Response res = await http.post(qaurl, body: body); final jsonData = json.decode(res.body); var map=Map<String, dynamic>.from(jsonData); var loginResponse=UserResponse.fromJsonMap(map); if (res.statusCode == 200) { return loginResponse; } else { Navigator.of(context, rootNavigator: true).pop('dialog'); throw Exception('Failed to load post'); } }