Wednesday, 15 April 2015

google drive sdk - How to handle if else in Dart Future -



google drive sdk - How to handle if else in Dart Future -

i need google drive folder's fileid. if folder not exist, need create folder name , homecoming fileid. fileid, need other works.

the google drive api in dart ok me, can create folder dart. question future. code follow:

class="lang-dart prettyprint-override"> drive.files.list(q:"title='test'").then((result){ if(result.items.length == 0) { driveclient.file file = new driveclient.file.fromjson({"title":"test", "mimetype": "application/vnd.google-apps.folder"}); drive.files.insert(file).then((result2) { homecoming result2.id; }); } else { homecoming result.items[0].id; } });

when test exists, id returned. if test doesn't, function error because no return.

how that?

thanks in advance.

you need homecoming future method phone call in line 4:

class="lang-dart prettyprint-override">drive.files.list(q:"title='test'").then((result){ if(result.items.length == 0) { driveclient.file file = new driveclient.file.fromjson({"title":"test", "mimetype": "application/vnd.google-apps.folder"}); homecoming drive.files.insert(file).then((result2) { homecoming result2.id; }); } else { homecoming result.items[0].id; } });

then() returns new future there completes value returned method give parameter method. then() smart plenty resolve nested future's handle value within then() method , never instance of future.

dart google-drive-sdk

No comments:

Post a Comment