Location package example is not working for me Flutter












1















I am new to flutter and trying to get current location lat and long from my mobile app, for that I am using location 1.4.1, and also found this example which I mentioned in the below link, I did how exactly how they mentioned step by step process but still its throwing errors.



Please go through example



Exception has occurred.
PlatformException(PERMISSION_DENIED, The user explicitly denied the use of location services for this app or location services are currently disabled in Settings., null)


This is the exception I am getting when I run my code, but there is a try catch for PlatformException in that example.I got stuck here, please help me out and thanks.



My AndroidManifest.xml



<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.latlong">

<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="lat_long"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>


main.dart:



import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
Map<String, double> _startLocation;
Map<String, double> _currentLocation;

StreamSubscription<Map<String, double>> _locationSubscription;

Location _location = new Location();
bool _permission = false;
String error;

bool currentWidget = true;

Image image1;

@override
void initState() {
super.initState();

initPlatformState();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
}

// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
Map<String, double> location;
// Platform messages may fail, so we use a try/catch PlatformException.

try {
_permission = await _location.hasPermission();
location = await _location.getLocation();


error = null;
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'Permission denied - please ask the user to enable it from the app settings';
}

location = null;
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
//if (!mounted) return;

setState(() {
_startLocation = location;
});

}

@override
Widget build(BuildContext context) {
List<Widget> widgets;


if (_currentLocation == null) {
widgets = new List();
} else {
widgets = [
new Image.network(
"https://maps.googleapis.com/maps/api/staticmap?"+
"center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}"+
"&zoom=18&size=640x400&key=AIzaSyBw_T2wCQGqWBEdF4UzMAuoQX_DCemYpQw")
];
}

widgets.add(new Center(
child: new Text(_startLocation != null
? 'Start location: $_startLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_currentLocation != null
? 'Continuous location: $_currentLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_permission
? 'Has permission : Yes'
: "Has permission : No")));

return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Location plugin example app'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: widgets,
)));
}
}


and my pubspec.yaml :



name: lat_long
description: A new Flutter project.

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
location: ^1.4.1

dev_dependencies:
flutter_test:
sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.

# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages









share|improve this question

























  • Did you add the permissions in your AndroidManifest? I.e. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> Edit: you might also have to add permissions for ACCESS_COARSE_LOCATION and INTERNET too.

    – SnakeyHips
    Nov 21 '18 at 9:25













  • Yes I did, still I cannot catch the exception.

    – Harsha Vardhan
    Nov 21 '18 at 9:37











  • You won't be able to catch this exception. There's something not right with the app's permissions set up.Can you input your AndroidManifest.xml if you're on Android or Info.plist if on iOS onto your post please?

    – SnakeyHips
    Nov 21 '18 at 9:50











  • Yes, updated my code please see

    – Harsha Vardhan
    Nov 21 '18 at 9:55











  • Are you testing this on an actual device or emulator?

    – SnakeyHips
    Nov 21 '18 at 10:13
















1















I am new to flutter and trying to get current location lat and long from my mobile app, for that I am using location 1.4.1, and also found this example which I mentioned in the below link, I did how exactly how they mentioned step by step process but still its throwing errors.



Please go through example



Exception has occurred.
PlatformException(PERMISSION_DENIED, The user explicitly denied the use of location services for this app or location services are currently disabled in Settings., null)


This is the exception I am getting when I run my code, but there is a try catch for PlatformException in that example.I got stuck here, please help me out and thanks.



My AndroidManifest.xml



<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.latlong">

<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="lat_long"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>


main.dart:



import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
Map<String, double> _startLocation;
Map<String, double> _currentLocation;

StreamSubscription<Map<String, double>> _locationSubscription;

Location _location = new Location();
bool _permission = false;
String error;

bool currentWidget = true;

Image image1;

@override
void initState() {
super.initState();

initPlatformState();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
}

// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
Map<String, double> location;
// Platform messages may fail, so we use a try/catch PlatformException.

try {
_permission = await _location.hasPermission();
location = await _location.getLocation();


error = null;
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'Permission denied - please ask the user to enable it from the app settings';
}

location = null;
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
//if (!mounted) return;

setState(() {
_startLocation = location;
});

}

@override
Widget build(BuildContext context) {
List<Widget> widgets;


if (_currentLocation == null) {
widgets = new List();
} else {
widgets = [
new Image.network(
"https://maps.googleapis.com/maps/api/staticmap?"+
"center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}"+
"&zoom=18&size=640x400&key=AIzaSyBw_T2wCQGqWBEdF4UzMAuoQX_DCemYpQw")
];
}

widgets.add(new Center(
child: new Text(_startLocation != null
? 'Start location: $_startLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_currentLocation != null
? 'Continuous location: $_currentLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_permission
? 'Has permission : Yes'
: "Has permission : No")));

return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Location plugin example app'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: widgets,
)));
}
}


and my pubspec.yaml :



name: lat_long
description: A new Flutter project.

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
location: ^1.4.1

dev_dependencies:
flutter_test:
sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.

# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages









share|improve this question

























  • Did you add the permissions in your AndroidManifest? I.e. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> Edit: you might also have to add permissions for ACCESS_COARSE_LOCATION and INTERNET too.

    – SnakeyHips
    Nov 21 '18 at 9:25













  • Yes I did, still I cannot catch the exception.

    – Harsha Vardhan
    Nov 21 '18 at 9:37











  • You won't be able to catch this exception. There's something not right with the app's permissions set up.Can you input your AndroidManifest.xml if you're on Android or Info.plist if on iOS onto your post please?

    – SnakeyHips
    Nov 21 '18 at 9:50











  • Yes, updated my code please see

    – Harsha Vardhan
    Nov 21 '18 at 9:55











  • Are you testing this on an actual device or emulator?

    – SnakeyHips
    Nov 21 '18 at 10:13














1












1








1








I am new to flutter and trying to get current location lat and long from my mobile app, for that I am using location 1.4.1, and also found this example which I mentioned in the below link, I did how exactly how they mentioned step by step process but still its throwing errors.



Please go through example



Exception has occurred.
PlatformException(PERMISSION_DENIED, The user explicitly denied the use of location services for this app or location services are currently disabled in Settings., null)


This is the exception I am getting when I run my code, but there is a try catch for PlatformException in that example.I got stuck here, please help me out and thanks.



My AndroidManifest.xml



<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.latlong">

<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="lat_long"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>


main.dart:



import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
Map<String, double> _startLocation;
Map<String, double> _currentLocation;

StreamSubscription<Map<String, double>> _locationSubscription;

Location _location = new Location();
bool _permission = false;
String error;

bool currentWidget = true;

Image image1;

@override
void initState() {
super.initState();

initPlatformState();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
}

// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
Map<String, double> location;
// Platform messages may fail, so we use a try/catch PlatformException.

try {
_permission = await _location.hasPermission();
location = await _location.getLocation();


error = null;
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'Permission denied - please ask the user to enable it from the app settings';
}

location = null;
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
//if (!mounted) return;

setState(() {
_startLocation = location;
});

}

@override
Widget build(BuildContext context) {
List<Widget> widgets;


if (_currentLocation == null) {
widgets = new List();
} else {
widgets = [
new Image.network(
"https://maps.googleapis.com/maps/api/staticmap?"+
"center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}"+
"&zoom=18&size=640x400&key=AIzaSyBw_T2wCQGqWBEdF4UzMAuoQX_DCemYpQw")
];
}

widgets.add(new Center(
child: new Text(_startLocation != null
? 'Start location: $_startLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_currentLocation != null
? 'Continuous location: $_currentLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_permission
? 'Has permission : Yes'
: "Has permission : No")));

return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Location plugin example app'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: widgets,
)));
}
}


and my pubspec.yaml :



name: lat_long
description: A new Flutter project.

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
location: ^1.4.1

dev_dependencies:
flutter_test:
sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.

# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages









share|improve this question
















I am new to flutter and trying to get current location lat and long from my mobile app, for that I am using location 1.4.1, and also found this example which I mentioned in the below link, I did how exactly how they mentioned step by step process but still its throwing errors.



Please go through example



Exception has occurred.
PlatformException(PERMISSION_DENIED, The user explicitly denied the use of location services for this app or location services are currently disabled in Settings., null)


This is the exception I am getting when I run my code, but there is a try catch for PlatformException in that example.I got stuck here, please help me out and thanks.



My AndroidManifest.xml



<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.latlong">

<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="lat_long"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>


main.dart:



import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
Map<String, double> _startLocation;
Map<String, double> _currentLocation;

StreamSubscription<Map<String, double>> _locationSubscription;

Location _location = new Location();
bool _permission = false;
String error;

bool currentWidget = true;

Image image1;

@override
void initState() {
super.initState();

initPlatformState();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
}

// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
Map<String, double> location;
// Platform messages may fail, so we use a try/catch PlatformException.

try {
_permission = await _location.hasPermission();
location = await _location.getLocation();


error = null;
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'Permission denied - please ask the user to enable it from the app settings';
}

location = null;
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
//if (!mounted) return;

setState(() {
_startLocation = location;
});

}

@override
Widget build(BuildContext context) {
List<Widget> widgets;


if (_currentLocation == null) {
widgets = new List();
} else {
widgets = [
new Image.network(
"https://maps.googleapis.com/maps/api/staticmap?"+
"center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}"+
"&zoom=18&size=640x400&key=AIzaSyBw_T2wCQGqWBEdF4UzMAuoQX_DCemYpQw")
];
}

widgets.add(new Center(
child: new Text(_startLocation != null
? 'Start location: $_startLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_currentLocation != null
? 'Continuous location: $_currentLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_permission
? 'Has permission : Yes'
: "Has permission : No")));

return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Location plugin example app'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: widgets,
)));
}
}


and my pubspec.yaml :



name: lat_long
description: A new Flutter project.

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
location: ^1.4.1

dev_dependencies:
flutter_test:
sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.

# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages






android dart flutter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 10:28







Harsha Vardhan

















asked Nov 21 '18 at 6:55









Harsha VardhanHarsha Vardhan

8410




8410













  • Did you add the permissions in your AndroidManifest? I.e. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> Edit: you might also have to add permissions for ACCESS_COARSE_LOCATION and INTERNET too.

    – SnakeyHips
    Nov 21 '18 at 9:25













  • Yes I did, still I cannot catch the exception.

    – Harsha Vardhan
    Nov 21 '18 at 9:37











  • You won't be able to catch this exception. There's something not right with the app's permissions set up.Can you input your AndroidManifest.xml if you're on Android or Info.plist if on iOS onto your post please?

    – SnakeyHips
    Nov 21 '18 at 9:50











  • Yes, updated my code please see

    – Harsha Vardhan
    Nov 21 '18 at 9:55











  • Are you testing this on an actual device or emulator?

    – SnakeyHips
    Nov 21 '18 at 10:13



















  • Did you add the permissions in your AndroidManifest? I.e. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> Edit: you might also have to add permissions for ACCESS_COARSE_LOCATION and INTERNET too.

    – SnakeyHips
    Nov 21 '18 at 9:25













  • Yes I did, still I cannot catch the exception.

    – Harsha Vardhan
    Nov 21 '18 at 9:37











  • You won't be able to catch this exception. There's something not right with the app's permissions set up.Can you input your AndroidManifest.xml if you're on Android or Info.plist if on iOS onto your post please?

    – SnakeyHips
    Nov 21 '18 at 9:50











  • Yes, updated my code please see

    – Harsha Vardhan
    Nov 21 '18 at 9:55











  • Are you testing this on an actual device or emulator?

    – SnakeyHips
    Nov 21 '18 at 10:13

















Did you add the permissions in your AndroidManifest? I.e. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> Edit: you might also have to add permissions for ACCESS_COARSE_LOCATION and INTERNET too.

– SnakeyHips
Nov 21 '18 at 9:25







Did you add the permissions in your AndroidManifest? I.e. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> Edit: you might also have to add permissions for ACCESS_COARSE_LOCATION and INTERNET too.

– SnakeyHips
Nov 21 '18 at 9:25















Yes I did, still I cannot catch the exception.

– Harsha Vardhan
Nov 21 '18 at 9:37





Yes I did, still I cannot catch the exception.

– Harsha Vardhan
Nov 21 '18 at 9:37













You won't be able to catch this exception. There's something not right with the app's permissions set up.Can you input your AndroidManifest.xml if you're on Android or Info.plist if on iOS onto your post please?

– SnakeyHips
Nov 21 '18 at 9:50





You won't be able to catch this exception. There's something not right with the app's permissions set up.Can you input your AndroidManifest.xml if you're on Android or Info.plist if on iOS onto your post please?

– SnakeyHips
Nov 21 '18 at 9:50













Yes, updated my code please see

– Harsha Vardhan
Nov 21 '18 at 9:55





Yes, updated my code please see

– Harsha Vardhan
Nov 21 '18 at 9:55













Are you testing this on an actual device or emulator?

– SnakeyHips
Nov 21 '18 at 10:13





Are you testing this on an actual device or emulator?

– SnakeyHips
Nov 21 '18 at 10:13












1 Answer
1






active

oldest

votes


















2














You just had the wrong order of things as you were trying to access the location/permissions before you actually got them.



Remove the onLocationChanged() subscription from your initState() and change your try statement in your initPlatformState() to this:



try {
location = await _location.getLocation();
_permission = await _location.hasPermission();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
error = null;
}


Note the swapping of you getting the location and checking if you have permission lines.



Edit: added full code:



import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
Map<String, double> _startLocation;
Map<String, double> _currentLocation;

StreamSubscription<Map<String, double>> _locationSubscription;

Location _location = new Location();

bool _permission = false;
String error;

bool currentWidget = true;

Image image1;

@override
void initState() {
super.initState();

initPlatformState();
}

// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
Map<String, double> location;
// Platform messages may fail, so we use a try/catch PlatformException.

try {
location = await _location.getLocation();
_permission = await _location.hasPermission();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
error = null;
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'Permission denied - please ask the user to enable it from the app settings';
}

location = null;
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
//if (!mounted) return;

setState(() {
_startLocation = location;
});

}

@override
Widget build(BuildContext context) {
List<Widget> widgets;


if (_currentLocation == null) {
widgets = new List();
} else {
widgets = [
new Image.network(
"https://maps.googleapis.com/maps/api/staticmap?"+
"center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}"+
"&zoom=18&size=640x400&key=AIzaSyBw_T2wCQGqWBEdF4UzMAuoQX_DCemYpQw")
];
}

widgets.add(new Center(
child: new Text(_startLocation != null
? 'Start location: $_startLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_currentLocation != null
? 'Continuous location: $_currentLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_permission
? 'Has permission : Yes'
: "Has permission : No")));

return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Location plugin example app'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: widgets,
)));
}
}





share|improve this answer


























  • Nope, Its not working, location subscription to is to listen if there is any location change, yes if u comment that or swap to initPlatformState() you wont get Allow or Deny pop up but still you will get that error saying permission_denied.

    – Harsha Vardhan
    Nov 21 '18 at 11:54













  • I've added the full code. This works on my Samsung S7 (as I said in first comments, location for emulator takes a few extra steps to get working).

    – SnakeyHips
    Nov 21 '18 at 12:00











  • How did you go with this @HarshaVardhan ?

    – TeamTam
    Feb 5 at 12:07











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%2f53406724%2flocation-package-example-is-not-working-for-me-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









2














You just had the wrong order of things as you were trying to access the location/permissions before you actually got them.



Remove the onLocationChanged() subscription from your initState() and change your try statement in your initPlatformState() to this:



try {
location = await _location.getLocation();
_permission = await _location.hasPermission();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
error = null;
}


Note the swapping of you getting the location and checking if you have permission lines.



Edit: added full code:



import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
Map<String, double> _startLocation;
Map<String, double> _currentLocation;

StreamSubscription<Map<String, double>> _locationSubscription;

Location _location = new Location();

bool _permission = false;
String error;

bool currentWidget = true;

Image image1;

@override
void initState() {
super.initState();

initPlatformState();
}

// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
Map<String, double> location;
// Platform messages may fail, so we use a try/catch PlatformException.

try {
location = await _location.getLocation();
_permission = await _location.hasPermission();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
error = null;
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'Permission denied - please ask the user to enable it from the app settings';
}

location = null;
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
//if (!mounted) return;

setState(() {
_startLocation = location;
});

}

@override
Widget build(BuildContext context) {
List<Widget> widgets;


if (_currentLocation == null) {
widgets = new List();
} else {
widgets = [
new Image.network(
"https://maps.googleapis.com/maps/api/staticmap?"+
"center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}"+
"&zoom=18&size=640x400&key=AIzaSyBw_T2wCQGqWBEdF4UzMAuoQX_DCemYpQw")
];
}

widgets.add(new Center(
child: new Text(_startLocation != null
? 'Start location: $_startLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_currentLocation != null
? 'Continuous location: $_currentLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_permission
? 'Has permission : Yes'
: "Has permission : No")));

return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Location plugin example app'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: widgets,
)));
}
}





share|improve this answer


























  • Nope, Its not working, location subscription to is to listen if there is any location change, yes if u comment that or swap to initPlatformState() you wont get Allow or Deny pop up but still you will get that error saying permission_denied.

    – Harsha Vardhan
    Nov 21 '18 at 11:54













  • I've added the full code. This works on my Samsung S7 (as I said in first comments, location for emulator takes a few extra steps to get working).

    – SnakeyHips
    Nov 21 '18 at 12:00











  • How did you go with this @HarshaVardhan ?

    – TeamTam
    Feb 5 at 12:07
















2














You just had the wrong order of things as you were trying to access the location/permissions before you actually got them.



Remove the onLocationChanged() subscription from your initState() and change your try statement in your initPlatformState() to this:



try {
location = await _location.getLocation();
_permission = await _location.hasPermission();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
error = null;
}


Note the swapping of you getting the location and checking if you have permission lines.



Edit: added full code:



import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
Map<String, double> _startLocation;
Map<String, double> _currentLocation;

StreamSubscription<Map<String, double>> _locationSubscription;

Location _location = new Location();

bool _permission = false;
String error;

bool currentWidget = true;

Image image1;

@override
void initState() {
super.initState();

initPlatformState();
}

// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
Map<String, double> location;
// Platform messages may fail, so we use a try/catch PlatformException.

try {
location = await _location.getLocation();
_permission = await _location.hasPermission();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
error = null;
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'Permission denied - please ask the user to enable it from the app settings';
}

location = null;
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
//if (!mounted) return;

setState(() {
_startLocation = location;
});

}

@override
Widget build(BuildContext context) {
List<Widget> widgets;


if (_currentLocation == null) {
widgets = new List();
} else {
widgets = [
new Image.network(
"https://maps.googleapis.com/maps/api/staticmap?"+
"center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}"+
"&zoom=18&size=640x400&key=AIzaSyBw_T2wCQGqWBEdF4UzMAuoQX_DCemYpQw")
];
}

widgets.add(new Center(
child: new Text(_startLocation != null
? 'Start location: $_startLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_currentLocation != null
? 'Continuous location: $_currentLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_permission
? 'Has permission : Yes'
: "Has permission : No")));

return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Location plugin example app'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: widgets,
)));
}
}





share|improve this answer


























  • Nope, Its not working, location subscription to is to listen if there is any location change, yes if u comment that or swap to initPlatformState() you wont get Allow or Deny pop up but still you will get that error saying permission_denied.

    – Harsha Vardhan
    Nov 21 '18 at 11:54













  • I've added the full code. This works on my Samsung S7 (as I said in first comments, location for emulator takes a few extra steps to get working).

    – SnakeyHips
    Nov 21 '18 at 12:00











  • How did you go with this @HarshaVardhan ?

    – TeamTam
    Feb 5 at 12:07














2












2








2







You just had the wrong order of things as you were trying to access the location/permissions before you actually got them.



Remove the onLocationChanged() subscription from your initState() and change your try statement in your initPlatformState() to this:



try {
location = await _location.getLocation();
_permission = await _location.hasPermission();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
error = null;
}


Note the swapping of you getting the location and checking if you have permission lines.



Edit: added full code:



import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
Map<String, double> _startLocation;
Map<String, double> _currentLocation;

StreamSubscription<Map<String, double>> _locationSubscription;

Location _location = new Location();

bool _permission = false;
String error;

bool currentWidget = true;

Image image1;

@override
void initState() {
super.initState();

initPlatformState();
}

// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
Map<String, double> location;
// Platform messages may fail, so we use a try/catch PlatformException.

try {
location = await _location.getLocation();
_permission = await _location.hasPermission();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
error = null;
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'Permission denied - please ask the user to enable it from the app settings';
}

location = null;
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
//if (!mounted) return;

setState(() {
_startLocation = location;
});

}

@override
Widget build(BuildContext context) {
List<Widget> widgets;


if (_currentLocation == null) {
widgets = new List();
} else {
widgets = [
new Image.network(
"https://maps.googleapis.com/maps/api/staticmap?"+
"center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}"+
"&zoom=18&size=640x400&key=AIzaSyBw_T2wCQGqWBEdF4UzMAuoQX_DCemYpQw")
];
}

widgets.add(new Center(
child: new Text(_startLocation != null
? 'Start location: $_startLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_currentLocation != null
? 'Continuous location: $_currentLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_permission
? 'Has permission : Yes'
: "Has permission : No")));

return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Location plugin example app'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: widgets,
)));
}
}





share|improve this answer















You just had the wrong order of things as you were trying to access the location/permissions before you actually got them.



Remove the onLocationChanged() subscription from your initState() and change your try statement in your initPlatformState() to this:



try {
location = await _location.getLocation();
_permission = await _location.hasPermission();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
error = null;
}


Note the swapping of you getting the location and checking if you have permission lines.



Edit: added full code:



import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:location/location.dart';

void main() {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
Map<String, double> _startLocation;
Map<String, double> _currentLocation;

StreamSubscription<Map<String, double>> _locationSubscription;

Location _location = new Location();

bool _permission = false;
String error;

bool currentWidget = true;

Image image1;

@override
void initState() {
super.initState();

initPlatformState();
}

// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
Map<String, double> location;
// Platform messages may fail, so we use a try/catch PlatformException.

try {
location = await _location.getLocation();
_permission = await _location.hasPermission();

_locationSubscription =
_location.onLocationChanged().listen((Map<String,double> result) {
setState(() {
_currentLocation = result;
});
});
error = null;
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'Permission denied - please ask the user to enable it from the app settings';
}

location = null;
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
//if (!mounted) return;

setState(() {
_startLocation = location;
});

}

@override
Widget build(BuildContext context) {
List<Widget> widgets;


if (_currentLocation == null) {
widgets = new List();
} else {
widgets = [
new Image.network(
"https://maps.googleapis.com/maps/api/staticmap?"+
"center=${_currentLocation["latitude"]},${_currentLocation["longitude"]}"+
"&zoom=18&size=640x400&key=AIzaSyBw_T2wCQGqWBEdF4UzMAuoQX_DCemYpQw")
];
}

widgets.add(new Center(
child: new Text(_startLocation != null
? 'Start location: $_startLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_currentLocation != null
? 'Continuous location: $_currentLocationn'
: 'Error: $errorn')));

widgets.add(new Center(
child: new Text(_permission
? 'Has permission : Yes'
: "Has permission : No")));

return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Location plugin example app'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: widgets,
)));
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 12:09

























answered Nov 21 '18 at 11:41









SnakeyHipsSnakeyHips

626114




626114













  • Nope, Its not working, location subscription to is to listen if there is any location change, yes if u comment that or swap to initPlatformState() you wont get Allow or Deny pop up but still you will get that error saying permission_denied.

    – Harsha Vardhan
    Nov 21 '18 at 11:54













  • I've added the full code. This works on my Samsung S7 (as I said in first comments, location for emulator takes a few extra steps to get working).

    – SnakeyHips
    Nov 21 '18 at 12:00











  • How did you go with this @HarshaVardhan ?

    – TeamTam
    Feb 5 at 12:07



















  • Nope, Its not working, location subscription to is to listen if there is any location change, yes if u comment that or swap to initPlatformState() you wont get Allow or Deny pop up but still you will get that error saying permission_denied.

    – Harsha Vardhan
    Nov 21 '18 at 11:54













  • I've added the full code. This works on my Samsung S7 (as I said in first comments, location for emulator takes a few extra steps to get working).

    – SnakeyHips
    Nov 21 '18 at 12:00











  • How did you go with this @HarshaVardhan ?

    – TeamTam
    Feb 5 at 12:07

















Nope, Its not working, location subscription to is to listen if there is any location change, yes if u comment that or swap to initPlatformState() you wont get Allow or Deny pop up but still you will get that error saying permission_denied.

– Harsha Vardhan
Nov 21 '18 at 11:54







Nope, Its not working, location subscription to is to listen if there is any location change, yes if u comment that or swap to initPlatformState() you wont get Allow or Deny pop up but still you will get that error saying permission_denied.

– Harsha Vardhan
Nov 21 '18 at 11:54















I've added the full code. This works on my Samsung S7 (as I said in first comments, location for emulator takes a few extra steps to get working).

– SnakeyHips
Nov 21 '18 at 12:00





I've added the full code. This works on my Samsung S7 (as I said in first comments, location for emulator takes a few extra steps to get working).

– SnakeyHips
Nov 21 '18 at 12:00













How did you go with this @HarshaVardhan ?

– TeamTam
Feb 5 at 12:07





How did you go with this @HarshaVardhan ?

– TeamTam
Feb 5 at 12:07




















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%2f53406724%2flocation-package-example-is-not-working-for-me-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







這個網誌中的熱門文章

Hercules Kyvelos

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud