setLocale method

Future<void> setLocale(
  1. HatangLocale locale
)

Switches the UI language; the socket re-authenticates so the gateway learns it too.

Implementation

Future<void> setLocale(HatangLocale locale) async {
  await _ensureLoaded();
  _preferredLocale = locale.code;
  if (_state.locale == locale) return;
  _emit(_state.copyWith(locale: locale));
  await _persist(_stored.copyWith(locale: locale.code));
  final socket = _socket;
  if (socket != null && socket.active) {
    socket.close();
    socket.connect();
  }
}