Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

Flutter Send a post request while waiting for gps data

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

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...