Closed FarsFuad closed 4 years ago
Hi @FarsFuad
There are several mistakes in your code.
I'd suggest you to reead this article.
class GSheet {
GSheets gsheets = GSheets(credentials);
Spreadsheet ss;
Worksheet sheet;
Future getStarted() async {
// fetch spreadsheet by its id
ss ??= await gsheets.spreadsheet(spreadsheetId);
// get worksheet by its title
sheet ??= ss.worksheetByTitle('number1');
}
}
refreshButton() async {
await gSheet.getStarted();
final card=[];
final dones = await gSheet.sheet.vlaues.row(4);
for(var i = 0; i < dones.length; i++) {
if(dones[i] == 'Done') {
final temp = await gSheet.sheet.vlaues.column(i + 1)
card.add(createCard(temp[0], temp[1], temp[2]))
}
}
setState(() {
this.card = card;
});
}
@FarsFuad Hi! Did you figure out the way to solve it?
yes , thanks soo much !! <3
I am using gSheet package and i stock on an error, the problem is unknown but i think its a bad use of anyc programming , here is my code :
import 'package:flutter/material.dart'; import 'package:gsheets/gsheets.dart'; import 'GSheet.dart'; import 'Comuntes.dart';
GSheet gSheet = GSheet(); void main() { runApp(MyApp()); }
class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); }
class _MyAppState extends State { @override void initState() { super.initState(); gSheet.getStarted(); }
List card = [];
createCard(String name, String phone, String order) {
return Card(
child: Row(
children: [
Text(name),
SizedBox(
width: 10,
),
Text(phone),
SizedBox(
width: 10,
),
Text(order),
],
),
);
}
refreshButton() async { int row=4,colm=1; card=[]; while(await gSheet.sheet.cells.cell(column: colm, row: row).toString() != null) {
if(await gSheet.sheet.cells.cell(column: colm, row: row).toString() == 'Done') colm++; else { String name = (await gSheet.sheet.cells.cell(column: colm, row: 1)) as String; String phone = (await gSheet.sheet.cells.cell(column: colm, row: 2)) as String; String order = (await gSheet.sheet.cells.cell(column: colm, row: 3)) as String; card.add(createCard(name, phone, order)); colm++; } } }
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(actions: [GestureDetector(child: Icon(Icons.add ,), onTap: refreshButton,)],), body: SafeArea( child: Column( children: [ Expanded( child: Column(children: card), ), ], ), ), ), ); } }
gSheet class :
class GSheet { GSheets gsheets; Spreadsheet ss; Worksheet sheet;
Future getStarted() async { // init GSheets final gsheets = GSheets(credentials); // fetch spreadsheet by its id final ss = await gsheets.spreadsheet(spreadsheetId); // get worksheet by its title final sheet = ss.worksheetByTitle('number1'); } }
please help , and thanks.
full error code :
error code : E/flutter (28502): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'cells' was called on null. E/flutter (28502): Receiver: null E/flutter (28502): Tried calling: cells E/flutter (28502): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) E/flutter (28502): #1 _MyAppState.refreshButton (package:manychatgooglesheet/main.dart:47:30) E/flutter (28502): #2 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) E/flutter (28502): #3 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11) E/flutter (28502): #4 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5) E/flutter (28502): #5 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:217:7) E/flutter (28502): #6 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9) E/flutter (28502): #7 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12) E/flutter (28502): #8 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:122:9) E/flutter (28502): #9 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8) E/flutter (28502): #10 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18) E/flutter (28502): #11 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7) E/flutter (28502): #12 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19) E/flutter (28502): #13 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22) E/flutter (28502): #14 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) E/flutter (28502): #15 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7) E/flutter (28502): #16 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7) E/flutter (28502): #17 _rootRunUnary (dart:async/zone.dart:1196:13) E/flutter (28502): #18 _CustomZone.runUnary (dart:async/zone.dart:1085:19) E/flutter (28502): #19 _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7) E/flutter (28502): #20 _invoke1 (dart:ui/hooks.dart:275:10) E/flutter (28502): #21 _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)