как использовать var _latitude
и var _longitude
как параметр в моей функции addOrderRequest()
? Обе переменные должны быть в строке,
весь код ниже, спасибо за любую помощь:)
_getCurrentLocation() async {
final position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
var _latitude = position.latitude;
var _longitude = position.longitude;
}
@override
Widget build(BuildContext context){
double width = MediaQuery.of(context).size.width;
return Scaffold(
body: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
//
],
),
),
),
bottomSheet: Container(
width: width,
height: 50.0,
child: new RaisedButton(
color: Color.fromRGBO(9, 133, 46, 100),
onPressed: () async {
addOrderRequest(titleController.text, zipCodeController.text, cityController.text, streetController.text, phoneNumberController.text, descriptionController.text, _selectedCategory);
Navigator.push(context,
MaterialPageRoute(builder: (context) => OrdersScreen()));
},
моя функция:
addOrderRequest(String title, zipCode, city, street, phoneNumber, description, category, latitude, longitude) async{
Map data = {
"title":title,
"zipCode":zipCode,
"city":city,
"street":street,
"phoneNumber":phoneNumber,
"description":description,
"category":category,
"latitude":latitude,
"longitude":longitude
};
var jsonResponse;
var url = 'http://10.0.2.2:80/order';
var response = await http.post(url, body:data);
if(response.statusCode == 200){
jsonResponse = json.decode(response.body);
print(jsonResponse);
}else{
throw new Exception("Not send data");
}
}