I' am trying to get geolocation and then push it on other route, but it returns me smth like:
W/ActivityThread(27303): SCHED: razewp.covid19_20/.MainActivity [81, r=36ms, a=8ms, w=31795ms]
here's code:
its my first file loc_get.dart
import 'package:geolocator/geolocator.dart';
class LocationGetter {
var test;
LocationGetter({
this.test,
});
Future<void> getLoc() async {
final position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
}
}
this is my loc.dart
:
import 'package:flutter/material.dart';
import 'package:covid19_20/pages/loc_get.dart';
class Location extends StatefulWidget {
@override
_LocationState createState() => _LocationState();
}
class _LocationState extends State<Location> {
void setupLoc() async {
LocationGetter location = LocationGetter(
test: '',
);
await location.getLoc();
Navigator.pushReplacementNamed(context, '/loading', arguments: {
'test': location.test,
});
}
@override
void initState() {
super.initState();
setupLoc();
}
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Center(
child: Text('Getting location...')
),
)
);
}
}
How can I fix it? Is there any ways? I'm debugging on my MI 8 SE phone
Try to change
Future<void> getLoc() async {
final position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
}
to
Future<void> getLoc() async {
final position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
this.test=position;
}