InfluxDBClient constructor

InfluxDBClient({
  1. String? url,
  2. String? token,
  3. String? bucket,
  4. String? org,
  5. Client? client,
  6. String? username,
  7. String? password,
  8. bool debug = defaultEnableDebug,
  9. int maxRedirects = defaultMaxRedirects,
  10. bool followRedirects = defaultFollowRedirects,
})

Create a new client for a InfluxDB.

Example:

 var client = InfluxDBClient(
    url: 'http://localhost:8086',
    token: 'my-token',
    org: 'my-org',
    bucket: 'my-bucket'
  );
  • debug - enable/disable verbose http call tracing
  • username and password is only for InfluxDB 1.8 compatibility

Implementation

InfluxDBClient(
    {String? url,
    String? token,
    String? bucket,
    String? org,
    Client? client,

    /// InfluxDB 1.x compatibility only
    String? username,

    /// InfluxDB 1.x compatibility only
    String? password,

    /// verbose logging of http calls
    this.debug = defaultEnableDebug,
    this.maxRedirects = defaultMaxRedirects,
    this.followRedirects = defaultFollowRedirects}) {
  this.url = url ?? const String.fromEnvironment('INFLUXDB_URL');
  this.token = token ?? const String.fromEnvironment('INFLUXDB_TOKEN');
  this.bucket = bucket ?? const String.fromEnvironment('INFLUXDB_BUCKET');
  this.org = org ?? const String.fromEnvironment('INFLUXDB_ORG');
  this.client = client ?? LoggingClient(debug, Client());

  // 1.8 compatibility token
  if (username != null && password != null && token == null) {
    this.token = '$username:$password';
  }
  defaultHeaders['User-Agent'] = '$clientName/$clientVersion';
}