waitForSessionState static method
Waits for a session to reach a specific state.
targetState - The target session state to wait for
timeoutSeconds - Maximum time to wait in seconds (defaults to 30)
Returns true if the target state is reached, false if timeout
Implementation
static Future<bool> waitForSessionState(
SessionState targetState, {
int timeoutSeconds = 30,
}) async {
_log('Waiting for session state: $targetState');
final startTime = DateTime.now();
final timeout = Duration(seconds: timeoutSeconds);
while (DateTime.now().difference(startTime) < timeout) {
try {
final currentState = await ULink.instance
.getSessionState();
if (currentState == targetState) {
_log('Session reached target state: $targetState');
return true;
}
// Wait a bit before checking again
await Future.delayed(const Duration(milliseconds: 500));
} catch (e) {
_log('Error checking session state: $e');
await Future.delayed(const Duration(milliseconds: 500));
}
}
_log('Timeout waiting for session state: $targetState');
return false;
}