Skip to content

Instantly share code, notes, and snippets.

View ShivamGoyal1899's full-sized avatar
🎖️
finishing the todo list, one task at a time.

Shivam Goyal ShivamGoyal1899

🎖️
finishing the todo list, one task at a time.
View GitHub Profile
<!-- Google Sign-in Section -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>COPY_REVERSE_CLIENT_ID_HERE</string>
</array>
Future<void> _createTrip(BuildContext context) async {
// Display the loading indicator.
setState(() => _isLoading = true);
await ScopedModel.of<PhotosLibraryApiModel>(context)
.createAlbum(tripNameFormController.text)
.then((Album album) {
// Hide the loading indicator.
setState(() => _isLoading = false);
Future<Album> createAlbum(String title) async {
return client
.createAlbum(CreateAlbumRequest.fromTitle(title))
.then((Album album) {
updateAlbums();
return album;
});
}
Future<Album> createAlbum(CreateAlbumRequest request) async {
return http
.post(
'https://photoslibrary.googleapis.com/v1/albums',
body: jsonEncode(request),
headers: await _authHeaders,
)
.then(
(Response response) {
if (response.statusCode != 200) {
Future<ListAlbumsResponse> listAlbums() async {
return http
.get(
'https://photoslibrary.googleapis.com/v1/albums?'
'excludeNonAppCreatedData=true&pageSize=50',
headers: await _authHeaders)
...
}
Future _getImage(BuildContext context) async {
// Use the image_picker package to prompt the user for a photo from their
// device.
final File image = await ImagePicker.pickImage(
source: ImageSource.camera,
);
// Store the image that was selected.
setState(() {
_image = image;
Future<String> uploadMediaItem(File image) async {
// Get the filename of the image
final String filename = path.basename(image.path);
// Set up the headers required for this request.
final Map<String, String> headers = <String,String>{};
headers.addAll(await _authHeaders);
headers['Content-type'] = 'application/octet-stream';
headers['X-Goog-Upload-Protocol'] = 'raw';
headers['X-Goog-Upload-File-Name'] = filename;
// Make the HTTP request to upload the image. The file is sent in the body.
Future<BatchCreateMediaItemsResponse> createMediaItem(
String uploadToken, String albumId, String description) {
// Construct the request with the token, albumId and description.
final BatchCreateMediaItemsRequest request =
BatchCreateMediaItemsRequest.inAlbum(uploadToken, albumId, description);
// Make the API call to create the media item. The response contains a
// media item.
return client
.batchCreateMediaItems(request)
Future<void> _shareAlbum(BuildContext context) async {
// Show the loading indicator
setState(() {
_inSharingApiCall = true;
});
final SnackBar snackBar = SnackBar(
duration: Duration(seconds: 3),
content: const Text('Sharing Album...'),
);
Scaffold.of(context).showSnackBar(snackBar);
void _showShareableUrl(BuildContext context) {
if (album.shareInfo == null || album.shareInfo.shareableUrl == null) {
print('Not shared, sharing album first.');
// Album is not shared yet, share it first, then display dialog
_shareAlbum(context).then((_) {
_showUrlDialog(context);
});
} else {
// Album is already shared, display dialog with URL
_showUrlDialog(context);