SanityConfig constructor

SanityConfig({
  1. required String projectId,
  2. required String dataset,
  3. required String token,
  4. String? apiVersion,
  5. bool? useCdn,
  6. Perspective? perspective,
  7. bool? explainQuery,
})

Creates a new Sanity configuration for fetching documents from a project and dataset

Implementation

SanityConfig({
  required this.projectId,
  required this.dataset,
  required this.token,
  String? apiVersion,
  bool? useCdn,
  Perspective? perspective,
  bool? explainQuery,
})  : useCdn = useCdn ?? true,
      apiVersion = apiVersion ?? defaultApiVersion,
      perspective = perspective ?? Perspective.raw,
      explainQuery = explainQuery ?? false {
  assert(token.trim().isNotEmpty, '''
Invalid Token provided.
Setup an API token, with Viewer access, in the Sanity Management Console.
Without a valid token you will not be able to fetch data from Sanity.''');

  assert(RegExp(r'^v\d{4}-\d{2}-\d{2}$').hasMatch(this.apiVersion),
      'Invalid API version provided. It should follow the format `vYYYY-MM-DD`');
}