music by: NCS Release - Fly Again
-----------------------------------------------------------------------------------------
code:
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
void getLocation() async{
print("getting location");
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
print(position);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: ElevatedButton(
onPressed: (){
getLocation();
},
child: Text("Get Location"),
)
)
)
);
}
}
-----------------------------------------------------------------------------------------
code:
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
void getLocation() async{
print("getting location");
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
print(position);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: ElevatedButton(
onPressed: (){
getLocation();
},
child: Text("Get Location"),
)
)
)
);
}
}
- Категория
- Язык программирования Dart
Комментариев нет.