buildInitialLink function

  1. @visibleForTesting
Uri buildInitialLink({
  1. required String platformUrl,
  2. required String token,
  3. required String langCode,
  4. String? redirectTo,
  5. String? resourceId,
  6. bool useHttp = false,
})

Builds the initial URL loaded into the WebView.

Always carries token and lang. The optional redirectTo (a web-app page key) and resourceId (e.g. a store id for a dynamic route) are appended only when non-empty — they let the host deep-link into a specific page (see WebviewContainer.initialLink / Flourish.home). This function is a pure forwarder: validation of these values is the web app's responsibility.

Implementation

@visibleForTesting
Uri buildInitialLink({
  required String platformUrl,
  required String token,
  required String langCode,
  String? redirectTo,
  String? resourceId,
  bool useHttp = false, // local dev serves the web app over plain HTTP
}) {
  final queryParams = <String, String>{
    'token': token,
    'lang': langCode,
  };

  if (redirectTo != null && redirectTo.isNotEmpty) {
    queryParams['redirectTo'] = redirectTo;
  }
  if (resourceId != null && resourceId.isNotEmpty) {
    queryParams['resourceId'] = resourceId;
  }

  final base = useHttp ? Uri.http(platformUrl) : Uri.https(platformUrl);
  return base.replace(queryParameters: queryParams);
}