Я реализовал этот пакет https://pub.dev/packages/geolocator, но я не знаю, как использовать StreamSubscription.
class LocationService{
UserLocation _userLocation;
StreamController<UserLocation> locationUserController;
var geolocator = Geolocator();
var locationOptions = LocationOptions(accuracy: LocationAccuracy.high, distanceFilter: 10);
LocationService(){
geolocator.getPositionStream(locationOptions).listen(
(Position position) {
if (position != null){
locationUserController.add(UserLocation(
latitude: position.latitude,
longitude: position.longitude
));
}
});
}
}
Я реализовал GeoLocator. Это устанавливает значения в класс модели UserLocation .
class UserLocation{
final double latitude;
final double longitude;
UserLocation({this.latitude, this.longitude});
}
Как я получаю доступ к этому UserLocation каждый раз, когда значения меняются?
Мне нужно получить доступ к этим данным в MapsScreen
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
//my try. I don't know what I'm doing
//StreamProvider<UserLocation>(
// create: (_) => LocationService().locationUserController,
//)
return MaterialApp(
title: 'UnMatch',
theme: ThemeData(
primaryColor: ThemeColor.nero,
),
initialRoute: '/home',
routes: {
'/home' : (context) => MapScreen(),
'/login' : (context) => Login()
}
);
}
}
Не могли бы вы объяснить и вставить в код, как мне делать? Меня это очень смущает ...