Closed MapleNoise closed 1 year ago
@MapleNoise - this should be fixed https://github.com/radarlabs/flutter-radar/releases/tag/3.1.5. let us know if you experience any other issues.
I am having the same problem. I have the following code as the docs state, but the print line inside onEvents never gets executed (but Radar's log line shows the event has been received):
Future<void> startTracking() async {
Radar.setUserId(authRepository.currentUserId);
Radar.onEvents(onEvents);
await Radar.startTracking('continuous');
}
@pragma('vm:entry-point')
static onEvents(Map result) {
print('event received');
}
I noticed that in the provided code snippet, you did not call Radar.attachListeners();
can you try adding that line as such
Radar.setUserId(authRepository.currentUserId);
Radar.attachListeners();
Radar.onEvents(onEvents);
await Radar.startTracking('continuous');
Thanks, but this is not working either. Just to explain how I call my startTracking function in case it makes a difference....it is inside a class which has a riverpod provider, and then in the initState of a widget I am calling ref.read(radarServiceProvider).startTracking();
Btw, attachListeners is not mentioned on the flutter docs page so you may want to add that (https://radar.com/documentation/sdk/flutter)
That is interesting, can you possibly share more code snippets of the way you are managing your state to aid us in reproducing the issue you are encountering?
Sure...I have the following class:
import 'package:flutter_radar/flutter_radar.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:workwith/src/features/auth/data/auth_repository.dart';
class RadarService {
final AuthRepository authRepository;
RadarService({required this.authRepository});
Future<void> startTracking() async {
Radar.setUserId(authRepository.currentUserId);
Radar.attachListeners();
Radar.onEvents(onEvents);
await Radar.startTracking('continuous');
}
@pragma('vm:entry-point')
static onEvents(Map result) {
print('event received');
}
}
final radarServiceProvider = Provider<RadarService>((ref) {
final authRepository = ref.watch(authRepositoryProvider);
return RadarService(authRepository: authRepository);
});
Then in one of my widgets I have this:
@override
void initState() {
super.initState();
ref.read(radarServiceProvider).startTracking();
}
I see events coming in from Radars own log lines, but my log line isn't being printed
Seeing this issue currently in a example project I've spun up to test out Radar. flutter_radar version is 3.9.1
class RadarWidget extends StatefulWidget {
const RadarWidget({super.key});
@override
State<RadarWidget> createState() => _RadarWidgetState();
}
class _RadarWidgetState extends State<RadarWidget> {
@override
Widget build(BuildContext context) {
print('Radar widget building');
return const map.Map();
}
@override
void initState() {
super.initState();
print('Radar init state');
initRadar();
}
@pragma('vm:entry-point')
static void onLocation(Map res) {
print('ππ onLocation: $res');
}
@pragma('vm:entry-point')
static void onClientLocation(Map res) {
print('ππ onClientLocation: $res');
}
@pragma('vm:entry-point')
static void onError(Map res) {
print('ππ onError: $res');
}
@pragma('vm:entry-point')
static void onLog(Map res) {
print('ππ onLog: $res');
}
@pragma('vm:entry-point')
static void onEvents(Map res) {
print('ππ onEvents: $res');
}
@pragma('vm:entry-point')
static void onToken(Map res) {
print('ππ onToken: $res');
}
Future<void> initRadar() async {
Radar.initialize("..."); //Radar api key
Radar.setLogLevel('info');
Radar.attachListeners();
Radar.onLocation(onLocation);
Radar.onClientLocation(onClientLocation);
Radar.onError(onError);
Radar.onEvents(onEvents);
Radar.onLog(onLog);
Radar.onToken(onToken);
final status = await Radar.getPermissionsStatus();
final requestedStatus = await Radar.requestPermissions(true);
await Radar.startTracking('continuous');
final happening = await Radar.mockTracking(
//(37.53206895196914,-77.42409998968543)
origin: {
'latitude': 37.53206895196914,
'longitude': -77.42409998968543
},
//dest: (37.53011080455556, -77.42597953180213)
destination: {
'latitude': 37.53011080455556,
'longitude': -77.42597953180213
},
mode: 'foot',
steps: 10,
interval: 5);
}
}
When running this widget, none of my onEvent print lines are triggered even though I can see the RadarLogger events printing. This issue is definitely not fixed, and it's not clear exactly what is occurring that the callbacks are not being triggered.
Edit: It looks like the logging via Radar.attachListener()
is really flaky, I've made some changes to the code above and when running the app (debug env) it's now a 50/50 chance as to wether the logs start printing.
So I realized I actually hadn't followed the setup instructions fully (I copied the code but didn't change it to my API key), so double check that you have done this correctly: https://radar.com/documentation/sdk/flutter
Just wanted to drop an update, I was able to get this working consistently in my projects now.
In case of future observers to this issue
Thank you for raising this, we will seek to improve the reliability of our SDK in one of our our upcoming releases.
I have a problem with Radar.onEvents(), is never called :
On my IDE logs I've :
But my print on the onEvents listener not show.
What have I done wrong ?
Thanks.