0

we are new to Flutter. We have a Google Sheet with data and would like to import that data to a Flutter App.

We tried this: https://patilshreyas.github.io/Flutter2GoogleSheets-Demo/demo/

In the above link, you can find :

a. The test Google Sheet: https://docs.google.com/spreadsheets/d/1OOArrqjOqmD4GiJOWlluZ4woTMH_qaV6RKv4JXnT3Hk/edit#gid=0

b. the code from Git Hub: https://github.com/PatilShreyas/Flutter2GoogleSheets-Demo

c. The Google AppScript code is:

    `
     function doGet(request){
     // Open Google Sheet using ID
     var sheet =      
     SpreadsheetApp.openById("1OOArrqjOqmD4GiJOWlluZ4woTMH_qaV6RKv4JXnT3Hk");

  // Get all values in active sheet
  var values = sheet.getActiveSheet().getDataRange().getValues();
  var data = [];

  // Iterate values in descending order 
  for (var i = values.length - 1; i >= 0; i--) {

  // Get each row
  var row = values[i];

// Create object
var feedback = {};

feedback['name'] = row[0];
feedback['email'] = row[1];
feedback['mobile_no'] = row[2];
feedback['feedback'] = row[3];

// Push each row object in data
data.push(feedback);
   }

   // Return result
   return ContentService
  .createTextOutput(JSON.stringify(data))
  .setMimeType(ContentService.MimeType.JSON);
   }


  function doPost(request){
  // Open Google Sheet using ID
  var sheet = SpreadsheetApp.openById("1OOArrqjOqmD4GiJOWlluZ4woTMH_qaV6RKv4JXnT3Hk");
  var result = {"status": "SUCCESS"};
  try{
  // Get all Parameters
  var name = request.parameter.name;
  var email = request.parameter.email;
  var mobileNo = request.parameter.mobileNo;
  var feedback = request.parameter.feedback;

// Append data on Google Sheet
var rowData = sheet.appendRow([name, email, mobileNo, feedback]);

 }catch(exc){
  // If error occurs, throw exception
  result = {"status": "FAILED", "message": exc};
 }

 // Return result
 return 
 ContentService.createTextOutput(JSON.stringify(result)).setMimeType(ContentService.MimeType.JSON);
 }`

But, on running the code, we get the error: E/flutter (23836): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: SocketException: Failed host lookup: 'script.google.com' (OS Error: No address associated with hostname, errno = 7)

Would you please advise us on how we can resolve this error.

Ashok
  • 69
  • 1
  • 8

1 Answers1

1

You can try to follow this case having the same issue as yours:

How to solve SocketException: Failed host lookup: 'www.xyz.com' (OS Error: No address associated with hostname, errno = 7)

There are many answers there that can help you solve your problem.

Monique G.
  • 239
  • 1
  • 6
  • Thank you Monique! The link you shared was very useful. Two things worked from the link you shared: 1. added to AndroidManifest.xml 2. Wipe data from Emulator and restart. – Ashok Jan 06 '21 at 06:55
  • You're welcome! It's great to hear that it helped you, @Ashok! – Monique G. Jan 06 '21 at 16:27