flutter run -d chrome
parent
ba5f3f457f
commit
bd517c4953
|
|
@ -1,26 +0,0 @@
|
|||
import 'package:location/location.dart';
|
||||
|
||||
Location location = Location();
|
||||
location.enableBackgroundMode(enable: true)
|
||||
|
||||
bool serviceEnabled;
|
||||
PermissionStatus permissionGranted;
|
||||
LocationData locationData;
|
||||
|
||||
serviceEnabled = await location.serviceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
serviceEnabled = await location.requestService();
|
||||
if (!serviceEnabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
permissionGranted = await location.hasPermission();
|
||||
if (permissionGranted == PermissionStatus.denied) {
|
||||
permissionGranted = await location.requestPermission();
|
||||
if (permissionGranted != PermissionStatus.granted) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
locationData = await location.getLocation();
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
import 'package:location/location.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Package {}
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Home'),
|
||||
),
|
||||
body: Center(
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
return Column(
|
||||
children: [
|
||||
const Text('Hello world'),
|
||||
const SizedBox(height: 20),
|
||||
//ElevatedButton()
|
||||
],
|
||||
)
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
void foo() async {
|
||||
Location location = Location();
|
||||
location.enableBackgroundMode(enable: true)
|
||||
|
||||
bool serviceEnabled;
|
||||
PermissionStatus permissionGranted;
|
||||
|
||||
serviceEnabled = await location.serviceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
serviceEnabled = await location.requestService();
|
||||
if (!serviceEnabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
permissionGranted = await location.hasPermission();
|
||||
if (permissionGranted == PermissionStatus.denied) {
|
||||
permissionGranted = await location.requestPermission();
|
||||
if (permissionGranted != PermissionStatus.granted) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final locationData = await location.getLocation();
|
||||
print(locationData);
|
||||
}
|
||||
|
|
@ -1,2 +1,4 @@
|
|||
environment:
|
||||
sdk: '^3.10.0'
|
||||
dependencies:
|
||||
location: ^5.0.0
|
||||
Loading…
Reference in New Issue