Getting data from Google Sheets📊 → Flutter App📱 — Part 2

In this article, We’ll learn to load data from Google Sheets and show it into the list in the Flutter app.

Shreyas Patil
Jul 4, 2020 · 4 min read

Hello everyone, this is Part 2 of this series where we’ll learn to get data from Google Sheets into the Flutter app. If anyhow you missed Part 1 of this article series then here’s the link:

In the previous article, we set up Google AppScript to insert/append fields into the Google Sheet using doPost() method. Now we’ll be implementing doGet() method which will return the list of feedback responses as JSON array of objects 😃. So let’s start…

Now, Just open your Google AppScript code again and just add a new method doGet() as below.

Code.gs implementation `doGet()`

Here’s a quick ⚡️ explanation for the above script:

  • First of all, after opening Google Sheet, we’ve received all values.
  • Then iterating data in descending order so that we’ll be able to see recent feedback item first.
  • Adding each feedback to data.
  • Finally returning data as a JSON.
  • Once AppScript is ready, again deploy your AppScript by Selecting a tab: Publish → Deploy as a web app.
  • Assign a new version to your app and click ‘Deploy’ 🚀.
  • After that, you can check if it’s working or not by visiting that URL. You’ll see it like below.
URL response
  • Nice😍. This is working perfectly! Now let’s start Flutter 💙.

⚡️ Let’s Flutter 💙:

In the previous article, we’ve already done setting up the Flutter project. So let’s continue directly from there.

  • In form.dart, you can see we have a factory method called fromJson() which instantiates object from JSON. We will be using that function here in this article.
factory FeedbackForm.fromJson(dynamic json) {
return FeedbackForm(
"${json['name']}",
"${json['email']}",
"${json['mobileNo']}",
"${json['feedback']}"
);
}
  • Now just go to form_controller.dart and we’ll create a new method called getFeedbackList() which will return List of Feedback from AppScript URL via GET request which we recently created in the previous step.
  • Okay! We’re now done with data controlling part. Now let’s develop UI for it. Create another dart file for UI let’s say feedback_list.dart as below.

You can refer full code from GitHub repository here. Here I’m just showing an important part of code.

  • So this is ListView which is being populated frominitState() method once the list is loaded from the network. Once this screen is loaded, initState() will be invoked and after some seconds, you’ll see a list of responses.

We’ve done the implementation of our flutter app. Let’s test it 😄.

Run command — flutter run and see the magic! 💙

Yeah! 😍 It’s working as expected. As you can see, this data is loaded from Google Sheets using Google AppScript. Hope you liked that. If you find it helpful please share this. Maybe it’ll help someone needy!

Wanna try it right now? 🤷‍♂️

You can try the web version of this app here.

At ScaleReal We believe in Sharing and Open Source.

If you found this project useful, then please consider giving it a ⭐️ on GitHub and sharing it with your friends via social media.

Sharing is Caring!

Thank You! 😃

ScaleReal

We build applications that scale beyond reality

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store