renderDeepLinkSetup function

void renderDeepLinkSetup(
  1. LiveBlock block,
  2. Map<String, Object?> payload,
  3. PlatformLinks platform
)

Adds the deeplink setup view: what the app does with links, and what the project's platform config lets in.

Implementation

void renderDeepLinkSetup(
  LiveBlock block,
  Map<String, Object?> payload,
  PlatformLinks platform,
) {
  final Object? routes = payload['routes'];
  final int count = routes is List ? routes.length : 0;
  final List<List<String>> rows = [
    ['Deep links', payload['enabled'] == true ? 'on' : 'off'],
    ['Fallback route', '${payload['fallbackRoute'] ?? '-'}'],
    ['onIncomingLink', payload['hasCallback'] == true ? 'set' : 'not set'],
    if (platform.iosFound)
      [
        'iOS schemes',
        platform.iosSchemes.isEmpty ? '-' : platform.iosSchemes.join(', '),
      ],
    if (platform.iosDomains.isNotEmpty)
      ['iOS domains', platform.iosDomains.join(', ')],
    if (platform.androidFound)
      [
        'Android schemes',
        platform.androidSchemes.isEmpty
            ? '-'
            : platform.androidSchemes.join(', '),
      ],
    if (platform.androidHosts.isNotEmpty)
      ['Android hosts', platform.androidHosts.join(', ')],
    ['Routes', '$count registered'],
  ];
  final int width = rows
      .map((List<String> row) => row.first.length)
      .reduce((int a, int b) => a > b ? a : b);
  for (final List<String> row in rows) {
    block.plain('${row.first.padRight(width + 2)}${row.last}');
  }

  if (payload['enabled'] != true) {
    block.note(
      'Links still resolve here, but the app won\'t receive real ones until '
      'you call nylo.useDeepLinks() in a provider.',
    );
  }
}