Flutter - Re ask location permission after denied
you could wrap your initPlatformState()
in a setState in initState
@override
void initState() {
super.initState();
setState(() {
initPlatformState()
});
}
Check if Geolocation was allowed and get Lat Lon
It isn't possible with the geolocation API but it is possible with the new permission API
This code is useful if you want to try to receive the coordinates but don't want to bother the user with a prompt dialog cuz the coordinates is not that important and may as well fallback to geoIP
function getCoords() { return new Promise((resolve, reject) => navigator.permissions ?
// Permission API is implemented navigator.permissions.query({ name: 'geolocation' }).then(permission => // is geolocation granted? permission.state === "granted" ? navigator.geolocation.getCurrentPosition(pos => resolve(pos.coords)) : resolve(null) ) :
// Permission API was not implemented reject(new Error("Permission API is not supported")) )}
getCoords().then(coords => console.log(coords))
Related Topics
Replace Unicode Matches in JavaScript
Html - Clicking a Button to Obtain Table Cell Value
Parsing Error: Unexpected Token, Expected ","
How to Pass Checkbox State to Onclick Function in React
Vue.Js Refs Are Undefined, Even Though This.$Refs Shows Theyre There
Jquery Change Event Called Two Times
Node.Js Document Is Not Defined
How to Fix Problem Closing Dropdown When I Click Outside It
Can We Call the Function Written in One JavaScript in Another Js File
How to Separate an Integer into Separate Digits in an Array in JavaScript
How to Align Text Input Correctly in React Native
Using Setstate to Change Multiple Values Within an Array of Objects - Reactjs
Show Form Fields Based on Selected Option
React Open Modal Window on Click in Another Component
Syntaxerror: Cannot Use Import Statement Outside a Module
Get the Value of Datepicker on Change in Jquery
Javascript (+) Sign Concatenates Instead of Giving Sum of Variables