provider static method

Widget provider({
  1. required String w3wApiKey,
  2. required Widget child,
  3. Client? httpClient,
})

Initializes the W3W services and provides them via ChangeNotifierProvider.

w3wApiKey is your What3Words API key. child is the widget that will have access to the W3WProvider. httpClient is an optional custom HTTP client.

Implementation

static Widget provider({
  required String w3wApiKey,
  required Widget child,
  http.Client? httpClient,
}) {
  final client = httpClient ?? http.Client();
  final dataSource = W3WRemoteDataSource(client, w3wApiKey);
  final repository = W3WRepositoryImpl(dataSource);

  final convertTo3wa = ConvertTo3wa(repository);
  final getGridSection = GetGridSection(repository);
  final convertToCoordinates = ConvertToCoordinates(repository);

  return ChangeNotifierProvider(
    create: (_) => W3WProvider(convertTo3wa, getGridSection, convertToCoordinates),
    child: child,
  );
}