7/23/2023 0 Comments Google flutter consultantIt is a well-liked option for creating top-notch, quick, and attractive mobile apps for both Android and iOS platforms. Check out the repo to see how it all fits together.Google developed the open-source Flutter mobile app development framework. Media media = Media(sc.stream, data.length) Īwait (file, uploadMedia: media) Īt this point, a new file should be out in your Google Drive! Accessing other Google services should be similar to this as long as you have setup the correct scopes and API access in the Google Developer Console. List data = utf8.encode('file contents') StreamController> sc = StreamController() create data in a stream to be written to the file Here I use it to create a file out on Google Drive: //Use the AuthClient to create the class that interacts with //Google DriveĭriveApi driveApi = DriveApi(authClient) Once you have an AuthClient, you can use it to interact with Google services. create the AutoRefreshingAuthClient using previous //credentialsĪuthClient authClient = autoRefreshingClient(_clientId, creds, c) Refresh tokens do not expire (for the most part).ĪccessCredentials creds = await refreshCredentials(ĪccessCredentials(accessToken, refreshToken, scopes), create the access token (even if it's expired)ĪccessToken accessToken = AccessToken(type, data, yParse(expiry)) String refreshToken = await _storage.read(key: 'refreshToken') String expiry = await _storage.read(key: 'expiry') String type = await _storage.read(key: 'type') String data = await _storage.read(key: 'accessToken') Here is an example on how to create the AutoRefreshingAuthClient: //pull data out of secure storage One of the implementations is AutoRefreshingAuthClient which handles an expired access token automatically by using the refresh token to get another access token. The Dart library for interacting with Google services expects an AuthClient from the Google API Auth library to make the calls to those services. Note: Be sure to read about this library and its problems with automatic backups here and here if you decide to use this library in a production application. That way, after the user has been away from the app for some time, the app can use the refresh token provided to get a new access token and not have to go through the authentication process again. This works like the shared_preferences library but encrypts the data. See the AndroidManifest.xml in the repository for an example.Īfter receiving the tokens back, I used flutter_secure_storage to store them. On Android it does this using an intent filter. After the consent screen, it redirects the user back to the application. I had to find another solution.įor my second attempt, I found the library flutter_web_auth. However, once you have completed the consent process, there isn’t a way to have it redirect back to your app (at least on Android). You give it the url to start the OAuth process, it opens it up in a browser, and you go through the consent process. Create credentials (Client ID in this case).įor my first attempt at making the authentication part of the process work, I used a library called url_launcher.Select the APIs you want to use (Google Drive in this case).Create a project in the Google Developer Console.The README in the repository goes into detail what to do and there are a number of tutorials online on how to create a Client ID for an application if you get stuck. After cloning this project, there is a fair amount of setup required to get it to work. I started wondering if I could write the file out to Google Drive so then it could be saved out “in the cloud”. One of the apps has basic export functionality that just writes a file to the application directory, which can be hard to find for the average user. I’ve been interested with Flutter for a couple of years and have written some simple apps to try it out.
0 Comments
Leave a Reply. |