It's a very simple way to google, but I haven't dealt with the Drop box
Note : Here is a simple example to illustrate the method
Follow these steps:
1-Add Dependencies :
dependencies:
googleapis: ^0.56.1
google_sign_in: ^4.5.6
2-Add these imports :
import 'package:googleapis/drive/v3.dart' as drive;
import 'package:google_sign_in/google_sign_in.dart' as signIn;
3-Google SignIn
Open main.dart, and locate the _incrementCounter() function, which is invoked when the user taps on the plus button , and edit like this :
Future<void> _incrementCounter() async {
setState(() {
_counter++;
});
final googleSignIn = signIn.GoogleSignIn.standard(scopes: [drive.DriveApi.DriveScope]);
final signIn.GoogleSignInAccount account = await googleSignIn.signIn();
print("User account $account");
}
4-Create a New Firebase Project :
You can check this to create project , and Enabled Auth Google .
5-Enable Google Drive API :
You can also go to Google Cloud Console, Look for the search bar and search for “Google Drive API”. Click “ENABLE”.
6-Upload File to Google Drive :
Create a new file, GoogleAuthClient.dart, using the http package. The GoogleAuthClient class is based on the BaseCleint, which already supports all the standard HTTP requests: POST, GET, etc. We wrap another Client inside and implement the send function where we will inject authentication header later.
import 'package:http/http.dart' as http;
class GoogleAuthClient extends http.BaseClient {
final Map<String, String> _headers;
final http.Client _client = new http.Client();
GoogleAuthClient(this._headers);
Future<http.StreamedResponse> send(http.BaseRequest request) {
return _client.send(request..headers.addAll(_headers));
}
}
Now we create a GoogleAuthClient with the auth headers from the user account above, and then use that to create a Google Drive API object DriveApi.
final authHeaders = await account.authHeaders;
final authenticateClient = GoogleAuthClient(authHeaders);
final driveApi = drive.DriveApi(authenticateClient);
Finally, let’s upload a file :
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);
print("Upload result: $result");