getServerTime method

  1. @override
Future<DateTime> getServerTime()
override

Implementation

@override
Future<DateTime> getServerTime() async {
  if (config.serverTimeFunctionId != null && config.functions != null) {
    try {
      final exec = await config.functions!.createExecution(
        functionId: config.serverTimeFunctionId!,
        body: '',
      );
      // Expecting ISO-8601 UTC in response body
      final body = exec.responseBody.trim();
      if (body.isNotEmpty) {
        return DateTime.parse(body).toUtc();
      }
    } catch (_) {
      // fallback below
    }
  }
  // Fallback (not recommended for production sync): client time
  return DateTime.now().toUtc();
}