Clients constructor

Clients(
  1. String baseUrl, {
  2. UserId? guestId = null,
  3. TenantId? tenantId = null,
  4. ZoneOffset? zoneOffset = null,
  5. ZoneId? zoneId = null,
  6. QueryMode queryMode = QueryMode.FIREBASE,
  7. FirebaseClient? firebase = null,
  8. Endpoints? endpoints = null,
  9. Duration subscriptionKeepUpPeriod = const Duration(minutes: 2),
  10. List typeRegistries = const [],
  11. HttpTranslator? httpTranslator = null,
})

Creates a new instance of Clients.

Parameters:

  • baseUrl — the base URL of the server which receives the requests from the clients;
  • guestId — the default UserId to use in the "guest" mode; the default is UserId(value = "guest");
  • tenantId — the tenant ID; use this argument only in multitenant systems;
  • zoneOffset and zoneId — the time zone in which the created clients operate; by default, uses the system time zone;
  • queryMode — the query processing mode which should be used by the created clients; see QueryMode for more info; the default value is FIREBASE;
  • firebase — a FirebaseClient which precesses queries and subscriptions; if queryMode is QueryMode.DIRECT and subscriptions are not required, this argument can be skipped;
  • endpoints — the custom endpoints of the backend; see Endpoints for the defaults;
  • subscriptionKeepUpPeriod — the time between subscription keep-up requests; 2 minutes by default;
  • onNetworkError — a callback handling network errors; should receive either error as the only argument or error and StackTrace; should return a FutureOr<Response>;
  • typeRegistries — a list of known type registries; the dart_code_gen tool generates the types.dart files for each module for main and test scopes. A types.dart file contains information about the known Protobuf types of this module. See the class level doc for an example of how to access a type registry and pass it to this constructor;
  • httpTranslator — a custom instance of HttpTranslator, which allows to configure how HTTP requests are sent, and how their responses are treated. By default, a new instance of HttpTranslator will be used.

Implementation

Clients(String baseUrl,
       {UserId? guestId = null,
        TenantId? tenantId = null,
        ZoneOffset? zoneOffset = null,
        ZoneId? zoneId = null,
        QueryMode queryMode = QueryMode.FIREBASE,
        FirebaseClient? firebase = null,
        Endpoints? endpoints = null,
        Duration subscriptionKeepUpPeriod = const Duration(minutes: 2),
        List<dynamic> typeRegistries = const [],
        HttpTranslator? httpTranslator = null}) :
        _httpClient = _createHttpClient(baseUrl, httpTranslator),
        _guestId = guestId ?? _DEFAULT_GUEST_ID,
        _tenant = tenantId,
        _zoneOffset = zoneOffset,
        _zoneId = zoneId,
        _endpoints = endpoints ?? Endpoints(),
        _firebase = firebase
{
    _checkNonNullOrDefault(_guestId, 'guestId');
    _queryProcessor = _chooseProcessor(queryMode, _httpClient, firebase);
    theKnownTypes.registerAll(typeRegistries);
    Timer.periodic(subscriptionKeepUpPeriod,
                   (timer) => _refreshSubscriptions());
}