getWidget method
Implementation
Widget getWidget({
required BuildContext context,
required KnowledgePanelTableCellWidthComputer computer,
}) {
final bool isDark = Theme.brightnessOf(context) == Brightness.dark;
final Color? color = getTextColorFromKnowledgePanelElementEvaluation(
evaluation,
context.extension<SmoothColorsThemeExtension>(),
);
final Color foreground, background;
if (isDark) {
foreground = Colors.white.withAlpha(192);
background = Colors.black.withAlpha(192);
} else {
foreground = Colors.black.withAlpha(192);
background = Colors.grey.withAlpha(64);
}
final Widget? iconWidget = iconUrl == null
? null
: Padding(
padding: const EdgeInsets.all(_cellItemPadding),
child: AbstractCache.best(
iconUrl: iconUrl,
width: _cellItemSize,
height: _cellItemSize,
color: foreground,
),
);
final double? clampedPercent = percent == null
? null
: clampDouble(percent!, 0, 100);
final Widget? percentWidget = clampedPercent == null
? null
: Padding(
padding: const EdgeInsets.all(_cellItemPadding),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: _cellItemSize,
width: _cellPercentageWidth * clampedPercent / 100,
color: foreground,
),
Container(
height: _cellItemSize,
width: _cellPercentageWidth * (100 - clampedPercent) / 100,
color: background,
),
],
),
);
Widget getTextWidget(int maxLines) {
final AlignmentDirectional textAlignment = leftAlign
? AlignmentDirectional.centerStart
: AlignmentDirectional.centerEnd;
final StringBuffer styleBuilder = StringBuffer(
'text-align:${textAlignment.toHTMLTextAlign()};'
'text-overflow: ellipsis;'
'overflow: hidden;'
'max-lines: $maxLines;',
);
if (color != null) {
styleBuilder.write(
'color: rgba('
'${(color.r * 255.0).round().clamp(0, 255)},'
'${(color.g * 255.0).round().clamp(0, 255)},'
'${(color.b * 255.0).round().clamp(0, 255)},'
'${color.a}'
');',
);
}
return SmoothHtmlWidget(
'<div style="$styleBuilder">$text</div>',
textStyle: _getStyle(computer),
isSelectable: false,
);
}
if (iconWidget == null && percentWidget == null) {
return getTextWidget(2);
}
return Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
?iconWidget,
?percentWidget,
Expanded(child: getTextWidget(1)),
],
);
}