Flutterexperts

Empowering Vision with FlutterExperts' Expertise
Flutter With GSheets

Google Sheet is an online web spreadsheet application made by Google. Google Sheet permits shared altering continuously. Everything clients can see every one of the progressions made by different users. Google Sheets additionally support disconnected altering. It additionally upholds different document arrangements and record types eg. .xlsx, .xls, .xlt, and so on Google Sheets can likewise be integrated with other Google items.

In this article, we will explore the Flutter With GSheets. We will see how to implement a demo program to create a sample app that stores user data from the Flutter app into Google Sheets in your flutter applications.


Table Of Contents ::

Introduction

Setting up Google Sheets

Setting up Google Cloud Console

Setting up Project

Conclusion

GitHub Link


Introduction:

Hello everyone, This is my first ever article on Flutter. Google Sheets is a very powerful package if we look deep into it. It provides us with an interface using the GSheets package so that we can do various types of operations on Google Spreadsheet. We can perform all types of operations like Reading/Inserting/Updating/Deleting using the GSheets package on Google Sheets. It’s so much powerful and capable than we can even use Google Sheets as a back-end of our application. Here we’ll develop a sample flutter application So, let’s start.

Setting up Google Sheets:

  • Sign in with your Google Account.
  • Go to your Google Drive and create a new Google Sheets document where you want to store your responses and Open that.
  • Setup header columns of sheet and you’ll see like this.

As above, I’ve set up header columns of the sheet. You can see I’ve highlighted part of the URL. It is the Sheet ID of our current document. Just copy it, we’ll require it in the next step. Every document has a unique Sheet ID.

Setting up Google Cloud Console:

  • Please go to the google cloud console.
  • As in the below Image, Just click on the new project
  • After creating a new project please select that project for further configuration.
  • Then click on create a service account and choose the project for service account configuration.
  • Fill the all required fields and click on the Done button.
  • Go to the key section as shown in bellow image
  • Click on ADD KEY Dropdown menu and choose to Create New Key.
  • Then select the JSON option and Click on CREATE for generating Credentials.
  • The Credentials are automatically Downloading when you click on CREATE button

Setting up Project :

1.Package Used:

gsheets | Dart Package
A library for working with Google Sheets API v4. Manage your spreadsheets with gsheets in Dart. Basic usage sees…pub.dev

pubspec.yaml:

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
gsheets 0.3.1

2.Create Methods

  • Define Credential detail.
const _credentials = r''' The data of JSON file Downloaded when setting up google Cloud console paste here''';
//spredsheet id
const _spreadsheetId = 'Type your spredsheet id here';
  • Create _loadCredential method for load credential details.
_loadCredential() async {
gsheets = GSheets(_credentials);
ss = await gsheets.spreadsheet(_spreadsheetId);
sheet = ss.worksheetByTitle('dump');
print('Google Sheet Successfully Load');
_tableHeader();
}
  • The _tableHeader() method sets the Column name of GSheets.
_tableHeader() async {
await sheet!.values.insertValue('S no', column: 1, row: 1);
await sheet!.values.insertValue('User ID', column: 2, row: 1);
await sheet!.values.insertValue('Album ID', column: 3, row: 1);
await sheet!.values.insertValue('Album title', column: 4, row: 1);
await sheet!.values.insertValue('Year', column: 5, row: 1);
}
  • Call the _loadCredential() method in initState().
@override
void initState() {
_loadCredential();

super.initState();
}
  • Upload the data on GSheet when the user pressed the button.
_uploadData() async { await sheet.values.insertValue(_counter, column: 1, row: rowCount);
await sheet.values.insertValue('nvkdk234', column: 2, row: rowCount);
await sheet.values.insertValue('Alb43', column: 3, row: rowCount);
await sheet.values.insertValue('wedding', column: 4, row: rowCount);
await sheet.values.insertValue('2021', column: 5, row: rowCount);}
  • Call the _uploadData() method on the button pressed.

Conclusion:

In the article, I have explained how you can integrate google sheet with your flutter app. You can use the package according to your requirement. This was a small introduction to how you create a service account on the google cloud console and use that credentials to post the data on google sheets and use it in our app.

❤ ❤ Thanks for reading this article ❤❤

If I got something wrong? Let me know in the comments. I would love to improve.

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the Flutter GSheets :

GitHub – flutter-devs/flutter_gsheet
A new Flutter project. This project is a starting point for a Flutter application. A few resources to get you started…github.com


Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on Facebook, GitHub, Twitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.


Leave comment

Your email address will not be published. Required fields are marked with *.