getWeather method

Public function to get the weather for a given saved city

Implementation

Future<RequestResponse<CurrentWeather?>> getWeather() async {
  /// Initializing the utilities
  WeatherFactoryUtilities utilities = WeatherFactoryUtilities(
    apiKey: apiKey,
    language: language,
    maxTimeBeforeTimeout: maxTimeBeforeTimeout,
  );

  /// Checking whether connected to the internet
  InternetStatus status = await utilities.connectionCheck();
  if (status == InternetStatus.Connected) {
    if (locationCoords != null) {
      /// Handing info to be requested and returning the info
      return _geoRequest(
        coords: LocationCoords(
          latitude: locationCoords!.latitude,
          longitude: locationCoords!.longitude,
        ),
      );
    } else {
      if (cityName!.isEmpty == true) {
        /// Checking for empty text (This is not usually an issue if the text is provided programmatically,
        /// but if the factory is hooked up directly to a TextField widget, and the user accidentally presses
        /// send on an empty widget, an empty String may be passed here
        return RequestResponse(
          requestStatus: RequestStatus.EmptyError,
          response: null,
        );
      } else {
        /// Handing info to be requested and returning the info
        _sanitizeInput(cityName: cityName!);
        return _namedRequest(cityName: cityName!);
      }
    }
  } else {
    /// There is a connection error as connectionCheck() returned InternetStatus.Disconnected
    return RequestResponse(
      requestStatus: RequestStatus.ConnectionError,
      response: null,
    );
  }
}