Я хочу постоянно отслеживать местоположение пользователя в моем приложении. По этой причине я хочу постоянно выполнять событие getLocaiton blo c на моей главной странице. Как я могу это сделать?
Вот мое событие getLocation;
GetLocationState get initialState => GetLocationState(saveUserCurrentLocation: initialPosition );
Stream<GetLocationState> mapEventToState(LocationEvent event) async*{
if (event is GetLocation){
userLocation.getLocation().then((l){
currentLatLng = LatLng(l.latitude, l.longitude);
});
yield GetLocationState(saveUserCurrentLocation: currentLatLng);
}
}
И это моя главная страница
initialCameraPosition:
CameraPosition(target: initialPosition, zoom: 10),
mapType: MapType.terrain,
onMapCreated: _onMapCreated,
myLocationEnabled: true,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
_locationBloc.add(GetLocation());
},
),
),
);
});
}
Как можно непрерывно выполнять код в фоновом режиме, не используя событие onPress?