initializeValues method

Future<void> initializeValues({
  1. void onComplete()?,
})

Implementation

Future<void> initializeValues({void Function()? onComplete}) async {
  // Return early if already initialized.
  if (initialized.isCompleted) return;

  assert(serviceManager!.isServiceAvailable);

  await Future.wait([isFlutterApp, isProfileBuild, isDartWebApp]);

  _operatingSystem = serviceManager!.vm!.operatingSystem ?? unknownOS;

  if (isFlutterAppNow!) {
    final flutterVersionServiceListenable = serviceManager!
        .registeredServiceListenable(flutterVersionService.service);
    void Function() listener;
    flutterVersionServiceListenable.addListener(
      listener = () async {
        final registered = flutterVersionServiceListenable.value;
        if (registered) {
          _flutterVersionCompleter.complete(
            FlutterVersion.parse(
              (await serviceManager!.flutterVersion).json!,
            ),
          );
        }
      },
    );

    _flutterVersion = await _flutterVersionCompleter.future.timeout(
      _flutterVersionTimeout,
      onTimeout: () {
        _log.info(
          'Timed out trying to fetch flutter version from '
          '`ConnectedApp.initializeValues`.',
        );
        return Future<FlutterVersion?>.value(FlutterVersion.unknown());
      },
    );
    flutterVersionServiceListenable.removeListener(listener);
  }
  onComplete?.call();
  initialized.complete(true);
}