65 lines
1.4 KiB
Dart
65 lines
1.4 KiB
Dart
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);
|
|
}
|