handle static method

FutureOr<Response> handle(
  1. Request request, {
  2. required ExtensionsManager extensionsManager,
  3. required DeeplinkManager deeplinkManager,
  4. ServerApi? api,
  5. DtdInfo? dtd,
})

Handles all requests.

To override an API call, pass in a subclass of ServerApi.

Implementation

static FutureOr<shelf.Response> handle(
  shelf.Request request, {
  required ExtensionsManager extensionsManager,
  required DeeplinkManager deeplinkManager,
  ServerApi? api,
  DtdInfo? dtd,
}) {
  api ??= ServerApi();
  final queryParams = request.requestedUri.queryParameters;
  // TODO(kenz): break this switch statement up so that it uses helper methods
  // for each case. Also use [_checkRequiredParameters] helper.
  switch (request.url.path) {
    case apiNotifyForVmServiceConnection:
      return Handler.handleNotifyForVmServiceConnection(
        api,
        queryParams,
        dtd,
      );

    // ----- Flutter Tool GA store. -----
    case apiGetFlutterGAEnabled:
      // Is Analytics collection enabled?
      return _encodeResponse(
        LocalFileSystem.flutterStoreExists()
            ? _flutterStore.gaEnabled
            : false,
        api: api,
      );
    case apiGetFlutterGAClientId:
      // Flutter Tool GA clientId - ONLY get Flutter's clientId if enabled is
      // true.
      return _encodeResponse(
        LocalFileSystem.flutterStoreExists()
            ? _flutterStore.flutterClientId
            : '',
        api: api,
      );

    // ----- DevTools GA store. -----

    case apiResetDevTools:
      _devToolsStore.reset();
      return _encodeResponse(true, api: api);
    case apiGetDevToolsFirstRun:
      // Has DevTools been run first time? To bring up analytics dialog.
      final isFirstRun = _devToolsStore.isFirstRun;
      return _encodeResponse(isFirstRun, api: api);
    case apiGetDevToolsEnabled:
      // Is DevTools Analytics collection enabled?
      final isEnabled = _devToolsStore.analyticsEnabled;
      return _encodeResponse(isEnabled, api: api);
    case apiSetDevToolsEnabled:
      // Enable or disable DevTools analytics collection.
      if (queryParams.containsKey(devToolsEnabledPropertyName)) {
        final analyticsEnabled =
            json.decode(queryParams[devToolsEnabledPropertyName]!);

        _devToolsStore.analyticsEnabled = analyticsEnabled;
      }
      return _encodeResponse(_devToolsStore.analyticsEnabled, api: api);

    // ----- Preferences api. -----
    case PreferencesApi.getPreferenceValue:
      return _PreferencesApiHandler.getPreferenceValue(
        api,
        queryParams,
        _devToolsStore,
      );

    case PreferencesApi.setPreferenceValue:
      return _PreferencesApiHandler.setPreferenceValue(
        api,
        queryParams,
        _devToolsStore,
      );

    // ----- DevTools survey api. -----

    case SurveyApi.setActiveSurvey:
      return _SurveyHandler.setActiveSurvey(api, queryParams, _devToolsStore);

    case SurveyApi.getSurveyActionTaken:
      return _SurveyHandler.getSurveyActionTaken(api, _devToolsStore);

    case SurveyApi.setSurveyActionTaken:
      return _SurveyHandler.setSurveyActionTaken(api, _devToolsStore);

    case SurveyApi.getSurveyShownCount:
      return _SurveyHandler.getSurveyShownCount(api, _devToolsStore);

    case SurveyApi.incrementSurveyShownCount:
      return _SurveyHandler.incrementSurveyShownCount(api, _devToolsStore);

    // ----- Release notes api. -----

    case ReleaseNotesApi.getLastReleaseNotesVersion:
      return _ReleaseNotesHandler.getLastReleaseNotesVersion(
        api,
        _devToolsStore,
      );

    case ReleaseNotesApi.setLastReleaseNotesVersion:
      return _ReleaseNotesHandler.setLastReleaseNotesVersion(
        api,
        queryParams,
        _devToolsStore,
      );

    // ----- App size api. -----

    case AppSizeApi.getBaseAppSizeFile:
      return _AppSizeHandler.getBaseAppSizeFile(api, queryParams);

    case AppSizeApi.getTestAppSizeFile:
      return _AppSizeHandler.getTestAppSizeFile(api, queryParams);

    // ----- Extensions api. -----

    case ExtensionsApi.apiServeAvailableExtensions:
      return _ExtensionsApiHandler.handleServeAvailableExtensions(
        api,
        queryParams,
        extensionsManager,
        dtd,
      );

    case ExtensionsApi.apiExtensionEnabledState:
      return _ExtensionsApiHandler.handleExtensionEnabledState(
        api,
        queryParams,
      );

    // ----- deeplink api. -----

    case DeeplinkApi.androidBuildVariants:
      return _DeeplinkApiHandler.handleAndroidBuildVariants(
        api,
        queryParams,
        deeplinkManager,
      );

    case DeeplinkApi.androidAppLinkSettings:
      return _DeeplinkApiHandler.handleAndroidAppLinkSettings(
        api,
        queryParams,
        deeplinkManager,
      );

    case DeeplinkApi.iosBuildOptions:
      return _DeeplinkApiHandler.handleIosBuildOptions(
        api,
        queryParams,
        deeplinkManager,
      );

    case DeeplinkApi.iosUniversalLinkSettings:
      return _DeeplinkApiHandler.handleIosUniversalLinkSettings(
        api,
        queryParams,
        deeplinkManager,
      );

    // ----- DTD api. -----

    case DtdApi.apiGetDtdUri:
      return _DtdApiHandler.handleGetDtdUri(api, dtd);

    // ----- Unimplemented. -----

    default:
      return api.notImplemented();
  }
}