2

I am trying to read and write data to google sheets in a Flutter application, but I can't figure out how to. I have not been able to find any documentation or examples for this issue. I am also fairly new to both Flutter / Dart and the Google API so I do not really know what I am doing.

Any help would be massively appreciated! Thanks so much.

  • 2
    You are using google sheets V4? Hope [this](https://stackoverflow.com/a/46466452/1785285) answer will help you – Narkhede Tushar Jun 03 '19 at 04:21
  • 1
    Does this answer your question? [Google Sheets API v4 for Flutter/Dart](https://stackoverflow.com/questions/46466410/google-sheets-api-v4-for-flutter-dart) – Maks Feb 27 '20 at 01:37

1 Answers1

0

Here's how you can read spreadhseets from Google Sheets using googleapis package. Note that this requires the use of googleapis_auth package for authentication.

Future readSpreadSheet() async {
  final httpClient = await clientViaApplicationDefaultCredentials(scopes: [
    StorageApi.devstorageReadOnlyScope,
  ]);
  try {
    final spreadsheetApi = SheetsApi(httpClient);
    spreadsheetApi.spreadsheets.get(spreadsheetId).then((Spreadsheet spreadsheet) {
      // Handle Spreadsheet
      // https://pub.dev/documentation/googleapis/latest/sheets.v4/Spreadsheet-class.html
    }).onError((error, stackTrace) {
      debugPrint('$error: $stackTrace');
    });
  } finally {
      httpClient.close();
  }
}

For fetching the spreadsheetId, you'll be needing to use drive.v3 API from googleapis package.

Omatt
  • 8,564
  • 2
  • 42
  • 144