buildBodyViewer method

Widget buildBodyViewer(
  1. BuildContext context,
  2. dynamic body
)

Implementation

Widget buildBodyViewer(BuildContext context, dynamic body) {
  String text;
  if (body == null) {
    text = '';
  } else if (body is String) {
    text = body;
  } else if (body is List || body is Map) {
    text = _jsonEncoder.convert(body);
  } else {
    text = body.toString();
  }
  return SingleChildScrollView(
    scrollDirection: Axis.horizontal,
    padding: const EdgeInsets.symmetric(horizontal: 15),
    child: GestureDetector(
      onLongPress: () {
        Clipboard.setData(ClipboardData(text: text));
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(
            content: Text('Copied to clipboard'),
            behavior: SnackBarBehavior.floating,
          ),
        );
      },
      child: Text(
        text,
        style: const TextStyle(
          fontFamily: 'monospace',
          fontFamilyFallback: ['sans-serif'],
        ),
      ),
    ),
  );
}