getValueWidget static method

Widget getValueWidget(
  1. dynamic content,
  2. TomlViewerConfig config
)

Determines the appropriate widget to display the value based on its type.

Implementation

static Widget getValueWidget(dynamic content, TomlViewerConfig config) {
  // Determine the style based on the value's type.
  var style = TextStyle(color: config.valueColor);
  if (content == null) {
    return Expanded(
      child: Text(
        'undefined',
        style: style,
      ),
    );
  } else if (content is int ||
      content is String ||
      content is bool ||
      content is double ||
      content is TomlLocalDate ||
      content is TomlLocalDateTime ||
      content is TomlDateTime) {
    return Expanded(
      child: Text(
        content.toString(),
        style: style,
      ),
    );
  } else if (content is List) {
    if (content.isEmpty) {
      return Text(
        'Array[0]',
        style: TextStyle(color: config.typeTextColor),
      );
    } else {
      return Text(
        'Array of ${getTypeName(content)}[${content.length}]',
        style: TextStyle(color: config.typeTextColor),
      );
    }
  }
  return Text('Table',
      style: TextStyle(
        color: config.typeTextColor,
      ));
}