skip to Main Content

I am new in flutter, I am working on solving bugs in app. I want to print latitude and longitude of current user after 2 seconds, how can i do that?

void startTimer() {
    const oneSec = const Duration(seconds: 2);
    timer2 = new Timer.periodic(
      oneSec,
      (Timer timer) {
        if (start == 0) {
          timer.cancel();
          setState(() {});
          // });
        } else {
          // setState(() {
          start--;
          setState(() {
            print("My current location ${homeMapCtrl!.userCurrentLatLng}");
          });
          // });
        }
      },
    );
  }

I am using this method and i am calling it in Consumer but it always run upto 1 to 100 seconds.

2

Answers


  1. Use Future.delayed

    void startTimer() async{
        await Future.delayed(Duration(seconds: 2));  
    
        print("My current location ${homeMapCtrl!.userCurrentLatLng}");
    
    Login or Signup to reply.
  2. Use location package to get user location or you can checkout this link for example click here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search