Skip to content

Commit

Permalink
Use TextScaler textScaler insted of double textScale to get rid of th…
Browse files Browse the repository at this point in the history
…e deprecation warning
  • Loading branch information
imaNNeo committed Nov 21, 2023
1 parent 1877f37 commit 888803f
Show file tree
Hide file tree
Showing 21 changed files with 349 additions and 213 deletions.
2 changes: 1 addition & 1 deletion lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class BarChartPainter extends AxisChartPainter<BarChartData> {
text: span,
textAlign: tooltipItem.textAlign,
textDirection: tooltipItem.textDirection,
textScaleFactor: holder.textScale,
textScaler: holder.textScaler,
)..layout(maxWidth: tooltipData.maxContentWidth);

/// creating TextPainters to calculate the width and height of the tooltip
Expand Down
23 changes: 11 additions & 12 deletions lib/src/chart/bar_chart/bar_chart_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class BarChartLeaf extends LeafRenderObjectWidget {
context,
data,
targetData,
MediaQuery.of(context).textScaleFactor,
MediaQuery.of(context).textScaler,
);

@override
void updateRenderObject(BuildContext context, RenderBarChart renderObject) {
renderObject
..data = data
..targetData = targetData
..textScale = MediaQuery.of(context).textScaleFactor
..textScaler = MediaQuery.of(context).textScaler
..buildContext = context;
}
}
Expand All @@ -39,10 +39,10 @@ class RenderBarChart extends RenderBaseChart<BarTouchResponse> {
BuildContext context,
BarChartData data,
BarChartData targetData,
double textScale,
TextScaler textScaler,
) : _data = data,
_targetData = targetData,
_textScale = textScale,
_textScaler = textScaler,
super(targetData.barTouchData, context);

BarChartData get data => _data;
Expand All @@ -64,12 +64,12 @@ class RenderBarChart extends RenderBaseChart<BarTouchResponse> {
markNeedsPaint();
}

double get textScale => _textScale;
double _textScale;
TextScaler get textScaler => _textScaler;
TextScaler _textScaler;

set textScale(double value) {
if (_textScale == value) return;
_textScale = value;
set textScaler(TextScaler value) {
if (_textScaler == value) return;
_textScaler = value;
markNeedsPaint();
}

Expand All @@ -80,9 +80,8 @@ class RenderBarChart extends RenderBaseChart<BarTouchResponse> {
@visibleForTesting
BarChartPainter painter = BarChartPainter();

PaintHolder<BarChartData> get paintHolder {
return PaintHolder(data, targetData, textScale);
}
PaintHolder<BarChartData> get paintHolder =>
PaintHolder(data, targetData, textScaler);

@override
void paint(PaintingContext context, Offset offset) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/chart/base/base_chart/base_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class BaseChartPainter<D extends BaseChartData> {
/// Holds data for painting on canvas
class PaintHolder<Data extends BaseChartData> {
/// Holds data for painting on canvas
const PaintHolder(this.data, this.targetData, this.textScale);
const PaintHolder(this.data, this.targetData, this.textScaler);

/// [data] is what we need to show frame by frame (it might be changed by an animator)
final Data data;

/// [targetData] is the target of animation that is playing.
final Data targetData;

/// system [textScale]
final double textScale;
/// system [TextScaler] used for scaling texts for better readability
final TextScaler textScaler;
}
2 changes: 1 addition & 1 deletion lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
text: span,
textAlign: tooltipItem.textAlign,
textDirection: tooltipItem.textDirection,
textScaleFactor: holder.textScale,
textScaler: holder.textScaler,
)..layout(maxWidth: tooltipData.maxContentWidth);
drawingTextPainters.add(tp);
}
Expand Down
23 changes: 11 additions & 12 deletions lib/src/chart/line_chart/line_chart_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class LineChartLeaf extends LeafRenderObjectWidget {
context,
data,
targetData,
MediaQuery.of(context).textScaleFactor,
MediaQuery.of(context).textScaler,
);

@override
void updateRenderObject(BuildContext context, RenderLineChart renderObject) {
renderObject
..data = data
..targetData = targetData
..textScale = MediaQuery.of(context).textScaleFactor
..textScaler = MediaQuery.of(context).textScaler
..buildContext = context;
}
}
Expand All @@ -44,10 +44,10 @@ class RenderLineChart extends RenderBaseChart<LineTouchResponse> {
BuildContext context,
LineChartData data,
LineChartData targetData,
double textScale,
TextScaler textScaler,
) : _data = data,
_targetData = targetData,
_textScale = textScale,
_textScaler = textScaler,
super(
targetData.lineTouchData,
context,
Expand All @@ -70,11 +70,11 @@ class RenderLineChart extends RenderBaseChart<LineTouchResponse> {
markNeedsPaint();
}

double get textScale => _textScale;
double _textScale;
set textScale(double value) {
if (_textScale == value) return;
_textScale = value;
TextScaler get textScaler => _textScaler;
TextScaler _textScaler;
set textScaler(TextScaler value) {
if (_textScaler == value) return;
_textScaler = value;
markNeedsPaint();
}

Expand All @@ -85,9 +85,8 @@ class RenderLineChart extends RenderBaseChart<LineTouchResponse> {
@visibleForTesting
LineChartPainter painter = LineChartPainter();

PaintHolder<LineChartData> get paintHolder {
return PaintHolder(data, targetData, textScale);
}
PaintHolder<LineChartData> get paintHolder =>
PaintHolder(data, targetData, textScaler);

@override
void paint(PaintingContext context, Offset offset) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/chart/pie_chart/pie_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class PieChartPainter extends BaseChartPainter<PieChartData> {
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
textScaleFactor: holder.textScale,
textScaler: holder.textScaler,
)..layout();

canvasWrapper.drawText(
Expand Down
23 changes: 11 additions & 12 deletions lib/src/chart/pie_chart/pie_chart_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class PieChartLeaf extends MultiChildRenderObjectWidget {
context,
data,
targetData,
MediaQuery.of(context).textScaleFactor,
MediaQuery.of(context).textScaler,
);

@override
void updateRenderObject(BuildContext context, RenderPieChart renderObject) {
renderObject
..data = data
..targetData = targetData
..textScale = MediaQuery.of(context).textScaleFactor
..textScaler = MediaQuery.of(context).textScaler
..buildContext = context;
}
}
Expand All @@ -50,10 +50,10 @@ class RenderPieChart extends RenderBaseChart<PieTouchResponse>
BuildContext context,
PieChartData data,
PieChartData targetData,
double textScale,
TextScaler textScaler,
) : _data = data,
_targetData = targetData,
_textScale = textScale,
_textScaler = textScaler,
super(targetData.pieTouchData, context);

PieChartData get data => _data;
Expand All @@ -77,12 +77,12 @@ class RenderPieChart extends RenderBaseChart<PieTouchResponse>
markNeedsLayout();
}

double get textScale => _textScale;
double _textScale;
TextScaler get textScaler => _textScaler;
TextScaler _textScaler;

set textScale(double value) {
if (_textScale == value) return;
_textScale = value;
set textScaler(TextScaler value) {
if (_textScaler == value) return;
_textScaler = value;
markNeedsPaint();
}

Expand All @@ -93,9 +93,8 @@ class RenderPieChart extends RenderBaseChart<PieTouchResponse>
@visibleForTesting
PieChartPainter painter = PieChartPainter();

PaintHolder<PieChartData> get paintHolder {
return PaintHolder(data, targetData, textScale);
}
PaintHolder<PieChartData> get paintHolder =>
PaintHolder(data, targetData, textScaler);

@override
void setupParentData(RenderBox child) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/chart/radar_chart/radar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class RadarChartPainter extends BaseChartPainter<RadarChartData> {
_titleTextPaint
..textAlign = TextAlign.center
..textDirection = TextDirection.ltr
..textScaleFactor = holder.textScale;
..textScaler = holder.textScaler;

for (var index = 0; index < data.titleCount; index++) {
final baseTitleAngle = Utils().degrees(diffAngle * index);
Expand Down
23 changes: 11 additions & 12 deletions lib/src/chart/radar_chart/radar_chart_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class RadarChartLeaf extends LeafRenderObjectWidget {
context,
data,
targetData,
MediaQuery.of(context).textScaleFactor,
MediaQuery.of(context).textScaler,
);

@override
void updateRenderObject(BuildContext context, RenderRadarChart renderObject) {
renderObject
..data = data
..targetData = targetData
..textScale = MediaQuery.of(context).textScaleFactor
..textScaler = MediaQuery.of(context).textScaler
..buildContext = context;
}
}
Expand All @@ -43,10 +43,10 @@ class RenderRadarChart extends RenderBaseChart<RadarTouchResponse> {
BuildContext context,
RadarChartData data,
RadarChartData targetData,
double textScale,
TextScaler textScaler,
) : _data = data,
_targetData = targetData,
_textScale = textScale,
_textScaler = textScaler,
super(targetData.radarTouchData, context);

RadarChartData get data => _data;
Expand All @@ -68,12 +68,12 @@ class RenderRadarChart extends RenderBaseChart<RadarTouchResponse> {
markNeedsPaint();
}

double get textScale => _textScale;
double _textScale;
TextScaler get textScaler => _textScaler;
TextScaler _textScaler;

set textScale(double value) {
if (_textScale == value) return;
_textScale = value;
set textScaler(TextScaler value) {
if (_textScaler == value) return;
_textScaler = value;
markNeedsPaint();
}

Expand All @@ -84,9 +84,8 @@ class RenderRadarChart extends RenderBaseChart<RadarTouchResponse> {
@visibleForTesting
RadarChartPainter painter = RadarChartPainter();

PaintHolder<RadarChartData> get paintHolder {
return PaintHolder(data, targetData, textScale);
}
PaintHolder<RadarChartData> get paintHolder =>
PaintHolder(data, targetData, textScaler);

@override
void paint(PaintingContext context, Offset offset) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/chart/scatter_chart/scatter_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ScatterChartPainter extends AxisChartPainter<ScatterChartData> {
text: span,
textAlign: TextAlign.center,
textDirection: holder.data.scatterLabelSettings.textDirection,
textScaleFactor: holder.textScale,
textScaler: holder.textScaler,
)..layout(maxWidth: viewSize.width);

final pixelX = getPixelX(scatterSpot.x, viewSize, holder);
Expand Down Expand Up @@ -233,7 +233,7 @@ class ScatterChartPainter extends AxisChartPainter<ScatterChartData> {
text: span,
textAlign: tooltipItem.textAlign,
textDirection: tooltipItem.textDirection,
textScaleFactor: holder.textScale,
textScaler: holder.textScaler,
)..layout(maxWidth: tooltipData.maxContentWidth);

final width = drawingTextPainter.width;
Expand Down
23 changes: 11 additions & 12 deletions lib/src/chart/scatter_chart/scatter_chart_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ScatterChartLeaf extends LeafRenderObjectWidget {
context,
data,
targetData,
MediaQuery.of(context).textScaleFactor,
MediaQuery.of(context).textScaler,
);

@override
Expand All @@ -35,7 +35,7 @@ class ScatterChartLeaf extends LeafRenderObjectWidget {
renderObject
..data = data
..targetData = targetData
..textScale = MediaQuery.of(context).textScaleFactor
..textScaler = MediaQuery.of(context).textScaler
..buildContext = context;
}
}
Expand All @@ -47,10 +47,10 @@ class RenderScatterChart extends RenderBaseChart<ScatterTouchResponse> {
BuildContext context,
ScatterChartData data,
ScatterChartData targetData,
double textScale,
TextScaler textScaler,
) : _data = data,
_targetData = targetData,
_textScale = textScale,
_textScaler = textScaler,
super(targetData.scatterTouchData, context);

ScatterChartData get data => _data;
Expand All @@ -72,12 +72,12 @@ class RenderScatterChart extends RenderBaseChart<ScatterTouchResponse> {
markNeedsPaint();
}

double get textScale => _textScale;
double _textScale;
TextScaler get textScaler => _textScaler;
TextScaler _textScaler;

set textScale(double value) {
if (_textScale == value) return;
_textScale = value;
set textScaler(TextScaler value) {
if (_textScaler == value) return;
_textScaler = value;
markNeedsPaint();
}

Expand All @@ -88,9 +88,8 @@ class RenderScatterChart extends RenderBaseChart<ScatterTouchResponse> {
@visibleForTesting
ScatterChartPainter painter = ScatterChartPainter();

PaintHolder<ScatterChartData> get paintHolder {
return PaintHolder(data, targetData, textScale);
}
PaintHolder<ScatterChartData> get paintHolder =>
PaintHolder(data, targetData, textScaler);

@override
void paint(PaintingContext context, Offset offset) {
Expand Down
Loading

0 comments on commit 888803f

Please sign in to comment.