a-marenkov / gsheets

A Dart library for working with Google Sheets API.
Other
79 stars 31 forks source link

No such Method Error #13

Closed rankdhaval04 closed 4 years ago

rankdhaval04 commented 4 years ago

here is my error E/flutter ( 6230): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'rowCount' was called on null. E/flutter ( 6230): Receiver: null E/flutter ( 6230): Tried calling: rowCount E/flutter ( 6230): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) E/flutter ( 6230): #1 main (package:flutterapp/main.dart:29:21) E/flutter ( 6230): <asynchronous suspension> E/flutter ( 6230): #2 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:239:25) E/flutter ( 6230): #3 _rootRun (dart:async/zone.dart:1126:13) E/flutter ( 6230): #4 _CustomZone.run (dart:async/zone.dart:1023:19) E/flutter ( 6230): #5 _runZoned (dart:async/zone.dart:1518:10) E/flutter ( 6230): #6 runZoned (dart:async/zone.dart:1502:12) E/flutter ( 6230): #7 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:231:5) E/flutter ( 6230): #8 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:307:19) E/flutter ( 6230): #9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12) E/flutter ( 6230): ****

here is my code: `import 'package:gsheets/gsheets.dart';

// your google auth credentials const _credentials = r''' { "type": "service_account", "project_id": "sadhyastudycenterapp", "private_key_id": "57a9457a78f73c572c03e533bf601c710e9ffef0", "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDV3ihCk4trPKyR\nCUpox3aVxrVfnAxltyyRTN6KbbmdcVDc/vqFjYiEHE7PLpyazo6FW/MbOrDKhgVb\nDS3jcdxmaHPbYutNnyEneyhpzpQqtwzRwyafVdjV0st575h4MJdHuDtqd/ddEe8V\ntLteVsn1tR9Q0x5YlyBMgjWnDUY+LY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1s6iwE2bAEBAoGAA5Dp\n94EzaeIYb6gAlzNW6eJka/h/IwmnXf9My64G47dq4M3tkmPDEhv9ETgFwFA32T69\nnG6oKmTEKriCXpk5xOTWkbvzvby0zDuUyRO1HygB+oH5RbJLf2OZ03MZIh3l+Sip\nLDNXeHhOqbj2InROOL0rGktoi2529jOoxA9vDB0CgYBU1fwtRlhVy2blscBe+cAz\nfi0lAhLyA07mKh+60V0U+07VRg9keXAJcQeydaoaAta4GHUQMfgGJbRTpXoS5jcu\nbGpZuIEWDIwOfLeaPgNB+aLGxU2RQJ6lwpx/2pwue354hC8pEWmQH/yTpZ8+Q8Gb\nY8qRuOEu/+1uEDEpQ7WkoQ==\n-----END PRIVATE KEY-----\n", "client_email": "sadhyastudycenter@sadhyastudycenterapp.iam.gserviceaccount.com", "client_id": "105341061440539056918", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/sadhyastudycenter%40sadhyastudycenterapp.iam.gserviceaccount.com" } ''';

const _spreadsheetId = '1HDiwYoC5-l6ESQ8cOPCWnQgXnVS1ys2ZGc5EhCHkQmQ';

void main() async { // init GSheets final gsheets = GSheets(_credentials); // fetch spreadsheet by its id final ss = await gsheets.spreadsheet(_spreadsheetId); // get worksheet by its title var sheet = await ss.worksheetByTitle('maths');

print(await sheet.rowCount); }`

piecubed commented 4 years ago

Hi! Please edit your answer to redact your credentials @rankdhaval04

piecubed commented 4 years ago

Please make sure that your worksheet title is correct, I believe this is case sensitive. Feel free to @ me or a-marenkov if you have any more problems.

piecubed commented 4 years ago

Also, consider regenerating your google service account credentials @rankdhaval04

a-marenkov commented 4 years ago

@rankdhaval04

Hi did you solve the issue?

Zorro-cristal commented 4 years ago

Hi, i have a similar problem. "The getter 'values' was called on null" and I almost checking the name and credentials @piecubed

a-marenkov commented 4 years ago

Hi, i have a similar problem. "The getter 'values' was called on null" and I almost checking the name and credentials @piecubed

Hi, make sure you use correct spreadsheetId and the spreadsheet already contains the worksheet that you're trying to use.

If everything is correct, could you please provide minimal example that produces the error.

rankdhaval04 commented 4 years ago

No i have still facing the same issue.

On Thu, Jun 4, 2020, 3:29 AM Zorro-cristal notifications@github.com wrote:

Hi, i have a similar problem. "The getter 'values' was called on null" and I almost checking the name and credentials

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/a-marenkov/gsheets/issues/13#issuecomment-638483603, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJNOH67LHOKSK5JGVDYPS5TRU3BULANCNFSM4M6PD5GQ .

a-marenkov commented 4 years ago

No i have still facing the same issue. On Thu, Jun 4, 2020, 3:29 AM Zorro-cristal @.***> wrote: Hi, i have a similar problem. "The getter 'values' was called on null" and I almost checking the name and credentials — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#13 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJNOH67LHOKSK5JGVDYPS5TRU3BULANCNFSM4M6PD5GQ .

Looking at the example you've provided, it seems that you either using wrong spreadsheetId or wrong title (it must be exactly the same as in spreadsheet including case of the letters, any special charachters and spaces).

I'd suggest you to try following:

void main() async {
  final gsheets = GSheets(_credentials);
  final ss = await gsheets.spreadsheet(_spreadsheetId);
  final ws = ss.worksheetByIndex(0);
  /// see what title it prints (using *** to catch any leading or following white spaces)
  print('***${ws.title}***');
}

Call worksheetByIndex with the index of the worksheet you are interested in.

Can you please let me know if it helps

a-marenkov commented 4 years ago

No i have still facing the same issue. On Thu, Jun 4, 2020, 3:29 AM Zorro-cristal @.***> wrote: Hi, i have a similar problem. "The getter 'values' was called on null" and I almost checking the name and credentials — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#13 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJNOH67LHOKSK5JGVDYPS5TRU3BULANCNFSM4M6PD5GQ .

I've just checked the spreadsheet you referenced. It does not contain maths worksheet, it only has worksheet named 'Sheet1'

Zorro-cristal commented 4 years ago

If I use ss.worksheetByTitle("stock"); it not work but if I use ss.worksheetByIndex(0); works. Thats why happens? I have the sheet whith the name "stock" and columns called "producto" and "precio"

a-marenkov commented 4 years ago

If I use ss.worksheetByTitle("stock"); it not work but if I use ss.worksheetByIndex(0); works. Thats why happens? I have the sheet whith the name "stock" and columns called "producto" and "precio"

worksheetByTitle should work as long as you pass title that is exactly the same as in spreadsheet.

Can you please check that "stock" is written exactly the same way? I'm not sure, but maybe you use Spanish characters in spreadsheet and English characthers in worksheetByTitle.

Zorro-cristal commented 4 years ago

imagen Here is a screenshoot of my document

a-marenkov commented 4 years ago

imagen Here is a screenshoot of my document

I see the confusion. The "stock" is not the title of a worksheet, it's a name of a spreadsheet (spreadsheet retrived by id).

See below - "products" and "example" are the worksheet titles.

image