LineChartStyle.fromTheme constructor

LineChartStyle.fromTheme(
  1. BuildContext context, {
  2. List<Color>? datasetColors,
})

Implementation

factory LineChartStyle.fromTheme(BuildContext context,
    {List<Color>? datasetColors}) {
  final theme = Theme.of(context);
  final textStyle = theme.textTheme.bodyLarge ?? theme.textTheme.bodyMedium!;
  final fontHeight = createTextPainter(textStyle, 'SAMPLE').height;
  final lineColor = textStyle.color!.withOpacity(0.3);
  final datasetStyles = (datasetColors ?? _defaultDatasetColors())
      .map((c) => DatasetStyle(color: c))
      .toList();
  final legendInsets = EdgeInsets.only(top: fontHeight / 2);
  final highlight =
      HighlightStyle(color: _Colors.highlight, lineSize: _defaultLineSize);
  final selectionLabelStyle = SelectionLabelStyle(
    borderColor: lineColor,
    textStyle: textStyle,
    xAxisLabelProvider: (point) => _defaultLabelProvider(point.x),
    leftYAxisLabelProvider: (point) => _defaultLabelProvider(point.y),
    rightYAxisLabelProvider: (point) => _defaultLabelProvider(point.y),
  );
  final labelInset = (fontHeight / 2).ceilToDouble();
  return LineChartStyle(
      legendStyle: LegendStyle(
          borderColor: lineColor, textStyle: textStyle, insets: legendInsets),
      datasetStyles: datasetStyles,
      highlightStyle: highlight,
      topAxisStyle: AxisStyle(
          textStyle: textStyle,
          lineColor: lineColor,
          labelProvider: (point) => _defaultLabelProvider(point.x),
          labelInsets: EdgeInsets.only(bottom: labelInset)),
      bottomAxisStyle: AxisStyle(
          textStyle: textStyle,
          lineColor: lineColor,
          labelProvider: (point) => _defaultLabelProvider(point.x),
          labelInsets: EdgeInsets.only(top: labelInset)),
      leftAxisStyle: AxisStyle(
          textStyle: textStyle,
          labelInsets: EdgeInsets.only(right: labelInset),
          labelProvider: (point) => _defaultLabelProvider(point.y),
          lineColor: lineColor),
      rightAxisStyle: AxisStyle(
          textStyle: textStyle,
          labelInsets: EdgeInsets.only(left: labelInset),
          labelProvider: (point) => _defaultLabelProvider(point.y),
          lineColor: lineColor),
      selectionLabelStyle: selectionLabelStyle);
}