Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

dart - Google Sheets to Flutter

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...