How to update my location after location turned on in flutter












1















I am new to flutter and I am trying something to achieve in this example, I want to update user location after user turns location on, say for suppose user didn't turn on his location first after we give user a pop up saying this application need location on then it should update data but in the below example its not working, please help me out.



Here is the example what I am working on



PS:



enter image description here










share|improve this question





























    1















    I am new to flutter and I am trying something to achieve in this example, I want to update user location after user turns location on, say for suppose user didn't turn on his location first after we give user a pop up saying this application need location on then it should update data but in the below example its not working, please help me out.



    Here is the example what I am working on



    PS:



    enter image description here










    share|improve this question



























      1












      1








      1








      I am new to flutter and I am trying something to achieve in this example, I want to update user location after user turns location on, say for suppose user didn't turn on his location first after we give user a pop up saying this application need location on then it should update data but in the below example its not working, please help me out.



      Here is the example what I am working on



      PS:



      enter image description here










      share|improve this question
















      I am new to flutter and I am trying something to achieve in this example, I want to update user location after user turns location on, say for suppose user didn't turn on his location first after we give user a pop up saying this application need location on then it should update data but in the below example its not working, please help me out.



      Here is the example what I am working on



      PS:



      enter image description here







      android dart flutter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 6:09







      Harsha Vardhan

















      asked Nov 19 '18 at 13:02









      Harsha VardhanHarsha Vardhan

      849




      849
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Just subscribe to "onLocationChanged" Stream like in the example.



          _location.onLocationChanged().listen((Map<String,double> result) {
          var latitude = result["latitude"]; //This is called always when the location updates
          var longitude = result["longitude"];
          });


          For showing a popup when the user has no location enabled use this:



          try {
          currentLocation = await location.getLocation;
          } on PlatformException {
          await showDialog<dynamic>(
          context: context,
          builder: (context) {
          return AlertDialog(
          title: Text("No Location"),
          content: Text(
          "Please allow this App to use Location or turn on your GPS."),
          actions: <Widget>[
          FlatButton(
          child: Text(
          "Ok"
          ),
          onPressed: () {
          Navigator.of(context).pop();
          },
          )
          ],
          );
          });
          }





          share|improve this answer
























          • Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..

            – Harsha Vardhan
            Nov 20 '18 at 6:12






          • 1





            Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)

            – Niklas Raab
            Nov 20 '18 at 12:51











          • I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.

            – Harsha Vardhan
            Nov 20 '18 at 12:56











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375270%2fhow-to-update-my-location-after-location-turned-on-in-flutter%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Just subscribe to "onLocationChanged" Stream like in the example.



          _location.onLocationChanged().listen((Map<String,double> result) {
          var latitude = result["latitude"]; //This is called always when the location updates
          var longitude = result["longitude"];
          });


          For showing a popup when the user has no location enabled use this:



          try {
          currentLocation = await location.getLocation;
          } on PlatformException {
          await showDialog<dynamic>(
          context: context,
          builder: (context) {
          return AlertDialog(
          title: Text("No Location"),
          content: Text(
          "Please allow this App to use Location or turn on your GPS."),
          actions: <Widget>[
          FlatButton(
          child: Text(
          "Ok"
          ),
          onPressed: () {
          Navigator.of(context).pop();
          },
          )
          ],
          );
          });
          }





          share|improve this answer
























          • Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..

            – Harsha Vardhan
            Nov 20 '18 at 6:12






          • 1





            Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)

            – Niklas Raab
            Nov 20 '18 at 12:51











          • I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.

            – Harsha Vardhan
            Nov 20 '18 at 12:56
















          0














          Just subscribe to "onLocationChanged" Stream like in the example.



          _location.onLocationChanged().listen((Map<String,double> result) {
          var latitude = result["latitude"]; //This is called always when the location updates
          var longitude = result["longitude"];
          });


          For showing a popup when the user has no location enabled use this:



          try {
          currentLocation = await location.getLocation;
          } on PlatformException {
          await showDialog<dynamic>(
          context: context,
          builder: (context) {
          return AlertDialog(
          title: Text("No Location"),
          content: Text(
          "Please allow this App to use Location or turn on your GPS."),
          actions: <Widget>[
          FlatButton(
          child: Text(
          "Ok"
          ),
          onPressed: () {
          Navigator.of(context).pop();
          },
          )
          ],
          );
          });
          }





          share|improve this answer
























          • Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..

            – Harsha Vardhan
            Nov 20 '18 at 6:12






          • 1





            Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)

            – Niklas Raab
            Nov 20 '18 at 12:51











          • I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.

            – Harsha Vardhan
            Nov 20 '18 at 12:56














          0












          0








          0







          Just subscribe to "onLocationChanged" Stream like in the example.



          _location.onLocationChanged().listen((Map<String,double> result) {
          var latitude = result["latitude"]; //This is called always when the location updates
          var longitude = result["longitude"];
          });


          For showing a popup when the user has no location enabled use this:



          try {
          currentLocation = await location.getLocation;
          } on PlatformException {
          await showDialog<dynamic>(
          context: context,
          builder: (context) {
          return AlertDialog(
          title: Text("No Location"),
          content: Text(
          "Please allow this App to use Location or turn on your GPS."),
          actions: <Widget>[
          FlatButton(
          child: Text(
          "Ok"
          ),
          onPressed: () {
          Navigator.of(context).pop();
          },
          )
          ],
          );
          });
          }





          share|improve this answer













          Just subscribe to "onLocationChanged" Stream like in the example.



          _location.onLocationChanged().listen((Map<String,double> result) {
          var latitude = result["latitude"]; //This is called always when the location updates
          var longitude = result["longitude"];
          });


          For showing a popup when the user has no location enabled use this:



          try {
          currentLocation = await location.getLocation;
          } on PlatformException {
          await showDialog<dynamic>(
          context: context,
          builder: (context) {
          return AlertDialog(
          title: Text("No Location"),
          content: Text(
          "Please allow this App to use Location or turn on your GPS."),
          actions: <Widget>[
          FlatButton(
          child: Text(
          "Ok"
          ),
          onPressed: () {
          Navigator.of(context).pop();
          },
          )
          ],
          );
          });
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 21:22









          Niklas RaabNiklas Raab

          8610




          8610













          • Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..

            – Harsha Vardhan
            Nov 20 '18 at 6:12






          • 1





            Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)

            – Niklas Raab
            Nov 20 '18 at 12:51











          • I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.

            – Harsha Vardhan
            Nov 20 '18 at 12:56



















          • Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..

            – Harsha Vardhan
            Nov 20 '18 at 6:12






          • 1





            Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)

            – Niklas Raab
            Nov 20 '18 at 12:51











          • I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.

            – Harsha Vardhan
            Nov 20 '18 at 12:56

















          Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..

          – Harsha Vardhan
          Nov 20 '18 at 6:12





          Updated my question, cause it have own pop up saying that as in image if my mobile location is off, but after I press "ok" location turned on but location is not updating on screen, it still shows null my question is how to update that data. That's what I want to achieve..

          – Harsha Vardhan
          Nov 20 '18 at 6:12




          1




          1





          Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)

          – Niklas Raab
          Nov 20 '18 at 12:51





          Please try to use an Emulator with Google Play Services installed. How to do this is explained here: stackoverflow.com/questions/50135124/…. Hope this helps :)

          – Niklas Raab
          Nov 20 '18 at 12:51













          I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.

          – Harsha Vardhan
          Nov 20 '18 at 12:56





          I am using an emulator only, and tried to make that update thing manually by passing some data in AVD still its not working I installed in my mobile and checked by moving one place to another place still not working. Thanks for your response sir.

          – Harsha Vardhan
          Nov 20 '18 at 12:56




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375270%2fhow-to-update-my-location-after-location-turned-on-in-flutter%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Xamarin.form Move up view when keyboard appear

          JBPM : POST request for execute process go wrong