'Showing Error (The operator '+' isn't defined for the type 'Uri'. Try defining the operator '+'.dart (undefined_operator))
THIS IS MY CODE
this is the app for storing data into google spreadsheets.
// showing red line under plus OPERATOR '+'
in LINE
import 'dart:convert' as convert;
import 'package:store_data/models/update.dart';
import 'package:http/http.dart' as http;
class FormController {
// Callback function to give response of status of current request.
final void Function(String) callback;
var url = Uri.parse('https://script.google.com/macros/s/AKfycbzFd5Cw0itASDzFgIrdr97j8PbfWHw1iVcoJWhbChPKfO2c2sA/exec');
static const STATUS_SUCCESS = "SUCCESS";
FormController(this.callback);
void submitForm(Update update) async{
try{
await http.get(
url + update.toParams()).then(
(response){
callback(convert.jsonDecode(response.body)['status']);
});
} catch(e){
print(e);
}
}
}'
Solution 1:[1]
I'm not sure.Try
var url ='...';
then
void submitForm(Update update) async{
url+=update.toParams();
Uri uri = Uri.paste(url);
try{
await http.get(
uri).then(
(response){
callback(convert.jsonDecode(response.body)['status']);
});
} catch(e){
print(e);
}
Solution 2:[2]
You can try
var url =
'https://script.google.com/macros/s/AKfycbzFd5Cw0itASDzFgIrdr97j8PbfWHw1iVcoJWhbChPKfO2c2sA/exec';
static const STATUS_SUCCESS = "SUCCESS";
void submitForm(Update update) async {
try {
await http.get(Uri.parse(url + update.toParams()).then((response) {
callback(convert.jsonDecode(response.body)['status']);
}));
} catch (e) {
print(e);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Minh Nguyên |
Solution 2 | Grimmret |