initSession method

Future<void> initSession()

Implementation

Future<void> initSession() async {
  final localSessionId = sharedPreferences.getString(_kSessionId);
  if (localSessionId != null && localSessionId.isNotEmpty) {
    _session = PalSession(uid: localSessionId);
    return;
  }

  final res = await _httpClient.post(
    Uri.parse('/sessions'),
    body: PalSessionRequest.create(
      platform: defaultTargetPlatform.name,
    ).toJson(),
  );
  _session = PalSession.fromJson(res.body);

  await sharedPreferences.setString(_kSessionId, _session!.uid);
}