Slash in worksheet title problem
CrossLeaf opened this issue · 6 comments
E/flutter (13231): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: FormatException: Unexpected character (at character 1)
E/flutter (13231): <!DOCTYPE html>
E/flutter (13231): ^
E/flutter (13231):
E/flutter (13231): #0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1394:5)
E/flutter (13231): #1 _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1261:9)
E/flutter (13231): #2 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:926:22)
E/flutter (13231): #3 _parseJson (dart:convert-patch/convert_patch.dart:31:10)
E/flutter (13231): #4 JsonDecoder.convert (dart:convert/json.dart:495:36)
E/flutter (13231): #5 JsonCodec.decode (dart:convert/json.dart:153:41)
E/flutter (13231): #6 jsonDecode (dart:convert/json.dart:96:10)
E/flutter (13231): #7 checkResponse (package:gsheets/src/utils.dart:68:18)
E/flutter (13231): #8 Worksheet._get (package:gsheets/src/gsheets.dart:914:5)
E/flutter (13231): <asynchronous suspension>
E/flutter (13231): #9 WorksheetAsValues.column (package:gsheets/src/gsheets.dart:1093:16)
E/flutter (13231): <asynchronous suspension>
E/flutter (13231): #10 WorksheetAsCells.column (package:gsheets/src/gsheets.dart:3049:35)
In gsheets.dart
Future<List<String>> _get(String range, String dimension) async {
final response = await _client.get(
'$_sheetsEndpoint$spreadsheetId/values/$range?majorDimension=$dimension&valueRenderOption=$renderOption',
);
checkResponse(response);
final list = (jsonDecode(response.body)['values'] as List)?.first as List;
return list?.map(parseValue)?.toList() ?? <String>[];
}
Maybe needs to handle the splash in range?
My worksheet title is '4/29(三)九龍港式'
I add the line to encode range in URL
var rangeEncode = Uri.encodeComponent(range);
Line: 831
Future<bool> _clear(String range) async {
var rangeEncode = Uri.encodeComponent(range);
final response = await _client.post(
'$_sheetsEndpoint$spreadsheetId/values/$rangeEncode:clear',
);
checkResponse(response);
return response.statusCode == 200;
}
Line: 912
Future<List<String>> _get(String range, String dimension) async {
var rangeEncode = Uri.encodeComponent(range);
final response = await _client.get(
'$_sheetsEndpoint$spreadsheetId/values/$rangeEncode?majorDimension=$dimension&valueRenderOption=$renderOption',
);
checkResponse(response);
final list = (jsonDecode(response.body)['values'] as List)?.first as List;
return list?.map(parseValue)?.toList() ?? <String>[];
}
Line: 922
Future<List<List<String>>> _getAll(String range, String dimension) async {
var rangeEncode = Uri.encodeComponent(range);
final response = await _client.get(
'$_sheetsEndpoint$spreadsheetId/values/$rangeEncode?majorDimension=$dimension&valueRenderOption=$renderOption',
);
checkResponse(response);
final values = jsonDecode(response.body)['values'] as List;
if (values == null) return <List<String>>[];
final list = <List<String>>[];
for (var sublist in values) {
list.add((sublist as List)?.map(parseValue)?.toList() ?? <String>[]);
}
return list;
}
Line: 942
Future<bool> _update({
List<dynamic> values,
String majorDimension,
String range,
}) async {
checkNotNested(values);
var rangeEncode = Uri.encodeComponent(range);
final response = await _client.put(
'$_sheetsEndpoint$spreadsheetId/values/$rangeEncode?valueInputOption=$inputOption',
body: jsonEncode(
{
'range': range,
'majorDimension': majorDimension,
'values': [values],
},
),
);
checkResponse(response);
return response.statusCode == 200;
}
Line: 962
Future<bool> _updateAll({
List<List<dynamic>> values,
String majorDimension,
String range,
}) async {
var rangeEncode = Uri.encodeComponent(range);
final response = await _client.put(
'$_sheetsEndpoint$spreadsheetId/values/$rangeEncode?valueInputOption=$inputOption',
body: jsonEncode(
{
'range': range,
'majorDimension': majorDimension,
'values': values,
},
),
);
checkResponse(response);
return response.statusCode == 200;
}
Hi! Thanks for checking out gsheets library and providing feedback! Also thanks for suggesting the solution!
I have added encoding of title in requsting ranges.
Could you please check gsheets 0.2.2 and let me know that everything works now?
Thanks!
Still have an exception.
E/flutter (16182): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: GSheetsException: Request range['5/4(一)'!B1:B1] does not match value's range['5%2F4%28%E4%B8%80%29'!B1:B1]
E/flutter (16182): #0 checkResponse (package:gsheets/src/utils.dart:69:5)
E/flutter (16182): #1 Worksheet._update (package:gsheets/src/gsheets.dart:949:5)
E/flutter (16182): <asynchronous suspension>
E/flutter (16182): #2 WorksheetAsValues.insertValue (package:gsheets/src/gsheets.dart:1429:16)
The value of 'range' in JSON body should be original data.
body: jsonEncode(
{
'range': range,
'majorDimension': majorDimension,
'values': [values],
},
)
Still have an exception.
E/flutter (16182): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: GSheetsException: Request range['5/4(一)'!B1:B1] does not match value's range['5%2F4%28%E4%B8%80%29'!B1:B1] E/flutter (16182): #0 checkResponse (package:gsheets/src/utils.dart:69:5) E/flutter (16182): #1 Worksheet._update (package:gsheets/src/gsheets.dart:949:5) E/flutter (16182): <asynchronous suspension> E/flutter (16182): #2 WorksheetAsValues.insertValue (package:gsheets/src/gsheets.dart:1429:16)
The value of 'range' in JSON body should be original data.
body: jsonEncode( { 'range': range, 'majorDimension': majorDimension, 'values': [values], }, )
Oh... my bad... obviosly range isn't always used as a query parameter. I'll fix it shortly. Thanks!
Still have an exception.
E/flutter (16182): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: GSheetsException: Request range['5/4(一)'!B1:B1] does not match value's range['5%2F4%28%E4%B8%80%29'!B1:B1] E/flutter (16182): #0 checkResponse (package:gsheets/src/utils.dart:69:5) E/flutter (16182): #1 Worksheet._update (package:gsheets/src/gsheets.dart:949:5) E/flutter (16182): <asynchronous suspension> E/flutter (16182): #2 WorksheetAsValues.insertValue (package:gsheets/src/gsheets.dart:1429:16)
The value of 'range' in JSON body should be original data.
body: jsonEncode( { 'range': range, 'majorDimension': majorDimension, 'values': [values], }, )
Could you please check gsheets 0.2.3 and let me if it's ok now?
Sorry, about first attempt. I should've paid more attention...
Thanks!
Thanks!
It doesn't have any problem.