Closed levi956 closed 1 year ago
Hi, Can you post the code
`class MyApp extends ConsumerWidget { final bool? logged; const MyApp({ super.key, this.logged, });
@override Widget build(BuildContext context, WidgetRef ref) { final sessionController = ref.watch(sessionControllerProvider);
ExpireSession.sessionConfiguations()
.stream
.listen((SessionTimeoutState timeoutEvent) {
sessionController.add(SessionState.startListening);
if (timeoutEvent == SessionTimeoutState.userInactivityTimeout) {
pushTo(context, const ForgotPassword());
} else if (timeoutEvent == SessionTimeoutState.appFocusTimeout) {
pushTo(context, const ForgotPassword());
}
});
return SessionTimeoutManager(
sessionConfig: ExpireSession.sessionConfiguations(),
sessionStateStream: sessionController.stream,
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'App',
theme: GobsThemeData.gobsThemeData,
home: logged! ? SignIn(isWelcome: logged!) : const Onboard(),
),
);
} } `
Pass a lower value for userActivityDebounceDuration
it's default value is 10 seconds, means it will record one event per 10 seconds by default to prevent spawning of multiple timer objects. If you want to notice events touch immediately set it to a lower value like 1 second
SessionTimeoutManager(
userActivityDebounceDuration = const Duration(seconds: 1)}
...
Let me know if it solves your issue
I also suspect if ExpireSession.sessionConfiguations()
returns a new SessionConfig
object everytime it is called?
If that's the case, you can store it in a variable instead of creating 2 different sessionConfigs
final sessionConfig = ExpireSession.sessionConfiguations();
sessionConfig.stream.listen((SessionTimeoutState timeoutEvent) {
sessionController.add(SessionState.startListening);
if (timeoutEvent == SessionTimeoutState.userInactivityTimeout) {
pushTo(context, const ForgotPassword());
} else if (timeoutEvent == SessionTimeoutState.appFocusTimeout) {
pushTo(context, const ForgotPassword());
}
});
return SessionTimeoutManager(
sessionConfig: sessionConfig,
sessionStateStream: sessionController.stream,
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'App',
theme: GobsThemeData.gobsThemeData,
home: logged! ? SignIn(isWelcome: logged!) : const Onboard(),
),
);
Still didn't work
Can you post the implementation of ExpireSession.sessionConfiguations()
class ExpireSession { static SessionConfig sessionConfiguations() { return SessionConfig( invalidateSessionForAppLostFocus: const Duration(seconds: 5), invalidateSessionForUserInactivity: const Duration(seconds: 5), ); } }
I made some changes in my above code, can you try it. Basically the issue is it returns a new sessionConfig everytime, each sessionConfig is associated with different stream. So make sure to use same sessionConfig object to sessionTimeoutManager and listen to strean
It still didn't work.
Can you create a minimal example to reproduce the problem?
How can I create a minimum example? I shared my code that includes the problem. I don't think the stream is detecting any event.
It would be helpful if you can reproduce the issue in DartPad with minimal code and share the link or share the link to your project if it's not private.
Would do that shortly.
https://github.com/levi956/local_session_issue-11
Here is the link to the project. Thank you.
When you pass sessionStateStream
argument, you have to also call sessionController.add(SessionState.startListening);
to start listening. However if you don't pass this optional parameter, it will always listen.
Let me know if this solves your issue.
It's added in the project. Line 22 on the project. It was always there.
Line 22; is not the right place to put it. In that case it will be executed only after the stream emits it's first event which doesn't. So put it outside that callback
It's working now. Thank you for taking your time to help my fix. I really appreciate.
I'm trying to apply this plugin to detect idle activity to log users out. Eventually, I used Riverpod per the documentation, but I wasn't getting any event from the stream. Then I copied the example code from the example folder, but still not detecting any event.
I'm testing on an Xcode simulator ios 16.0 and ios physical device.
Is there some sort of configuration I'm missing or something?