I have created a function that is implemented in my flutter app, I set up all the configurations in the google cloud console for uploading files to google drive API. My function looks like this
Future<void> uploadFileOnDrive() async {
try {
//auth credentials
final googleSignIn =
signIn.GoogleSignIn.standard(scopes: [drive.DriveApi.driveScope]);
final signIn.GoogleSignInAccount? account = await googleSignIn.signIn();
// print("User account $account");
final authHeaders = await account!.authHeaders;
final authenticateClient = GoogleAuthClient(authHeaders);
final driveApi = drive.DriveApi(authenticateClient);
//Uploading the file with "hi" text
final Stream<List<int>> mediaStream =
Future.value([104, 105]).asStream().asBroadcastStream();
var media = new drive.Media(mediaStream, 2);
var driveFile = new drive.File();
driveFile.name = "hello_world.txt";
final result = await driveApi.files.create(driveFile, uploadMedia: media);
//printing the values
print(result.driveId);
print(result.name);
print(result.id);
print(result.createdTime);
print("Upload result: $result");
Fluttertoast.showToast(msg: "Uploaded succesfully");
} catch (e) {
Fluttertoast.showToast(msg: e.toString());
}
}
This function is uploading files successfully on my drive but I need to edit these files for which I need their ID. The result contains the Instance of 'file' but when I try to print the result.driveId, I get null value but result.name is printing "hello_world.txt" correctly and result.id is also printing some id which is not the actual id of the "hello_world.txt" file (I checked the URL, it does not match). Am I doing anything wrong here? Please correct me. Thanks