Using dart g.sheets package how do i display all rows of the sheet

62 Views Asked by At

I am very new to coding and trying to learn. However, I have got stuck with trying to read existing data from google sheets using the g.sheets package.

Inside the Gsheets Api file, I currently have

/// Get all tasks 
 static Future<List<Task>> getAll() async {

/// check if TaskSheet is available, if not return an empty list of ///Tasks

if (_Tasks == null) return <Task>[];
/// if Tasksheet available then load list of notes

final tasks = await _Tasks!.values.map.allRows();

/// if task list is null return empty list or map list to task object

return tasks == null ? <Task>[] : tasks.map(Task.fromJson).toList();
}

Inside the task database file, I have

class TaskDatabase {List toDoList = [];
//load the data from database
Future loadData() async {toDoList = await GoogleSheetsApi.getAll();
}
}

Inside the Landing Page (Where the tasks will be displayed and created

`class TasksLandingPage extends StatefulWidget {
const TasksLandingPage({Key? key}) : super(key: key);
@override
State<TasksLandingPage> createState() => _TasksLandingPageState();}
class _TasksLandingPageState extends State<TasksLandingPage> {
// text controller
final _controller = TextEditingController();
// list of ToDo tasks

TaskDatabase tdb = TaskDatabase();
@override

void initState() {
super.initState();tdb.loadData();
}
//save new task

void saveNewTask() {
setState((){tdb.toDoList.add(_controller.text);
_controller.clear();});
Navigator.of(context).pop();
}
// create new tasks

void createNewTask() {
showDialog(
context: context,
builder: (context) {
return DialogBox(controller: _controller,
onCancel: () => Navigator.of(context).pop(),
onSave: saveNewTask,
);
},
);
}
// delete taskvoid deleteTask(int index) {
setState(() {
tdb.toDoList.removeAt(index);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Tasks '),
elevation: 20,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
createNewTask();
},
child: Icon(Icons.add),
),
body: ListView.builder(
itemCount: tdb.toDoList.length,
itemBuilder: (context, index) {
return TaskTile(
taskName: tdb.toDoList[index],
taskCompleted: tdb.toDoList[index],
onChanged: (p0) {} //Unused code at this time,
deleteFunction: (context) => deleteTask(index),
);
},
),
);
}
}`

When I reload the app the existing rows in the spreadsheet don't display. Any help is appreciated.

0

There are 0 best solutions below