Skip to content

Commit

Permalink
Fix analyze issues with Dart 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed May 18, 2023
1 parent 2984262 commit 872878b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 87 deletions.
15 changes: 4 additions & 11 deletions lib/src/chart/base/axis_chart/axis_chart_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,10 @@ class _SideTitleWidgetState extends State<SideTitleWidget> {
if (context == null) return;

// Set size based on its axis side
late double size;
switch (widget.axisSide) {
case AxisSide.left:
case AxisSide.right:
size = context.size?.height ?? 0;
break;
case AxisSide.top:
case AxisSide.bottom:
size = context.size?.width ?? 0;
break;
}
final size = switch (widget.axisSide) {
AxisSide.left || AxisSide.right => context.size?.height ?? 0,
AxisSide.top || AxisSide.bottom => context.size?.width ?? 0,
};

// If childSize is the same, no need to set new value
if (_childSize == size) return;
Expand Down
35 changes: 12 additions & 23 deletions lib/src/chart/base/axis_chart/side_titles/side_titles_flex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,16 @@ class AxisSideTitlesRenderFlex extends RenderBox
var child = firstChild;
while (child != null) {
final childParentData = child.parentData! as FlexParentData;
final BoxConstraints innerConstraints;

// Stretch
switch (_direction) {
case Axis.horizontal:
innerConstraints =
BoxConstraints.tightFor(height: constraints.maxHeight);
break;
case Axis.vertical:
innerConstraints =
BoxConstraints.tightFor(width: constraints.maxWidth);
break;
}
final innerConstraints = switch (_direction) {
Axis.horizontal => BoxConstraints.tightFor(
height: constraints.maxHeight,
),
Axis.vertical => BoxConstraints.tightFor(
width: constraints.maxWidth,
),
};

final childSize = layoutChild(child, innerConstraints);
allocatedSize += _getMainSize(childSize);
Expand Down Expand Up @@ -202,12 +199,10 @@ class AxisSideTitlesRenderFlex extends RenderBox
size = constraints.constrain(Size(actualSize, crossSize));
actualSize = size.width;
crossSize = size.height;
break;
case Axis.vertical:
size = constraints.constrain(Size(crossSize, actualSize));
actualSize = size.height;
crossSize = size.width;
break;
}

// Position elements
Expand All @@ -222,16 +217,10 @@ class AxisSideTitlesRenderFlex extends RenderBox
childCrossPosition = 0.0;
final childMainPosition =
metaData.axisPixelLocation - (_getMainSize(child.size) / 2);
switch (_direction) {
case Axis.horizontal:
childParentData.offset =
Offset(childMainPosition, childCrossPosition);
break;
case Axis.vertical:
childParentData.offset =
Offset(childCrossPosition, childMainPosition);
break;
}
childParentData.offset = switch (_direction) {
Axis.horizontal => Offset(childMainPosition, childCrossPosition),
Axis.vertical => Offset(childCrossPosition, childMainPosition),
};
child = childParentData.nextSibling;
counter++;
}
Expand Down
19 changes: 7 additions & 12 deletions lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1140,18 +1140,13 @@ class LineChartPainter extends AxisChartPainter<LineChartData> {
textRotationOffset.dy +
rectRotationOffset.dy;

double xOffset;
switch (tp.textAlign.getFinalHorizontalAlignment(tp.textDirection)) {
case HorizontalAlignment.left:
xOffset = rect.left + tooltipData.tooltipPadding.left;
break;
case HorizontalAlignment.right:
xOffset = rect.right - tooltipData.tooltipPadding.right - tp.width;
break;
default:
xOffset = rect.center.dx - (tp.width / 2);
break;
}
final align = tp.textAlign.getFinalHorizontalAlignment(tp.textDirection);
final xOffset = switch (align) {
HorizontalAlignment.left => rect.left + tooltipData.tooltipPadding.left,
HorizontalAlignment.right =>
rect.right - tooltipData.tooltipPadding.right - tp.width,
_ => rect.center.dx - (tp.width / 2),
};

final drawOffset = Offset(
xOffset,
Expand Down
6 changes: 0 additions & 6 deletions lib/src/extensions/bar_chart_data_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extension BarChartDataExtension on BarChartData {
final groupSpace = i == barGroups.length - 1 ? 0 : groupsSpace;
tempX += group.width + groupSpace;
}
break;

case BarChartAlignment.end:
var sumWidth =
Expand All @@ -30,7 +29,6 @@ extension BarChartDataExtension on BarChartData {
final groupSpace = i == barGroups.length - 1 ? 0 : groupsSpace;
tempX += group.width + groupSpace;
}
break;

case BarChartAlignment.center:
var sumWidth =
Expand All @@ -46,7 +44,6 @@ extension BarChartDataExtension on BarChartData {
final groupSpace = i == barGroups.length - 1 ? 0 : groupsSpace;
tempX += group.width + groupSpace;
}
break;

case BarChartAlignment.spaceBetween:
final sumWidth =
Expand All @@ -63,7 +60,6 @@ extension BarChartDataExtension on BarChartData {
groupsX[index] = tempX;
tempX += group.width / 2;
});
break;

case BarChartAlignment.spaceAround:
final sumWidth =
Expand All @@ -79,7 +75,6 @@ extension BarChartDataExtension on BarChartData {
tempX += group.width / 2;
tempX += eachSpace;
});
break;

case BarChartAlignment.spaceEvenly:
final sumWidth =
Expand All @@ -94,7 +89,6 @@ extension BarChartDataExtension on BarChartData {
groupsX[i] = tempX;
tempX += group.width / 2;
});
break;
}

return groupsX;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dev_dependencies:
sdk: flutter
mockito: ^5.4.0
vector_math: ^2.1.4 #Added to use in some generated codes of mockito
very_good_analysis: ">=4.0.0+1 <6.0.0"
very_good_analysis: ^5.0.0

screenshots:
- description: 'LineChartSample1 and LineChartSample2'
Expand Down
23 changes: 6 additions & 17 deletions test/chart/base/axis_chart/axis_chart_scaffold_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,12 @@ void main() {
);

Future<void> checkSide(AxisSide side) async {
String axisChar;
switch (side) {
case AxisSide.left:
axisChar = 'L';
break;
case AxisSide.top:
axisChar = 'T';
break;
case AxisSide.right:
axisChar = 'R';
break;
case AxisSide.bottom:
axisChar = 'B';
break;
default:
throw StateError('Invalid');
}
final axisChar = switch (side) {
AxisSide.left => 'L',
AxisSide.top => 'T',
AxisSide.right => 'R',
AxisSide.bottom => 'B',
};
for (var i = 0; i <= 10; i++) {
expect(find.text('$axisChar-$i'), findsOneWidget);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,12 @@ void main() {
),
);

String axisName;
switch (side) {
case AxisSide.left:
axisName = 'Left';
break;
case AxisSide.top:
axisName = 'Top';
break;
case AxisSide.right:
axisName = 'Right';
break;
case AxisSide.bottom:
axisName = 'Bottom';
break;
default:
throw StateError('Invalid');
}
final axisName = switch (side) {
AxisSide.left => 'Left',
AxisSide.top => 'Top',
AxisSide.right => 'Right',
AxisSide.bottom => 'Bottom',
};
expect(find.text('$axisName Titles'), findsOneWidget);
for (var i = 0; i <= 10; i++) {
expect(find.text('${axisName.characters.first}-$i'), findsOneWidget);
Expand Down

0 comments on commit 872878b

Please sign in to comment.