getData method

  1. @override
Map<String, dynamic> getData()
override

Collects context data. Implementations must never throw; if an internal error occurs, return an empty map instead.

Implementation

@override
Map<String, dynamic> getData() {
  final media = MediaQuery.maybeOf(context);
  final theme = Theme.of(context);
  final locale = Localizations.maybeLocaleOf(context);
  final navigator = Navigator.maybeOf(context);
  final route = ModalRoute.of(context);

  return <String, dynamic>{
    'theme': {
      'brightness': theme.brightness.name,
      'primaryColor': theme.primaryColor.toARGB32(),
      'colorScheme': {
        'brightness': theme.colorScheme.brightness.name,
        'primary': theme.colorScheme.primary.toARGB32(),
        'secondary': theme.colorScheme.secondary.toARGB32(),
        'background': theme.colorScheme.surface.toARGB32(),
        'surface': theme.colorScheme.surface.toARGB32(),
        'error': theme.colorScheme.error.toARGB32(),
      },
      'textTheme': {
        'displayLarge': theme.textTheme.displayLarge?.fontSize,
        'displayMedium': theme.textTheme.displayMedium?.fontSize,
        'displaySmall': theme.textTheme.displaySmall?.fontSize,
        'headlineLarge': theme.textTheme.headlineLarge?.fontSize,
        'headlineMedium': theme.textTheme.headlineMedium?.fontSize,
        'headlineSmall': theme.textTheme.headlineSmall?.fontSize,
        'titleLarge': theme.textTheme.titleLarge?.fontSize,
        'titleMedium': theme.textTheme.titleMedium?.fontSize,
        'titleSmall': theme.textTheme.titleSmall?.fontSize,
        'bodyLarge': theme.textTheme.bodyLarge?.fontSize,
        'bodyMedium': theme.textTheme.bodyMedium?.fontSize,
        'bodySmall': theme.textTheme.bodySmall?.fontSize,
        'labelLarge': theme.textTheme.labelLarge?.fontSize,
        'labelMedium': theme.textTheme.labelMedium?.fontSize,
        'labelSmall': theme.textTheme.labelSmall?.fontSize,
      },
      'platform': theme.platform.name,
    },
    'mediaQuery': media == null
        ? null
        : {
            'size': {
              'width': media.size.width,
              'height': media.size.height,
            },
            'devicePixelRatio': media.devicePixelRatio,
            'padding': media.padding.toString(),
            'viewInsets': media.viewInsets.toString(),
            'viewPadding': media.viewPadding.toString(),
            'textScaleFactor': media.textScaler.toString(),
            'orientation': media.orientation.name,
            'platformBrightness': media.platformBrightness.name,
            'accessibleNavigation': media.accessibleNavigation,
            'boldText': media.boldText,
            'disableAnimations': media.disableAnimations,
            'highContrast': media.highContrast,
            'invertColors': media.invertColors,
            'alwaysUse24HourFormat': media.alwaysUse24HourFormat,
          },
    'locale': locale?.toLanguageTag(),
    'textDirection': Directionality.of(context).name,
    'navigation': navigator == null
        ? null
        : {
            'canPop': navigator.canPop(),
            'userGestureInProgress': navigator.userGestureInProgress,
            'routeName': route?.settings.name,
          },
    'scheduler': {
      'timeDilation': timeDilation,
      'frameTime': SchedulerBinding.instance.currentFrameTimeStamp.toString(),
    },
    if (_additional != null) ..._additional(),
  };
}