I'm stuck on my flutter project, I want to send the gps coordinate every time the user open the app to check if its position is on specific place referenced on my base (if yes it send a notification). I have two futures, one of which is dependent on the other (sending needs gps data).
import 'package:http/http.dart' as http;
import 'package:location/location.dart';
import 'dart:convert';
class Islandmenu extends StatelessWidget {
Widget build(BuildContext context) {
......
}
Future<void>getgpscoordinates() async{
final locdata = await Location().getLocation();
List<double> gps= [locdata.latitude,locdata.longitude];
return gps;
}
Future<void>checkUser(gps) async{
const String userurl="*********/input_dbco.php";
final response = await http.post(userurl, body:jsonEncode({
"id": "",
"gps":[gps[0],gps[1]],
"dateco": "",
}));
return response;
}
}//end of class
but it's make my VM crash so i guess i do it in the wrong way ^^.
question from:
https://stackoverflow.com/questions/65884147/flutter-send-a-post-request-while-waiting-for-gps-data 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…