diff --git a/analysis_options.yaml b/analysis_options.yaml index c7c7c577f..8dd99c73e 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,3 +1,4 @@ +include: package:pedantic/analysis_options.1.9.0.yaml analyzer: strong-mode: implicit-dynamic: false @@ -19,140 +20,4 @@ analyzer: - 'lib/i18n/stock_messages_*.dart' - 'lib/src/http/**' - 'example/**' - -linter: - rules: - # these rules are documented on and in the same order as - # the Dart Lint rules page to make maintenance easier - # https://github.com/dart-lang/linter/blob/master/example/all.yaml - - always_declare_return_types - - always_put_control_body_on_new_line - # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219 - - always_require_non_null_named_parameters - - annotate_overrides - # - avoid_annotating_with_dynamic # conflicts with always_specify_types - - avoid_as - # - avoid_bool_literals_in_conditional_expressions # not yet tested - # - avoid_catches_without_on_clauses # we do this commonly - # - avoid_catching_errors # we do this commonly - - avoid_classes_with_only_static_members - # - avoid_double_and_int_checks # only useful when targeting JS runtime - - avoid_empty_else - - avoid_field_initializers_in_const_classes - - avoid_function_literals_in_foreach_calls - # - avoid_implementing_value_types # not yet tested - - avoid_init_to_null - # - avoid_js_rounded_ints # only useful when targeting JS runtime - - avoid_null_checks_in_equality_operators - # - avoid_positional_boolean_parameters # not yet tested - # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356) - - avoid_relative_lib_imports - - avoid_renaming_method_parameters - - avoid_return_types_on_setters - # - avoid_returning_null # there are plenty of valid reasons to return null - # - avoid_returning_null_for_future # not yet tested - - avoid_returning_null_for_void - # - avoid_returning_this # there are plenty of valid reasons to return this - # - avoid_setters_without_getters # not yet tested - # - avoid_shadowing_type_parameters # not yet tested - # - avoid_single_cascade_in_expression_statements # not yet tested - - avoid_slow_async_io - - avoid_types_as_parameter_names - # - avoid_types_on_closure_parameters # conflicts with always_specify_types - - avoid_unused_constructor_parameters - - avoid_void_async - - await_only_futures - - camel_case_types - - cancel_subscriptions - # - cascade_invocations # not yet tested - # - close_sinks # not reliable enough - # - comment_references # blocked on https://github.com/flutter/flutter/issues/20765 - # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204 - - control_flow_in_finally - # - curly_braces_in_flow_control_structures # not yet tested -# - directives_ordering - - empty_catches - - empty_constructor_bodies - - empty_statements - # - file_names # not yet tested - - flutter_style_todos - - hash_and_equals - - implementation_imports - # - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811 - - iterable_contains_unrelated_type - # - join_return_with_assignment # not yet tested - - library_names - - library_prefixes - # - lines_longer_than_80_chars # not yet tested - - list_remove_unrelated_type - # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181 - - no_adjacent_strings_in_list - - no_duplicate_case_values - - non_constant_identifier_names - # - null_closures # not yet tested - # - omit_local_variable_types # opposite of always_specify_types - # - one_member_abstracts # too many false positives - # - only_throw_errors # https://github.com/flutter/flutter/issues/5792 - - overridden_fields - - package_api_docs - - package_names - - package_prefixed_library_names - # - parameter_assignments # we do this commonly - - prefer_adjacent_string_concatenation - - prefer_asserts_in_initializer_lists - - prefer_collection_literals - - prefer_conditional_assignment - - prefer_const_constructors - - prefer_const_constructors_in_immutables - - prefer_const_declarations - - prefer_const_literals_to_create_immutables - # - prefer_constructors_over_static_methods # not yet tested - - prefer_contains - - prefer_equal_for_default_values - # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods - - prefer_final_fields - - prefer_final_locals - - prefer_foreach - # - prefer_function_declarations_over_variables # not yet tested - - prefer_generic_function_type_aliases - # - prefer_initializing_formals # Fucked up with Equatable, because it's added props field, then we couldn't have const constructor. - # - prefer_int_literals # not yet tested - # - prefer_interpolation_to_compose_strings # not yet tested - - prefer_is_empty - - prefer_is_not_empty - - prefer_iterable_whereType - # - prefer_mixin # https://github.com/dart-lang/language/issues/32 - # - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932 - - prefer_single_quotes - - prefer_typing_uninitialized_variables - - prefer_void_to_null - # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml - - recursive_getters - - slash_for_doc_comments - - sort_pub_dependencies - # - super_goes_last # no longer needed w/ Dart 2 - - test_types_in_equals - - throw_in_finally - # - type_annotate_public_apis # subset of always_specify_types - - type_init_formals - # - unawaited_futures # too many false positives - # - unnecessary_await_in_return # not yet tested - - unnecessary_brace_in_string_interps - - unnecessary_const - - unnecessary_getters_setters - # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498 - - unnecessary_new - - unnecessary_null_aware_assignments - - unnecessary_null_in_if_null_operators - - unnecessary_overrides - - unnecessary_parenthesis - - unnecessary_statements - - unnecessary_this - - unrelated_type_equality_checks - # - use_function_type_syntax_for_parameters # not yet tested - - use_rethrow_when_possible - # - use_setters_to_change_properties # not yet tested - # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182 - # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review - - valid_regexps - # - void_checks # not yet tested \ No newline at end of file + - 'test/**' \ No newline at end of file diff --git a/lib/src/chart/bar_chart/bar_chart.dart b/lib/src/chart/bar_chart/bar_chart.dart index 3daa7d65e..b029b65b5 100644 --- a/lib/src/chart/bar_chart/bar_chart.dart +++ b/lib/src/chart/bar_chart/bar_chart.dart @@ -35,12 +35,12 @@ class _BarChartState extends AnimatedWidgetBaseState { @override Widget build(BuildContext context) { - final BarChartData showingData = _getData(); - final BarTouchData touchData = showingData.barTouchData; + final showingData = _getData(); + final touchData = showingData.barTouchData; return GestureDetector( onLongPressStart: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -52,7 +52,7 @@ class _BarChartState extends AnimatedWidgetBaseState { } }, onLongPressEnd: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -64,7 +64,7 @@ class _BarChartState extends AnimatedWidgetBaseState { } }, onLongPressMoveUpdate: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -76,7 +76,7 @@ class _BarChartState extends AnimatedWidgetBaseState { } }, onPanCancel: () { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -88,7 +88,7 @@ class _BarChartState extends AnimatedWidgetBaseState { } }, onPanEnd: (DragEndDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -100,7 +100,7 @@ class _BarChartState extends AnimatedWidgetBaseState { } }, onPanDown: (DragDownDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -112,7 +112,7 @@ class _BarChartState extends AnimatedWidgetBaseState { } }, onPanUpdate: (DragUpdateDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -153,8 +153,8 @@ class _BarChartState extends AnimatedWidgetBaseState { return barChartData; } - final List newGroups = []; - for (int i = 0; i < barChartData.barGroups.length; i++) { + final newGroups = []; + for (var i = 0; i < barChartData.barGroups.length; i++) { final group = barChartData.barGroups[i]; newGroups.add( diff --git a/lib/src/chart/bar_chart/bar_chart_data.dart b/lib/src/chart/bar_chart/bar_chart_data.dart index f453ca0b5..fa9a973d7 100644 --- a/lib/src/chart/bar_chart/bar_chart_data.dart +++ b/lib/src/chart/bar_chart/bar_chart_data.dart @@ -83,8 +83,8 @@ class BarChartData extends AxisChartData with EquatableMixin { double maxY, double minY, ) { - for (int i = 0; i < barGroups.length; i++) { - final BarChartGroupData barData = barGroups[i]; + for (var i = 0; i < barGroups.length; i++) { + final barData = barGroups[i]; if (barData.barRods == null || barData.barRods.isEmpty) { throw Exception('barRods could not be null or empty'); } @@ -101,10 +101,10 @@ class BarChartData extends AxisChartData with EquatableMixin { minY = 0; } - for (int i = 0; i < barGroups.length; i++) { - final BarChartGroupData barGroup = barGroups[i]; - for (int j = 0; j < barGroup.barRods.length; j++) { - final BarChartRodData rod = barGroup.barRods[j]; + for (var i = 0; i < barGroups.length; i++) { + final barGroup = barGroups[i]; + for (var j = 0; j < barGroup.barRods.length; j++) { + final rod = barGroup.barRods[j]; if (canModifyMaxY && rod.y > maxY) { maxY = rod.y; @@ -266,9 +266,9 @@ class BarChartGroupData with EquatableMixin { return 0; } - final double sumWidth = + final sumWidth = barRods.map((rodData) => rodData.width).reduce((first, second) => first + second); - final double spaces = (barRods.length - 1) * barsSpace; + final spaces = (barRods.length - 1) * barsSpace; return sumWidth + spaces; } @@ -752,7 +752,7 @@ BarTooltipItem defaultBarTooltipItem( BarChartRodData rod, int rodIndex, ) { - const TextStyle textStyle = TextStyle( + const textStyle = TextStyle( color: Colors.black, fontWeight: FontWeight.bold, fontSize: 14, diff --git a/lib/src/chart/bar_chart/bar_chart_painter.dart b/lib/src/chart/bar_chart/bar_chart_painter.dart index a30580250..4c5efc2f5 100644 --- a/lib/src/chart/bar_chart/bar_chart_painter.dart +++ b/lib/src/chart/bar_chart/bar_chart_painter.dart @@ -49,16 +49,16 @@ class BarChartPainter extends AxisChartPainter with TouchHandler groupsX = _calculateGroupsX(size, data.barGroups, data.alignment); + final groupsX = _calculateGroupsX(size, data.barGroups, data.alignment); _groupBarsPosition = _calculateGroupAndBarsPosition(size, groupsX, data.barGroups); _drawBars(canvasWrapper, _groupBarsPosition); drawAxisTitles(canvasWrapper); _drawTitles(canvasWrapper, _groupBarsPosition); - for (int i = 0; i < targetData.barGroups.length; i++) { + for (var i = 0; i < targetData.barGroups.length; i++) { final barGroup = targetData.barGroups[i]; - for (int j = 0; j < barGroup.barRods.length; j++) { + for (var j = 0; j < barGroup.barRods.length; j++) { if (!barGroup.showingTooltipIndicators.contains(j)) { continue; } @@ -73,15 +73,15 @@ class BarChartPainter extends AxisChartPainter with TouchHandler _calculateGroupsX( Size viewSize, List barGroups, BarChartAlignment alignment) { - final Size drawSize = getChartUsableDrawSize(viewSize); + final drawSize = getChartUsableDrawSize(viewSize); - final List groupsX = List(barGroups.length); + final groupsX = List(barGroups.length); - final double leftTextsSpace = getLeftOffsetDrawSize(); + final leftTextsSpace = getLeftOffsetDrawSize(); switch (alignment) { case BarChartAlignment.start: - double tempX = 0; + var tempX = 0.0; barGroups.asMap().forEach((i, group) { groupsX[i] = leftTextsSpace + tempX + group.width / 2; tempX += group.width; @@ -89,8 +89,8 @@ class BarChartPainter extends AxisChartPainter with TouchHandler= 0; i--) { + var tempX = 0.0; + for (var i = barGroups.length - 1; i >= 0; i--) { final group = barGroups[i]; groupsX[i] = (leftTextsSpace + drawSize.width) - tempX - group.width / 2; tempX += group.width; @@ -98,26 +98,26 @@ class BarChartPainter extends AxisChartPainter with TouchHandler group.width).reduce((a, b) => a + b); + var sumWidth = barGroups.map((group) => group.width).reduce((a, b) => a + b); sumWidth += data.groupsSpace * (barGroups.length - 1); - final double horizontalMargin = (drawSize.width - sumWidth) / 2; + final horizontalMargin = (drawSize.width - sumWidth) / 2; - double tempX = 0; - for (int i = 0; i < barGroups.length; i++) { + var tempX = 0.0; + for (var i = 0; i < barGroups.length; i++) { final group = barGroups[i]; groupsX[i] = leftTextsSpace + horizontalMargin + tempX + group.width / 2; - final double groupSpace = i == barGroups.length - 1 ? 0 : data.groupsSpace; + final groupSpace = i == barGroups.length - 1 ? 0 : data.groupsSpace; tempX += group.width + groupSpace; } break; case BarChartAlignment.spaceBetween: - final double sumWidth = barGroups.map((group) => group.width).reduce((a, b) => a + b); - final double spaceAvailable = drawSize.width - sumWidth; - final double eachSpace = spaceAvailable / (barGroups.length - 1); + final sumWidth = barGroups.map((group) => group.width).reduce((a, b) => a + b); + final spaceAvailable = drawSize.width - sumWidth; + final eachSpace = spaceAvailable / (barGroups.length - 1); - double tempX = 0; + var tempX = 0.0; barGroups.asMap().forEach((index, group) { tempX += group.width / 2; if (index != 0) { @@ -129,11 +129,11 @@ class BarChartPainter extends AxisChartPainter with TouchHandler group.width).reduce((a, b) => a + b); - final double spaceAvailable = drawSize.width - sumWidth; - final double eachSpace = spaceAvailable / (barGroups.length * 2); + final sumWidth = barGroups.map((group) => group.width).reduce((a, b) => a + b); + final spaceAvailable = drawSize.width - sumWidth; + final eachSpace = spaceAvailable / (barGroups.length * 2); - double tempX = 0; + var tempX = 0.0; barGroups.asMap().forEach((i, group) { tempX += eachSpace; tempX += group.width / 2; @@ -144,11 +144,11 @@ class BarChartPainter extends AxisChartPainter with TouchHandler group.width).reduce((a, b) => a + b); - final double spaceAvailable = drawSize.width - sumWidth; - final double eachSpace = spaceAvailable / (barGroups.length + 1); + final sumWidth = barGroups.map((group) => group.width).reduce((a, b) => a + b); + final spaceAvailable = drawSize.width - sumWidth; + final eachSpace = spaceAvailable / (barGroups.length + 1); - double tempX = 0; + var tempX = 0.0; barGroups.asMap().forEach((i, group) { tempX += eachSpace; tempX += group.width / 2; @@ -168,15 +168,15 @@ class BarChartPainter extends AxisChartPainter with TouchHandler groupBarsPosition = []; - for (int i = 0; i < barGroups.length; i++) { - final BarChartGroupData barGroup = barGroups[i]; - final double groupX = groupsX[i]; + final groupBarsPosition = <_GroupBarsPosition>[]; + for (var i = 0; i < barGroups.length; i++) { + final barGroup = barGroups[i]; + final groupX = groupsX[i]; - double tempX = 0; - final List barsX = []; + var tempX = 0.0; + final barsX = []; barGroup.barRods.asMap().forEach((barIndex, barRod) { - final double widthHalf = barRod.width / 2; + final widthHalf = barRod.width / 2; barsX.add(groupX - (barGroup.width / 2) + tempX + widthHalf); tempX += barRod.width + barGroup.barsSpace; }); @@ -189,15 +189,14 @@ class BarChartPainter extends AxisChartPainter with TouchHandler with TouchHandler stops = []; + var stops = []; if (barRod.backDrawRodData.colorStops == null || barRod.backDrawRodData.colorStops.length != barRod.backDrawRodData.colors.length) { /// provided colorStops is invalid and we calculate it here @@ -296,7 +295,7 @@ class BarChartPainter extends AxisChartPainter with TouchHandler stops = []; + var stops = []; if (barRod.colorStops == null || barRod.colorStops.length != barRod.colors.length) { /// provided colorStops is invalid and we calculate it here barRod.colors.asMap().forEach((index, color) { @@ -324,7 +323,7 @@ class BarChartPainter extends AxisChartPainter with TouchHandler with TouchHandler with TouchHandler with TouchHandler with TouchHandler with TouchHandler with TouchHandler with TouchHandler with TouchHandler 0; - final double tooltipWidth = textWidth + tooltipData.tooltipPadding.horizontal; - final double tooltipHeight = textHeight + tooltipData.tooltipPadding.vertical; + final tooltipWidth = textWidth + tooltipData.tooltipPadding.horizontal; + final tooltipHeight = textHeight + tooltipData.tooltipPadding.vertical; - final double tooltipTop = isPositive + final tooltipTop = isPositive ? barOffset.dy - tooltipHeight - tooltipData.tooltipBottomMargin : barOffset.dy + tooltipData.tooltipBottomMargin; /// draw the background rect with rounded radius + // ignore: omit_local_variable_types Rect rect = Rect.fromLTWH(barOffset.dx - (tooltipWidth / 2), tooltipTop, tooltipWidth, tooltipHeight); @@ -597,14 +597,14 @@ class BarChartPainter extends AxisChartPainter with TouchHandler with TouchHandler with TouchHandler with TouchHandler with TouchHandler groupBarsPosition) { if (groupBarsPosition == null) { - final List groupsX = _calculateGroupsX(viewSize, data.barGroups, data.alignment); + final groupsX = _calculateGroupsX(viewSize, data.barGroups, data.alignment); groupBarsPosition = _calculateGroupAndBarsPosition(viewSize, groupsX, data.barGroups); } - final Size chartViewSize = getChartUsableDrawSize(viewSize); + final chartViewSize = getChartUsableDrawSize(viewSize); /// Find the nearest barRod - for (int i = 0; i < groupBarsPosition.length; i++) { - final _GroupBarsPosition groupBarPos = groupBarsPosition[i]; - for (int j = 0; j < groupBarPos.barsX.length; j++) { - final double barX = groupBarPos.barsX[j]; - final double barWidth = targetData.barGroups[i].barRods[j].width; - final double halfBarWidth = barWidth / 2; + for (var i = 0; i < groupBarsPosition.length; i++) { + final groupBarPos = groupBarsPosition[i]; + for (var j = 0; j < groupBarPos.barsX.length; j++) { + final barX = groupBarPos.barsX[j]; + final barWidth = targetData.barGroups[i].barRods[j].width; + final halfBarWidth = barWidth / 2; double barTopY; double barBotY; - final bool isPositive = targetData.barGroups[i].barRods[j].y > 0; + final isPositive = targetData.barGroups[i].barRods[j].y > 0; if (isPositive) { barTopY = getPixelY(targetData.barGroups[i].barRods[j].y, chartViewSize); barBotY = getPixelY(0, chartViewSize); @@ -728,15 +727,15 @@ class BarChartPainter extends AxisChartPainter with TouchHandler= barX - halfBarWidth - touchExtraThreshold.left); - final bool isYInBarBounds = (touchedPoint.dy <= barBotY + touchExtraThreshold.bottom) && + final isYInBarBounds = (touchedPoint.dy <= barBotY + touchExtraThreshold.bottom) && (touchedPoint.dy >= barTopY - touchExtraThreshold.top); bool isYInBarBackDrawBounds; @@ -748,7 +747,7 @@ class BarChartPainter extends AxisChartPainter with TouchHandler with TouchHandler= toPixel) { diff --git a/lib/src/chart/base/axis_chart/axis_chart_painter.dart b/lib/src/chart/base/axis_chart/axis_chart_painter.dart index 714e7b383..58a4f1602 100644 --- a/lib/src/chart/base/axis_chart/axis_chart_painter.dart +++ b/lib/src/chart/base/axis_chart/axis_chart_painter.dart @@ -56,8 +56,8 @@ abstract class AxisChartPainter extends BaseChartPainte // Left Title final leftTitle = axisTitles.leftTitle; if (leftTitle.showTitle) { - final TextSpan span = TextSpan(style: leftTitle.textStyle, text: leftTitle.titleText); - final TextPainter tp = TextPainter( + final span = TextSpan(style: leftTitle.textStyle, text: leftTitle.titleText); + final tp = TextPainter( text: span, textAlign: leftTitle.textAlign, textDirection: TextDirection.ltr, @@ -73,8 +73,8 @@ abstract class AxisChartPainter extends BaseChartPainte // Top title final topTitle = axisTitles.topTitle; if (topTitle.showTitle) { - final TextSpan span = TextSpan(style: topTitle.textStyle, text: topTitle.titleText); - final TextPainter tp = TextPainter( + final span = TextSpan(style: topTitle.textStyle, text: topTitle.titleText); + final tp = TextPainter( text: span, textAlign: topTitle.textAlign, textDirection: TextDirection.ltr, @@ -87,8 +87,8 @@ abstract class AxisChartPainter extends BaseChartPainte // Right Title final rightTitle = axisTitles.rightTitle; if (rightTitle.showTitle) { - final TextSpan span = TextSpan(style: rightTitle.textStyle, text: rightTitle.titleText); - final TextPainter tp = TextPainter( + final span = TextSpan(style: rightTitle.textStyle, text: rightTitle.titleText); + final tp = TextPainter( text: span, textAlign: rightTitle.textAlign, textDirection: TextDirection.ltr, @@ -106,8 +106,8 @@ abstract class AxisChartPainter extends BaseChartPainte // Bottom title final bottomTitle = axisTitles.bottomTitle; if (bottomTitle.showTitle) { - final TextSpan span = TextSpan(style: bottomTitle.textStyle, text: bottomTitle.titleText); - final TextPainter tp = TextPainter( + final span = TextSpan(style: bottomTitle.textStyle, text: bottomTitle.titleText); + final tp = TextPainter( text: span, textAlign: bottomTitle.textAlign, textDirection: TextDirection.ltr, @@ -126,7 +126,7 @@ abstract class AxisChartPainter extends BaseChartPainte /// It returns extra needed spaces in left and right side of the chart. @override double getExtraNeededHorizontalSpace() { - double sum = super.getExtraNeededHorizontalSpace(); + var sum = super.getExtraNeededHorizontalSpace(); if (data.axisTitleData.show) { final leftSide = data.axisTitleData.leftTitle; @@ -149,7 +149,7 @@ abstract class AxisChartPainter extends BaseChartPainte /// It returns extra needed spaces in bottom and top side of the chart. @override double getExtraNeededVerticalSpace() { - double sum = super.getExtraNeededVerticalSpace(); + var sum = super.getExtraNeededVerticalSpace(); if (data.axisTitleData.show) { final topSide = data.axisTitleData.topTitle; @@ -206,27 +206,27 @@ abstract class AxisChartPainter extends BaseChartPainte final usableViewSize = getChartUsableDrawSize(viewSize); // Show Vertical Grid if (data.gridData.drawVerticalLine) { - final double verticalInterval = data.gridData.verticalInterval ?? + final verticalInterval = data.gridData.verticalInterval ?? getEfficientInterval(viewSize.width, data.horizontalDiff); - double verticalSeek = data.minX + verticalInterval; + var verticalSeek = data.minX + verticalInterval; - final double delta = data.maxX - data.minX; - final int count = delta ~/ verticalInterval; - final double lastPosition = count * verticalSeek; - final bool lastPositionOverlapsWithBorder = lastPosition == data.maxX; + final delta = data.maxX - data.minX; + final count = delta ~/ verticalInterval; + final lastPosition = count * verticalSeek; + final lastPositionOverlapsWithBorder = lastPosition == data.maxX; final end = lastPositionOverlapsWithBorder ? data.maxX - verticalInterval : data.maxX; while (verticalSeek <= end) { if (data.gridData.checkToShowVerticalLine(verticalSeek)) { - final FlLine flLineStyle = data.gridData.getDrawingVerticalLine(verticalSeek); + final flLineStyle = data.gridData.getDrawingVerticalLine(verticalSeek); _gridPaint.color = flLineStyle.color; _gridPaint.strokeWidth = flLineStyle.strokeWidth; - final double bothX = getPixelX(verticalSeek, usableViewSize); - final double x1 = bothX; - final double y1 = 0 + getTopOffsetDrawSize(); - final double x2 = bothX; - final double y2 = usableViewSize.height + getTopOffsetDrawSize(); + final bothX = getPixelX(verticalSeek, usableViewSize); + final x1 = bothX; + final y1 = 0 + getTopOffsetDrawSize(); + final x2 = bothX; + final y2 = usableViewSize.height + getTopOffsetDrawSize(); canvasWrapper.drawDashedLine( Offset(x1, y1), Offset(x2, y2), _gridPaint, flLineStyle.dashArray); } @@ -236,28 +236,28 @@ abstract class AxisChartPainter extends BaseChartPainte // Show Horizontal Grid if (data.gridData.drawHorizontalLine) { - final double horizontalInterval = data.gridData.horizontalInterval ?? + final horizontalInterval = data.gridData.horizontalInterval ?? getEfficientInterval(viewSize.height, data.verticalDiff); - double horizontalSeek = data.minY + horizontalInterval; + var horizontalSeek = data.minY + horizontalInterval; - final double delta = data.maxY - data.minY; - final int count = delta ~/ horizontalInterval; - final double lastPosition = count * horizontalSeek; - final bool lastPositionOverlapsWithBorder = lastPosition == data.maxY; + final delta = data.maxY - data.minY; + final count = delta ~/ horizontalInterval; + final lastPosition = count * horizontalSeek; + final lastPositionOverlapsWithBorder = lastPosition == data.maxY; final end = lastPositionOverlapsWithBorder ? data.maxY - horizontalInterval : data.maxY; while (horizontalSeek <= end) { if (data.gridData.checkToShowHorizontalLine(horizontalSeek)) { - final FlLine flLine = data.gridData.getDrawingHorizontalLine(horizontalSeek); + final flLine = data.gridData.getDrawingHorizontalLine(horizontalSeek); _gridPaint.color = flLine.color; _gridPaint.strokeWidth = flLine.strokeWidth; - final double bothY = getPixelY(horizontalSeek, usableViewSize); - final double x1 = 0 + getLeftOffsetDrawSize(); - final double y1 = bothY; - final double x2 = usableViewSize.width + getLeftOffsetDrawSize(); - final double y2 = bothY; + final bothY = getPixelY(horizontalSeek, usableViewSize); + final x1 = 0 + getLeftOffsetDrawSize(); + final y1 = bothY; + final x2 = usableViewSize.width + getLeftOffsetDrawSize(); + final y2 = bothY; canvasWrapper.drawDashedLine( Offset(x1, y1), Offset(x2, y2), _gridPaint, flLine.dashArray); } @@ -274,7 +274,7 @@ abstract class AxisChartPainter extends BaseChartPainte } final viewSize = canvasWrapper.size; - final Size usableViewSize = getChartUsableDrawSize(viewSize); + final usableViewSize = getChartUsableDrawSize(viewSize); _backgroundPaint.color = data.backgroundColor; canvasWrapper.drawRect( Rect.fromLTWH( @@ -293,18 +293,18 @@ abstract class AxisChartPainter extends BaseChartPainte } final viewSize = canvasWrapper.size; - final Size chartUsableSize = getChartUsableDrawSize(viewSize); + final chartUsableSize = getChartUsableDrawSize(viewSize); if (data.rangeAnnotations.verticalRangeAnnotations.isNotEmpty) { - for (VerticalRangeAnnotation annotation in data.rangeAnnotations.verticalRangeAnnotations) { - final double topChartPadding = getTopOffsetDrawSize(); - final Offset from = Offset(getPixelX(annotation.x1, chartUsableSize), topChartPadding); + for (var annotation in data.rangeAnnotations.verticalRangeAnnotations) { + final topChartPadding = getTopOffsetDrawSize(); + final from = Offset(getPixelX(annotation.x1, chartUsableSize), topChartPadding); - final double bottomChartPadding = getExtraNeededVerticalSpace() - getTopOffsetDrawSize(); - final Offset to = Offset( + final bottomChartPadding = getExtraNeededVerticalSpace() - getTopOffsetDrawSize(); + final to = Offset( getPixelX(annotation.x2, chartUsableSize), viewSize.height - bottomChartPadding); //9 - final Rect rect = Rect.fromPoints(from, to); + final rect = Rect.fromPoints(from, to); _rangeAnnotationPaint.color = annotation.color; @@ -313,16 +313,15 @@ abstract class AxisChartPainter extends BaseChartPainte } if (data.rangeAnnotations.horizontalRangeAnnotations.isNotEmpty) { - for (HorizontalRangeAnnotation annotation - in data.rangeAnnotations.horizontalRangeAnnotations) { - final double leftChartPadding = getLeftOffsetDrawSize(); - final Offset from = Offset(leftChartPadding, getPixelY(annotation.y1, chartUsableSize)); + for (var annotation in data.rangeAnnotations.horizontalRangeAnnotations) { + final leftChartPadding = getLeftOffsetDrawSize(); + final from = Offset(leftChartPadding, getPixelY(annotation.y1, chartUsableSize)); - final double rightChartPadding = getExtraNeededHorizontalSpace() - getLeftOffsetDrawSize(); - final Offset to = + final rightChartPadding = getExtraNeededHorizontalSpace() - getLeftOffsetDrawSize(); + final to = Offset(viewSize.width - rightChartPadding, getPixelY(annotation.y2, chartUsableSize)); - final Rect rect = Rect.fromPoints(from, to); + final rect = Rect.fromPoints(from, to); _rangeAnnotationPaint.color = annotation.color; @@ -335,7 +334,7 @@ abstract class AxisChartPainter extends BaseChartPainte /// to the view base axis x . /// the view 0, 0 is on the top/left, but the spots is bottom/left double getPixelX(double spotX, Size chartUsableSize) { - final double deltaX = data.maxX - data.minX; + final deltaX = data.maxX - data.minX; if (deltaX == 0.0) { return getLeftOffsetDrawSize(); } @@ -348,12 +347,12 @@ abstract class AxisChartPainter extends BaseChartPainte double spotY, Size chartUsableSize, ) { - final double deltaY = data.maxY - data.minY; + final deltaY = data.maxY - data.minY; if (deltaY == 0.0) { return chartUsableSize.height + getTopOffsetDrawSize(); } - double y = ((spotY - data.minY) / deltaY) * chartUsableSize.height; + var y = ((spotY - data.minY) / deltaY) * chartUsableSize.height; y = chartUsableSize.height - y; return y + getTopOffsetDrawSize(); } diff --git a/lib/src/chart/base/base_chart/base_chart_painter.dart b/lib/src/chart/base/base_chart/base_chart_painter.dart index 3de737781..860336f7c 100644 --- a/lib/src/chart/base/base_chart/base_chart_painter.dart +++ b/lib/src/chart/base/base_chart/base_chart_painter.dart @@ -41,7 +41,7 @@ abstract class BaseChartPainter extends CustomPainter { getTopOffsetDrawSize() + chartViewSize.height); /// Draw Top Line - final BorderSide topBorder = data.borderData.border.top; + final topBorder = data.borderData.border.top; if (topBorder.width != 0.0) { _borderPaint.color = topBorder.color; _borderPaint.strokeWidth = topBorder.width; @@ -49,7 +49,7 @@ abstract class BaseChartPainter extends CustomPainter { } /// Draw Right Line - final BorderSide rightBorder = data.borderData.border.right; + final rightBorder = data.borderData.border.right; if (rightBorder.width != 0.0) { _borderPaint.color = rightBorder.color; _borderPaint.strokeWidth = rightBorder.width; @@ -57,7 +57,7 @@ abstract class BaseChartPainter extends CustomPainter { } /// Draw Bottom Line - final BorderSide bottomBorder = data.borderData.border.bottom; + final bottomBorder = data.borderData.border.bottom; if (bottomBorder.width != 0.0) { _borderPaint.color = bottomBorder.color; _borderPaint.strokeWidth = bottomBorder.width; @@ -65,7 +65,7 @@ abstract class BaseChartPainter extends CustomPainter { } /// Draw Left Line - final BorderSide leftBorder = data.borderData.border.left; + final leftBorder = data.borderData.border.left; if (leftBorder.width != 0.0) { _borderPaint.color = leftBorder.color; _borderPaint.strokeWidth = leftBorder.width; diff --git a/lib/src/chart/line_chart/line_chart.dart b/lib/src/chart/line_chart/line_chart.dart index 5076bed1d..84a3af4fa 100644 --- a/lib/src/chart/line_chart/line_chart.dart +++ b/lib/src/chart/line_chart/line_chart.dart @@ -40,12 +40,12 @@ class _LineChartState extends AnimatedWidgetBaseState { @override Widget build(BuildContext context) { - final LineChartData showingData = _getData(); - final LineTouchData touchData = showingData.lineTouchData; + final showingData = _getData(); + final touchData = showingData.lineTouchData; return GestureDetector( onLongPressStart: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -57,7 +57,7 @@ class _LineChartState extends AnimatedWidgetBaseState { } }, onLongPressEnd: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -69,7 +69,7 @@ class _LineChartState extends AnimatedWidgetBaseState { } }, onLongPressMoveUpdate: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -81,7 +81,7 @@ class _LineChartState extends AnimatedWidgetBaseState { } }, onPanCancel: () { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -93,7 +93,7 @@ class _LineChartState extends AnimatedWidgetBaseState { } }, onPanEnd: (DragEndDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -105,7 +105,7 @@ class _LineChartState extends AnimatedWidgetBaseState { } }, onPanDown: (DragDownDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -117,7 +117,7 @@ class _LineChartState extends AnimatedWidgetBaseState { } }, onPanUpdate: (DragUpdateDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -197,7 +197,7 @@ class _LineChartState extends AnimatedWidgetBaseState { sortedLineSpots.sort((spot1, spot2) => spot2.y.compareTo(spot1.y)); _showingTouchedIndicators.clear(); - for (int i = 0; i < touchResponse.lineBarSpots.length; i++) { + for (var i = 0; i < touchResponse.lineBarSpots.length; i++) { final touchedBarSpot = touchResponse.lineBarSpots[i]; final barPos = touchedBarSpot.barIndex; _showingTouchedIndicators[barPos] = [touchedBarSpot.spotIndex]; diff --git a/lib/src/chart/line_chart/line_chart_data.dart b/lib/src/chart/line_chart/line_chart_data.dart index 320d41505..6591b15c5 100644 --- a/lib/src/chart/line_chart/line_chart_data.dart +++ b/lib/src/chart/line_chart/line_chart_data.dart @@ -105,8 +105,8 @@ class LineChartData extends AxisChartData with EquatableMixin { double minY, double maxY, ) { - for (int i = 0; i < lineBarsData.length; i++) { - final LineChartBarData lineBarChart = lineBarsData[i]; + for (var i = 0; i < lineBarsData.length; i++) { + final lineBarChart = lineBarsData[i]; if (lineBarChart.spots == null || lineBarChart.spots.isEmpty) { throw Exception('spots could not be null or empty'); } @@ -117,10 +117,10 @@ class LineChartData extends AxisChartData with EquatableMixin { final canModifyMinY = minY == null; final canModifyMaxY = maxY == null; - for (int i = 0; i < lineBarsData.length; i++) { - final LineChartBarData barData = lineBarsData[i]; - for (int j = 0; j < barData.spots.length; j++) { - final FlSpot spot = barData.spots[j]; + for (var i = 0; i < lineBarsData.length; i++) { + final barData = lineBarsData[i]; + for (var j = 0; j < barData.spots.length; j++) { + final spot = barData.spots[j]; if (spot.isNotNull()) { if (canModifyMaxX && (maxX == null || spot.x > maxX)) { maxX = spot.x; @@ -1440,14 +1440,14 @@ List defaultTouchedIndicators( } return indicators.map((int index) { /// Indicator Line - Color lineColor = barData.colors[0]; + var lineColor = barData.colors[0]; if (barData.dotData.show) { lineColor = _defaultGetDotColor(barData.spots[index], 0, barData); } - const double lineStrokeWidth = 4; - final FlLine flLine = FlLine(color: lineColor, strokeWidth: lineStrokeWidth); + const lineStrokeWidth = 4.0; + final flLine = FlLine(color: lineColor, strokeWidth: lineStrokeWidth); - double dotSize = 10; + var dotSize = 10.0; if (barData.dotData.show) { dotSize = 4.0 * 1.8; } @@ -1557,7 +1557,7 @@ List defaultLineTooltipItem(List touchedSpots) { if (touchedSpot == null) { return null; } - final TextStyle textStyle = TextStyle( + final textStyle = TextStyle( color: touchedSpot.bar.colors[0], fontWeight: FontWeight.bold, fontSize: 14, diff --git a/lib/src/chart/line_chart/line_chart_painter.dart b/lib/src/chart/line_chart/line_chart_painter.dart index fa2f3435f..a322b2097 100644 --- a/lib/src/chart/line_chart/line_chart_painter.dart +++ b/lib/src/chart/line_chart/line_chart_painter.dart @@ -85,7 +85,7 @@ class LineChartPainter extends AxisChartPainter super.paint(canvas, size); - for (BetweenBarsData betweenBarsData in data.betweenBarsData) { + for (var betweenBarsData in data.betweenBarsData) { _drawBetweenBarsArea(canvasWrapper, data, betweenBarsData); } @@ -94,7 +94,7 @@ class LineChartPainter extends AxisChartPainter } /// draw each line independently on the chart - for (int i = 0; i < data.lineBarsData.length; i++) { + for (var i = 0; i < data.lineBarsData.length; i++) { final barData = data.lineBarsData[i]; if (!barData.show) { @@ -119,16 +119,16 @@ class LineChartPainter extends AxisChartPainter _drawTitles(canvasWrapper); // Draw touch tooltip on most top spot - for (int i = 0; i < data.showingTooltipIndicators.length; i++) { - ShowingTooltipIndicators tooltipSpots = data.showingTooltipIndicators[i]; + for (var i = 0; i < data.showingTooltipIndicators.length; i++) { + var tooltipSpots = data.showingTooltipIndicators[i]; - final List showingBarSpots = tooltipSpots.showingSpots; + final showingBarSpots = tooltipSpots.showingSpots; if (showingBarSpots.isEmpty) { continue; } - final List barSpots = List.of(showingBarSpots); + final barSpots = List.of(showingBarSpots); FlSpot topSpot = barSpots[0]; - for (LineBarSpot barSpot in barSpots) { + for (var barSpot in barSpots) { if (barSpot.y > topSpot.y) { topSpot = barSpot; } @@ -145,10 +145,10 @@ class LineChartPainter extends AxisChartPainter final usableSize = getChartUsableDrawSize(size); final border = data.borderData.show ? data.borderData.border : null; - double left = 0.0; - double top = 0.0; - double right = size.width; - double bottom = size.height; + var left = 0.0; + var top = 0.0; + var right = size.width; + var bottom = size.height; if (clip.left) { final borderWidth = border?.left?.width ?? 0; @@ -172,7 +172,7 @@ class LineChartPainter extends AxisChartPainter void _drawBarLine(CanvasWrapper canvasWrapper, LineChartBarData barData) { final viewSize = canvasWrapper.size; - final List> barList = [[]]; + final barList = >[[]]; // handle nullability by splitting off the list into multiple // separate lists when separated by nulls @@ -192,7 +192,7 @@ class LineChartPainter extends AxisChartPainter // bar is passed in separately from barData // because barData is the whole line // and bar is a piece of that line - for (List bar in barList) { + for (var bar in barList) { final barPath = _generateBarPath(viewSize, barData, bar); final belowBarPath = _generateBelowBarPath(viewSize, barData, barPath, bar); @@ -212,10 +212,10 @@ class LineChartPainter extends AxisChartPainter void _drawBetweenBarsArea( CanvasWrapper canvasWrapper, LineChartData data, BetweenBarsData betweenBarsData) { final viewSize = canvasWrapper.size; - final LineChartBarData fromBarData = data.lineBarsData[betweenBarsData.fromIndex]; - final LineChartBarData toBarData = data.lineBarsData[betweenBarsData.toIndex]; + final fromBarData = data.lineBarsData[betweenBarsData.fromIndex]; + final toBarData = data.lineBarsData[betweenBarsData.toIndex]; - final List spots = []; + final spots = []; spots.addAll(toBarData.spots.reversed.toList()); final fromBarPath = _generateBarPath( viewSize, @@ -240,16 +240,15 @@ class LineChartPainter extends AxisChartPainter final barXDelta = _getBarLineXLength(barData, viewSize); - for (int i = 0; i < barData.spots.length; i++) { - final FlSpot spot = barData.spots[i]; + for (var i = 0; i < barData.spots.length; i++) { + final spot = barData.spots[i]; if (spot.isNotNull() && barData.dotData.checkToShowDot(spot, barData)) { - final double x = getPixelX(spot.x, viewSize); - final double y = getPixelY(spot.y, viewSize); + final x = getPixelX(spot.x, viewSize); + final y = getPixelY(spot.y, viewSize); - final double xPercentInLine = ((x - getLeftOffsetDrawSize()) / barXDelta) * 100; + final xPercentInLine = ((x - getLeftOffsetDrawSize()) / barXDelta) * 100; - final FlDotPainter painter = - barData.dotData.getDotPainter(spot, xPercentInLine, barData, i); + final painter = barData.dotData.getDotPainter(spot, xPercentInLine, barData, i); canvasWrapper.drawDot(painter, spot, Offset(x, y)); } @@ -264,34 +263,33 @@ class LineChartPainter extends AxisChartPainter // Todo technical debt, we can read the TouchedSpotIndicatorData directly, // Todo instead of mapping indexes to TouchedSpotIndicatorData - final List indicatorsData = + final indicatorsData = data.lineTouchData.getTouchedSpotIndicator(barData, barData.showingIndicators); if (indicatorsData.length != barData.showingIndicators.length) { throw Exception('indicatorsData and touchedSpotOffsets size should be same'); } - for (int i = 0; i < barData.showingIndicators.length; i++) { - final TouchedSpotIndicatorData indicatorData = indicatorsData[i]; - final int index = barData.showingIndicators[i]; - final FlSpot spot = barData.spots[index]; + for (var i = 0; i < barData.showingIndicators.length; i++) { + final indicatorData = indicatorsData[i]; + final index = barData.showingIndicators[i]; + final spot = barData.spots[index]; if (indicatorData == null) { continue; } - final Offset touchedSpot = + final touchedSpot = Offset(getPixelX(spot.x, chartViewSize), getPixelY(spot.y, chartViewSize)); /// For drawing the dot - final bool showingDots = + final showingDots = indicatorData.touchedSpotDotData != null && indicatorData.touchedSpotDotData.show; - double dotHeight = 0; + var dotHeight = 0.0; FlDotPainter dotPainter; if (showingDots) { - final double xPercentInLine = - ((touchedSpot.dx - getLeftOffsetDrawSize()) / barXDelta) * 100; + final xPercentInLine = ((touchedSpot.dx - getLeftOffsetDrawSize()) / barXDelta) * 100; dotPainter = indicatorData.touchedSpotDotData.getDotPainter(spot, xPercentInLine, barData, index); dotHeight = dotPainter.getSize(spot).height; @@ -302,7 +300,7 @@ class LineChartPainter extends AxisChartPainter final top = Offset(getPixelX(spot.x, chartViewSize), getTopOffsetDrawSize()); /// Draw to top or to the touchedSpot - final Offset lineEnd = + final lineEnd = data.lineTouchData.fullHeightTouchLine ? top : touchedSpot + Offset(0, dotHeight / 2); _touchLinePaint.color = indicatorData.indicatorBelowLine.color; @@ -339,19 +337,19 @@ class LineChartPainter extends AxisChartPainter Path _generateNormalBarPath(Size viewSize, LineChartBarData barData, List barSpots, {Path appendToPath}) { viewSize = getChartUsableDrawSize(viewSize); - final Path path = appendToPath ?? Path(); - final int size = barSpots.length; + final path = appendToPath ?? Path(); + final size = barSpots.length; var temp = const Offset(0.0, 0.0); - final double x = getPixelX(barSpots[0].x, viewSize); - final double y = getPixelY(barSpots[0].y, viewSize); + final x = getPixelX(barSpots[0].x, viewSize); + final y = getPixelY(barSpots[0].y, viewSize); if (appendToPath == null) { path.moveTo(x, y); } else { path.lineTo(x, y); } - for (int i = 1; i < size; i++) { + for (var i = 1; i < size; i++) { /// CurrentSpot final current = Offset( getPixelX(barSpots[i].x, viewSize), @@ -409,17 +407,17 @@ class LineChartPainter extends AxisChartPainter Path _generateStepBarPath(Size viewSize, LineChartBarData barData, List barSpots, {Path appendToPath}) { viewSize = getChartUsableDrawSize(viewSize); - final Path path = appendToPath ?? Path(); - final int size = barSpots.length; + final path = appendToPath ?? Path(); + final size = barSpots.length; - final double x = getPixelX(barSpots[0].x, viewSize); - final double y = getPixelY(barSpots[0].y, viewSize); + final x = getPixelX(barSpots[0].x, viewSize); + final y = getPixelY(barSpots[0].y, viewSize); if (appendToPath == null) { path.moveTo(x, y); } else { path.lineTo(x, y); } - for (int i = 0; i < size; i++) { + for (var i = 0; i < size; i++) { /// CurrentSpot final current = Offset( getPixelX(barSpots[i].x, viewSize), @@ -461,7 +459,7 @@ class LineChartPainter extends AxisChartPainter final chartViewSize = getChartUsableDrawSize(viewSize); /// Line To Bottom Right - double x = getPixelX(barSpots[barSpots.length - 1].x, chartViewSize); + var x = getPixelX(barSpots[barSpots.length - 1].x, chartViewSize); double y; if (!fillCompletely && barData.belowBarData.applyCutOffY) { y = getPixelY(barData.belowBarData.cutOffY, chartViewSize); @@ -500,7 +498,7 @@ class LineChartPainter extends AxisChartPainter final chartViewSize = getChartUsableDrawSize(viewSize); /// Line To Top Right - double x = getPixelX(barSpots[barSpots.length - 1].x, chartViewSize); + var x = getPixelX(barSpots[barSpots.length - 1].x, chartViewSize); double y; if (!fillCompletely && barData.aboveBarData.applyCutOffY) { y = getPixelY(barData.aboveBarData.cutOffY, chartViewSize); @@ -545,7 +543,7 @@ class LineChartPainter extends AxisChartPainter _barAreaPaint.color = barData.belowBarData.colors[0]; _barAreaPaint.shader = null; } else { - List stops = []; + var stops = []; if (barData.belowBarData.gradientColorStops == null || barData.belowBarData.gradientColorStops.length != barData.belowBarData.colors.length) { /// provided gradientColorStops is invalid and we calculate it here @@ -587,14 +585,14 @@ class LineChartPainter extends AxisChartPainter /// draw below spots line if (barData.belowBarData.spotsLine != null && barData.belowBarData.spotsLine.show) { - for (FlSpot spot in barData.spots) { + for (var spot in barData.spots) { if (barData.belowBarData.spotsLine.checkToShowSpotLine(spot)) { - final Offset from = Offset( + final from = Offset( getPixelX(spot.x, chartViewSize), getPixelY(spot.y, chartViewSize), ); - final double bottomPadding = getExtraNeededVerticalSpace() - getTopOffsetDrawSize(); + final bottomPadding = getExtraNeededVerticalSpace() - getTopOffsetDrawSize(); Offset to; // Check applyCutOffY @@ -638,7 +636,7 @@ class LineChartPainter extends AxisChartPainter _barAreaPaint.color = barData.aboveBarData.colors[0]; _barAreaPaint.shader = null; } else { - List stops = []; + var stops = []; if (barData.aboveBarData.gradientColorStops == null || barData.aboveBarData.gradientColorStops.length != barData.aboveBarData.colors.length) { /// provided gradientColorStops is invalid and we calculate it here @@ -680,9 +678,9 @@ class LineChartPainter extends AxisChartPainter /// draw above spots line if (barData.aboveBarData.spotsLine != null && barData.aboveBarData.spotsLine.show) { - for (FlSpot spot in barData.spots) { + for (var spot in barData.spots) { if (barData.aboveBarData.spotsLine.checkToShowSpotLine(spot)) { - final Offset from = Offset( + final from = Offset( getPixelX(spot.x, chartViewSize), getPixelY(spot.y, chartViewSize), ); @@ -723,7 +721,7 @@ class LineChartPainter extends AxisChartPainter _barAreaPaint.color = betweenBarsData.colors[0]; _barAreaPaint.shader = null; } else { - List stops = []; + var stops = []; if (betweenBarsData.gradientColorStops == null || betweenBarsData.gradientColorStops.length != betweenBarsData.colors.length) { /// provided gradientColorStops is invalid and we calculate it here @@ -804,11 +802,11 @@ class LineChartPainter extends AxisChartPainter _barPaint.color = barData.colors[0]; _barPaint.shader = null; } else { - List stops = []; + var stops = []; if (barData.colorStops == null || barData.colorStops.length != barData.colors.length) { /// provided colorStops is invalid and we calculate it here barData.colors.asMap().forEach((index, color) { - final double percent = 1.0 / barData.colors.length; + final percent = 1.0 / barData.colors.length; stops.add(percent * index); }); } else { @@ -849,17 +847,17 @@ class LineChartPainter extends AxisChartPainter final leftInterval = leftTitles.interval ?? getEfficientInterval(viewSize.height, data.verticalDiff); if (leftTitles.showTitles) { - double verticalSeek = data.minY; + var verticalSeek = data.minY; while (verticalSeek <= data.maxY) { if (leftTitles.checkToShowTitle( data.minY, data.maxY, leftTitles, leftInterval, verticalSeek)) { - double x = 0 + getLeftOffsetDrawSize(); - double y = getPixelY(verticalSeek, viewSize); + var x = 0 + getLeftOffsetDrawSize(); + var y = getPixelY(verticalSeek, viewSize); - final String text = leftTitles.getTitles(verticalSeek); + final text = leftTitles.getTitles(verticalSeek); - final TextSpan span = TextSpan(style: leftTitles.getTextStyles(verticalSeek), text: text); - final TextPainter tp = TextPainter( + final span = TextSpan(style: leftTitles.getTextStyles(verticalSeek), text: text); + final tp = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -888,18 +886,17 @@ class LineChartPainter extends AxisChartPainter final topInterval = topTitles.interval ?? getEfficientInterval(viewSize.width, data.horizontalDiff); if (topTitles.showTitles) { - double horizontalSeek = data.minX; + var horizontalSeek = data.minX; while (horizontalSeek <= data.maxX) { if (topTitles.checkToShowTitle( data.minX, data.maxX, topTitles, topInterval, horizontalSeek)) { - double x = getPixelX(horizontalSeek, viewSize); - double y = getTopOffsetDrawSize(); + var x = getPixelX(horizontalSeek, viewSize); + var y = getTopOffsetDrawSize(); - final String text = topTitles.getTitles(horizontalSeek); + final text = topTitles.getTitles(horizontalSeek); - final TextSpan span = - TextSpan(style: topTitles.getTextStyles(horizontalSeek), text: text); - final TextPainter tp = TextPainter( + final span = TextSpan(style: topTitles.getTextStyles(horizontalSeek), text: text); + final tp = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -929,18 +926,17 @@ class LineChartPainter extends AxisChartPainter final rightInterval = rightTitles.interval ?? getEfficientInterval(viewSize.height, data.verticalDiff); if (rightTitles.showTitles) { - double verticalSeek = data.minY; + var verticalSeek = data.minY; while (verticalSeek <= data.maxY) { if (rightTitles.checkToShowTitle( data.minY, data.maxY, rightTitles, rightInterval, verticalSeek)) { - double x = viewSize.width + getLeftOffsetDrawSize(); - double y = getPixelY(verticalSeek, viewSize); + var x = viewSize.width + getLeftOffsetDrawSize(); + var y = getPixelY(verticalSeek, viewSize); - final String text = rightTitles.getTitles(verticalSeek); + final text = rightTitles.getTitles(verticalSeek); - final TextSpan span = - TextSpan(style: rightTitles.getTextStyles(verticalSeek), text: text); - final TextPainter tp = TextPainter( + final span = TextSpan(style: rightTitles.getTextStyles(verticalSeek), text: text); + final tp = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -971,16 +967,15 @@ class LineChartPainter extends AxisChartPainter final bottomInterval = bottomTitles.interval ?? getEfficientInterval(viewSize.width, data.horizontalDiff); if (bottomTitles.showTitles) { - double horizontalSeek = data.minX; + var horizontalSeek = data.minX; while (horizontalSeek <= data.maxX) { if (bottomTitles.checkToShowTitle( data.minX, data.maxX, bottomTitles, bottomInterval, horizontalSeek)) { - double x = getPixelX(horizontalSeek, viewSize); - double y = viewSize.height + getTopOffsetDrawSize(); - final String text = bottomTitles.getTitles(horizontalSeek); - final TextSpan span = - TextSpan(style: bottomTitles.getTextStyles(horizontalSeek), text: text); - final TextPainter tp = TextPainter( + var x = getPixelX(horizontalSeek, viewSize); + var y = viewSize.height + getTopOffsetDrawSize(); + final text = bottomTitles.getTitles(horizontalSeek); + final span = TextSpan(style: bottomTitles.getTextStyles(horizontalSeek), text: text); + final tp = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -1013,16 +1008,15 @@ class LineChartPainter extends AxisChartPainter } final viewSize = canvasWrapper.size; - final Size chartUsableSize = getChartUsableDrawSize(viewSize); + final chartUsableSize = getChartUsableDrawSize(viewSize); if (data.extraLinesData.horizontalLines.isNotEmpty) { - for (HorizontalLine line in data.extraLinesData.horizontalLines) { - final double leftChartPadding = getLeftOffsetDrawSize(); - final Offset from = Offset(leftChartPadding, getPixelY(line.y, chartUsableSize)); + for (var line in data.extraLinesData.horizontalLines) { + final leftChartPadding = getLeftOffsetDrawSize(); + final from = Offset(leftChartPadding, getPixelY(line.y, chartUsableSize)); - final double rightChartPadding = getExtraNeededHorizontalSpace() - getLeftOffsetDrawSize(); - final Offset to = - Offset(viewSize.width - rightChartPadding, getPixelY(line.y, chartUsableSize)); + final rightChartPadding = getExtraNeededHorizontalSpace() - getLeftOffsetDrawSize(); + final to = Offset(viewSize.width - rightChartPadding, getPixelY(line.y, chartUsableSize)); _extraLinesPaint.color = line.color; _extraLinesPaint.strokeWidth = line.strokeWidth; @@ -1030,10 +1024,10 @@ class LineChartPainter extends AxisChartPainter canvasWrapper.drawDashedLine(from, to, _extraLinesPaint, line.dashArray); if (line.sizedPicture != null) { - final double centerX = line.sizedPicture.width / 2; - final double centerY = line.sizedPicture.height / 2; - final double xPosition = leftChartPadding - centerX; - final double yPosition = to.dy - centerY; + final centerX = line.sizedPicture.width / 2; + final centerY = line.sizedPicture.height / 2; + final xPosition = leftChartPadding - centerX; + final yPosition = to.dy - centerY; canvasWrapper.save(); canvasWrapper.translate(xPosition, yPosition); @@ -1042,23 +1036,23 @@ class LineChartPainter extends AxisChartPainter } if (line.image != null) { - final double centerX = line.image.width / 2; - final double centerY = line.image.height / 2; - final Offset centeredImageOffset = Offset(leftChartPadding - centerX, to.dy - centerY); + final centerX = line.image.width / 2; + final centerY = line.image.height / 2; + final centeredImageOffset = Offset(leftChartPadding - centerX, to.dy - centerY); canvasWrapper.drawImage(line.image, centeredImageOffset, _imagePaint); } if (line.label != null && line.label.show) { - final HorizontalLineLabel label = line.label; - final TextStyle style = TextStyle(fontSize: 11, color: line.color).merge(label.style); + final label = line.label; + final style = TextStyle(fontSize: 11, color: line.color).merge(label.style); final EdgeInsets padding = label.padding ?? EdgeInsets.zero; - final TextSpan span = TextSpan( + final span = TextSpan( text: label.labelResolver(line), style: style, ); - final TextPainter tp = TextPainter( + final tp = TextPainter( text: span, textDirection: TextDirection.ltr, ); @@ -1079,13 +1073,12 @@ class LineChartPainter extends AxisChartPainter } if (data.extraLinesData.verticalLines.isNotEmpty) { - for (VerticalLine line in data.extraLinesData.verticalLines) { - final double topChartPadding = getTopOffsetDrawSize(); - final Offset from = Offset(getPixelX(line.x, chartUsableSize), topChartPadding); + for (var line in data.extraLinesData.verticalLines) { + final topChartPadding = getTopOffsetDrawSize(); + final from = Offset(getPixelX(line.x, chartUsableSize), topChartPadding); - final double bottomChartPadding = getExtraNeededVerticalSpace() - getTopOffsetDrawSize(); - final Offset to = - Offset(getPixelX(line.x, chartUsableSize), viewSize.height - bottomChartPadding); + final bottomChartPadding = getExtraNeededVerticalSpace() - getTopOffsetDrawSize(); + final to = Offset(getPixelX(line.x, chartUsableSize), viewSize.height - bottomChartPadding); _extraLinesPaint.color = line.color; _extraLinesPaint.strokeWidth = line.strokeWidth; @@ -1093,10 +1086,10 @@ class LineChartPainter extends AxisChartPainter canvasWrapper.drawDashedLine(from, to, _extraLinesPaint, line.dashArray); if (line.sizedPicture != null) { - final double centerX = line.sizedPicture.width / 2; - final double centerY = line.sizedPicture.height / 2; - final double xPosition = to.dx - centerX; - final double yPosition = viewSize.height - bottomChartPadding - centerY; + final centerX = line.sizedPicture.width / 2; + final centerY = line.sizedPicture.height / 2; + final xPosition = to.dx - centerX; + final yPosition = viewSize.height - bottomChartPadding - centerY; canvasWrapper.save(); canvasWrapper.translate(xPosition, yPosition); @@ -1104,24 +1097,24 @@ class LineChartPainter extends AxisChartPainter canvasWrapper.restore(); } if (line.image != null) { - final double centerX = line.image.width / 2; - final double centerY = line.image.height / 2; - final Offset centeredImageOffset = + final centerX = line.image.width / 2; + final centerY = line.image.height / 2; + final centeredImageOffset = Offset(to.dx - centerX, viewSize.height - bottomChartPadding - centerY); canvasWrapper.drawImage(line.image, centeredImageOffset, _imagePaint); } if (line.label != null && line.label.show) { - final VerticalLineLabel label = line.label; - final TextStyle style = TextStyle(fontSize: 11, color: line.color).merge(label.style); + final label = line.label; + final style = TextStyle(fontSize: 11, color: line.color).merge(label.style); final EdgeInsets padding = label.padding ?? EdgeInsets.zero; - final TextSpan span = TextSpan( + final span = TextSpan( text: label.labelResolver(line), style: style, ); - final TextPainter tp = TextPainter( + final tp = TextPainter( text: span, textDirection: TextDirection.ltr, ); @@ -1149,25 +1142,24 @@ class LineChartPainter extends AxisChartPainter final viewSize = canvasWrapper.size; final chartUsableSize = getChartUsableDrawSize(viewSize); - const double textsBelowMargin = 4; + const textsBelowMargin = 4; /// creating TextPainters to calculate the width and height of the tooltip - final List drawingTextPainters = []; + final drawingTextPainters = []; - final List tooltipItems = - tooltipData.getTooltipItems(showingTooltipSpots.showingSpots); + final tooltipItems = tooltipData.getTooltipItems(showingTooltipSpots.showingSpots); if (tooltipItems.length != showingTooltipSpots.showingSpots.length) { throw Exception('tooltipItems and touchedSpots size should be same'); } - for (int i = 0; i < showingTooltipSpots.showingSpots.length; i++) { - final LineTooltipItem tooltipItem = tooltipItems[i]; + for (var i = 0; i < showingTooltipSpots.showingSpots.length; i++) { + final tooltipItem = tooltipItems[i]; if (tooltipItem == null) { continue; } - final TextSpan span = TextSpan(style: tooltipItem.textStyle, text: tooltipItem.text); - final TextPainter tp = TextPainter( + final span = TextSpan(style: tooltipItem.textStyle, text: tooltipItem.text); + final tp = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -1186,9 +1178,9 @@ class LineChartPainter extends AxisChartPainter /// sumTextsHeight /// sum up all Texts height, then we should /// draw the tooltip's height as tall as sumTextsHeight - double biggerWidth = 0; - double sumTextsHeight = 0; - for (TextPainter tp in drawingTextPainters) { + var biggerWidth = 0.0; + var sumTextsHeight = 0.0; + for (var tp in drawingTextPainters) { if (tp.width > biggerWidth) { biggerWidth = tp.width; } @@ -1199,13 +1191,13 @@ class LineChartPainter extends AxisChartPainter /// if we have multiple bar lines, /// there are more than one FlCandidate on touch area, /// we should get the most top FlSpot Offset to draw the tooltip on top of it - final Offset mostTopOffset = Offset( + final mostTopOffset = Offset( getPixelX(showOnSpot.x, chartUsableSize), getPixelY(showOnSpot.y, chartUsableSize), ); - final double tooltipWidth = biggerWidth + tooltipData.tooltipPadding.horizontal; - final double tooltipHeight = sumTextsHeight + tooltipData.tooltipPadding.vertical; + final tooltipWidth = biggerWidth + tooltipData.tooltipPadding.horizontal; + final tooltipHeight = sumTextsHeight + tooltipData.tooltipPadding.vertical; double tooltipTopPosition; if (tooltipData.showOnTopOfTheChartBoxArea) { @@ -1215,7 +1207,7 @@ class LineChartPainter extends AxisChartPainter } /// draw the background rect with rounded radius - Rect rect = Rect.fromLTWH( + var rect = Rect.fromLTWH( mostTopOffset.dx - (tooltipWidth / 2), tooltipTopPosition, tooltipWidth, @@ -1266,15 +1258,15 @@ class LineChartPainter extends AxisChartPainter } } - final Radius radius = Radius.circular(tooltipData.tooltipRoundedRadius); - final RRect roundedRect = RRect.fromRectAndCorners(rect, + final radius = Radius.circular(tooltipData.tooltipRoundedRadius); + final roundedRect = RRect.fromRectAndCorners(rect, topLeft: radius, topRight: radius, bottomLeft: radius, bottomRight: radius); _bgTouchTooltipPaint.color = tooltipData.tooltipBgColor; canvasWrapper.drawRRect(roundedRect, _bgTouchTooltipPaint); /// draw the texts one by one in below of each other - double topPosSeek = tooltipData.tooltipPadding.top; - for (TextPainter tp in drawingTextPainters) { + var topPosSeek = tooltipData.tooltipPadding.top; + for (var tp in drawingTextPainters) { final drawOffset = Offset( rect.center.dx - (tp.width / 2), rect.topCenter.dy + topPosSeek, @@ -1306,7 +1298,7 @@ class LineChartPainter extends AxisChartPainter /// and the whole space is [getExtraNeededHorizontalSpace] @override double getExtraNeededHorizontalSpace() { - double sum = super.getExtraNeededHorizontalSpace(); + var sum = super.getExtraNeededHorizontalSpace(); if (data.titlesData.show) { final leftSide = data.titlesData.leftTitles; if (leftSide.showTitles) { @@ -1328,7 +1320,7 @@ class LineChartPainter extends AxisChartPainter /// and the whole space is [getExtraNeededVerticalSpace] @override double getExtraNeededVerticalSpace() { - double sum = super.getExtraNeededVerticalSpace(); + var sum = super.getExtraNeededVerticalSpace(); if (data.titlesData.show) { final topSide = data.titlesData.topTitles; if (topSide.showTitles) { @@ -1381,15 +1373,14 @@ class LineChartPainter extends AxisChartPainter LineTouchResponse handleTouch(FlTouchInput touchInput, Size size) { /// it holds list of nearest touched spots of each line /// and we use it to draw touch stuff on them - final List touchedSpots = []; + final touchedSpots = []; /// draw each line independently on the chart - for (int i = 0; i < data.lineBarsData.length; i++) { + for (var i = 0; i < data.lineBarsData.length; i++) { final barData = data.lineBarsData[i]; // find the nearest spot on touch area in this bar line - final LineBarSpot foundTouchedSpot = - _getNearestTouchedSpot(size, touchInput.getOffset(), barData, i); + final foundTouchedSpot = _getNearestTouchedSpot(size, touchInput.getOffset(), barData, i); if (foundTouchedSpot != null) { touchedSpots.add(foundTouchedSpot); } @@ -1405,10 +1396,10 @@ class LineChartPainter extends AxisChartPainter return null; } - final Size chartViewSize = getChartUsableDrawSize(viewSize); + final chartViewSize = getChartUsableDrawSize(viewSize); /// Find the nearest spot (on X axis) - for (int i = 0; i < barData.spots.length; i++) { + for (var i = 0; i < barData.spots.length; i++) { final spot = barData.spots[i]; if (spot.isNotNull()) { if ((touchedPoint.dx - getPixelX(spot.x, chartViewSize)).abs() <= diff --git a/lib/src/chart/pie_chart/pie_chart.dart b/lib/src/chart/pie_chart/pie_chart.dart index d92812c0d..7134ade44 100644 --- a/lib/src/chart/pie_chart/pie_chart.dart +++ b/lib/src/chart/pie_chart/pie_chart.dart @@ -57,12 +57,12 @@ class _PieChartState extends AnimatedWidgetBaseState { @override Widget build(BuildContext context) { - final PieChartData showingData = _getData(); - final PieTouchData touchData = showingData.pieTouchData; + final showingData = _getData(); + final touchData = showingData.pieTouchData; return GestureDetector( onLongPressStart: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -73,7 +73,7 @@ class _PieChartState extends AnimatedWidgetBaseState { } }, onLongPressEnd: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -85,7 +85,7 @@ class _PieChartState extends AnimatedWidgetBaseState { } }, onLongPressMoveUpdate: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -97,7 +97,7 @@ class _PieChartState extends AnimatedWidgetBaseState { } }, onPanCancel: () { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -109,7 +109,7 @@ class _PieChartState extends AnimatedWidgetBaseState { } }, onPanEnd: (DragEndDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -121,7 +121,7 @@ class _PieChartState extends AnimatedWidgetBaseState { } }, onPanDown: (DragDownDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -133,7 +133,7 @@ class _PieChartState extends AnimatedWidgetBaseState { } }, onPanUpdate: (DragUpdateDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } @@ -180,7 +180,7 @@ class _PieChartState extends AnimatedWidgetBaseState { children: List.generate( offsetsMap.length, (index) { - final int _key = offsetsMap.keys.elementAt(index); + final _key = offsetsMap.keys.elementAt(index); if (offsetsMap.length != _getData().sections.length) { return LayoutId( @@ -189,7 +189,7 @@ class _PieChartState extends AnimatedWidgetBaseState { ); } - final Widget _badgeWidget = _getData().sections[_key].badgeWidget; + final _badgeWidget = _getData().sections[_key].badgeWidget; if (_badgeWidget == null) { return LayoutId( @@ -251,10 +251,10 @@ class BadgeWidgetsDelegate extends MultiChildLayoutDelegate { @override void performLayout(Size size) { - for (int index = 0; index < badgeWidgetsCount; index++) { - final int _key = badgeWidgetsOffsets.keys.elementAt(index); + for (var index = 0; index < badgeWidgetsCount; index++) { + final _key = badgeWidgetsOffsets.keys.elementAt(index); - final Size _size = layoutChild( + final _size = layoutChild( _key, BoxConstraints( maxWidth: size.width, diff --git a/lib/src/chart/pie_chart/pie_chart_painter.dart b/lib/src/chart/pie_chart/pie_chart_painter.dart index 3fa48e2d2..5ed18c618 100644 --- a/lib/src/chart/pie_chart/pie_chart_painter.dart +++ b/lib/src/chart/pie_chart/pie_chart_painter.dart @@ -60,7 +60,7 @@ class PieChartPainter extends BaseChartPainter final canvasWrapper = CanvasWrapper(canvas, size); - final List sectionsAngle = _calculateSectionsAngle(data.sections, data.sumValue); + final sectionsAngle = _calculateSectionsAngle(data.sections, data.sumValue); _drawCenterSpace(canvasWrapper); _drawSections(canvasWrapper, sectionsAngle); @@ -75,8 +75,8 @@ class PieChartPainter extends BaseChartPainter void _drawCenterSpace(CanvasWrapper canvasWrapper) { final viewSize = canvasWrapper.size; - final double centerX = viewSize.width / 2; - final double centerY = viewSize.height / 2; + final centerX = viewSize.width / 2; + final centerY = viewSize.height / 2; canvasWrapper.drawCircle(Offset(centerX, centerY), data.centerSpaceRadius, _centerSpacePaint); } @@ -90,11 +90,11 @@ class PieChartPainter extends BaseChartPainter canvasWrapper.saveLayer(Rect.fromLTWH(0, 0, viewSize.width, viewSize.height), Paint()); } - final Offset center = Offset(viewSize.width / 2, viewSize.height / 2); + final center = Offset(viewSize.width / 2, viewSize.height / 2); - double tempAngle = data.startDegreeOffset; + var tempAngle = data.startDegreeOffset; - for (int i = 0; i < data.sections.length; i++) { + for (var i = 0; i < data.sections.length; i++) { final section = data.sections[i]; final sectionDegree = sectionsAngle[i]; @@ -106,8 +106,8 @@ class PieChartPainter extends BaseChartPainter _sectionPaint.color = section.color; _sectionPaint.strokeWidth = section.radius; - final double startAngle = tempAngle; - final double sweepAngle = sectionDegree; + final startAngle = tempAngle; + final sweepAngle = sectionDegree; canvasWrapper.drawArc( rect, radians(startAngle), @@ -128,20 +128,20 @@ class PieChartPainter extends BaseChartPainter /// then here we clear a line with given [PieChartData.width] void _removeSectionsSpace(CanvasWrapper canvasWrapper) { final viewSize = canvasWrapper.size; - const double extraLineSize = 1; - final Offset center = Offset(viewSize.width / 2, viewSize.height / 2); + const extraLineSize = 1; + final center = Offset(viewSize.width / 2, viewSize.height / 2); - double tempAngle = data.startDegreeOffset; + var tempAngle = data.startDegreeOffset; data.sections.asMap().forEach((index, section) { - final int previousIndex = index == 0 ? data.sections.length - 1 : index - 1; + final previousIndex = index == 0 ? data.sections.length - 1 : index - 1; final previousSection = data.sections[previousIndex]; - final double maxSectionRadius = math.max(section.radius, previousSection.radius); + final maxSectionRadius = math.max(section.radius, previousSection.radius); - final double startAngle = tempAngle; - final double sweepAngle = 360 * (section.value / data.sumValue); + final startAngle = tempAngle; + final sweepAngle = 360 * (section.value / data.sumValue); - final Offset sectionsStartFrom = center + + final sectionsStartFrom = center + Offset( math.cos(radians(startAngle)) * (_calculateCenterRadius(viewSize, data.centerSpaceRadius) - extraLineSize), @@ -149,7 +149,7 @@ class PieChartPainter extends BaseChartPainter (_calculateCenterRadius(viewSize, data.centerSpaceRadius) - extraLineSize), ); - final Offset sectionsStartTo = center + + final sectionsStartTo = center + Offset( math.cos(radians(startAngle)) * (_calculateCenterRadius(viewSize, data.centerSpaceRadius) + @@ -173,15 +173,15 @@ class PieChartPainter extends BaseChartPainter /// - badge widget positions void _drawTexts(CanvasWrapper canvasWrapper) { final viewSize = canvasWrapper.size; - final Offset center = Offset(viewSize.width / 2, viewSize.height / 2); + final center = Offset(viewSize.width / 2, viewSize.height / 2); - double tempAngle = data.startDegreeOffset; + var tempAngle = data.startDegreeOffset; - for (int i = 0; i < data.sections.length; i++) { - final PieChartSectionData section = data.sections[i]; - final double startAngle = tempAngle; - final double sweepAngle = 360 * (section.value / data.sumValue); - final double sectionCenterAngle = startAngle + (sweepAngle / 2); + for (var i = 0; i < data.sections.length; i++) { + final section = data.sections[i]; + final startAngle = tempAngle; + final sweepAngle = 360 * (section.value / data.sumValue); + final sectionCenterAngle = startAngle + (sweepAngle / 2); Offset sectionCenter(double percentageOffset) => center + @@ -194,14 +194,14 @@ class PieChartPainter extends BaseChartPainter (section.radius * percentageOffset)), ); - final Offset sectionCenterOffsetTitle = sectionCenter(section.titlePositionPercentageOffset); + final sectionCenterOffsetTitle = sectionCenter(section.titlePositionPercentageOffset); if (section.showTitle) { - final TextSpan span = TextSpan( + final span = TextSpan( style: section.titleStyle, text: section.title, ); - final TextPainter tp = TextPainter( + final tp = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -220,8 +220,8 @@ class PieChartPainter extends BaseChartPainter return givenCenterRadius; } - double maxRadius = 0; - for (int i = 0; i < data.sections.length; i++) { + var maxRadius = 0.0; + for (var i = 0; i < data.sections.length; i++) { final section = data.sections[i]; if (section.radius > maxRadius) { maxRadius = section.radius; @@ -240,7 +240,7 @@ class PieChartPainter extends BaseChartPainter /// then makes a [PieTouchResponse] from the elements that has been touched. @override PieTouchResponse handleTouch(FlTouchInput touchInput, Size size) { - final List sectionsAngle = _calculateSectionsAngle(data.sections, data.sumValue); + final sectionsAngle = _calculateSectionsAngle(data.sections, data.sumValue); return _getTouchedDetails(size, touchInput, sectionsAngle); } @@ -259,7 +259,7 @@ class PieChartPainter extends BaseChartPainter final touchY = touchedPoint2.dy; final touchR = math.sqrt(math.pow(touchX, 2) + math.pow(touchY, 2)); - double touchAngle = degrees(math.atan2(touchY, touchX)); + var touchAngle = degrees(math.atan2(touchY, touchX)); touchAngle = touchAngle < 0 ? (180 - touchAngle.abs()) + 180 : touchAngle; PieChartSectionData foundSectionData; @@ -267,10 +267,10 @@ class PieChartPainter extends BaseChartPainter /// Find the nearest section base on the touch spot final relativeTouchAngle = (touchAngle - data.startDegreeOffset) % 360; - double tempAngle = 0.0; - for (int i = 0; i < data.sections.length; i++) { + var tempAngle = 0.0; + for (var i = 0; i < data.sections.length; i++) { final section = data.sections[i]; - double sectionAngle = sectionsAngle[i]; + var sectionAngle = sectionsAngle[i]; tempAngle %= 360; if (data.sections.length == 1) { @@ -306,16 +306,16 @@ class PieChartPainter extends BaseChartPainter /// Exposes offset for laying out the badge widgets upon the chart. @override Map getBadgeOffsets(Size viewSize) { - final Offset center = Offset(viewSize.width / 2, viewSize.height / 2); - final Map badgeWidgetsOffsets = {}; + final center = Offset(viewSize.width / 2, viewSize.height / 2); + final badgeWidgetsOffsets = {}; - double tempAngle = data.startDegreeOffset; + var tempAngle = data.startDegreeOffset; - for (int i = 0; i < data.sections.length; i++) { - final PieChartSectionData section = data.sections[i]; - final double startAngle = tempAngle; - final double sweepAngle = 360 * (section.value / data.sumValue); - final double sectionCenterAngle = startAngle + (sweepAngle / 2); + for (var i = 0; i < data.sections.length; i++) { + final section = data.sections[i]; + final startAngle = tempAngle; + final sweepAngle = 360 * (section.value / data.sumValue); + final sectionCenterAngle = startAngle + (sweepAngle / 2); Offset sectionCenter(double percentageOffset) => center + @@ -328,8 +328,7 @@ class PieChartPainter extends BaseChartPainter (section.radius * percentageOffset)), ); - final Offset sectionCenterOffsetBadgeWidget = - sectionCenter(section.badgePositionPercentageOffset); + final sectionCenterOffsetBadgeWidget = sectionCenter(section.badgePositionPercentageOffset); if (section.badgeWidget != null) { badgeWidgetsOffsets[i] = sectionCenterOffsetBadgeWidget; diff --git a/lib/src/chart/scatter_chart/scatter_chart.dart b/lib/src/chart/scatter_chart/scatter_chart.dart index d30914abd..6a4c08b98 100644 --- a/lib/src/chart/scatter_chart/scatter_chart.dart +++ b/lib/src/chart/scatter_chart/scatter_chart.dart @@ -37,89 +37,86 @@ class _ScatterChartState extends AnimatedWidgetBaseState { @override Widget build(BuildContext context) { - final ScatterChartData showingData = _getData(); - final ScatterTouchData touchData = showingData.scatterTouchData; + final showingData = _getData(); + final touchData = showingData.scatterTouchData; return GestureDetector( onLongPressStart: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } - final ScatterTouchResponse response = - _touchHandler?.handleTouch(FlLongPressStart(d.localPosition), chartSize); + final response = _touchHandler?.handleTouch(FlLongPressStart(d.localPosition), chartSize); if (_canHandleTouch(response, touchData)) { touchData.touchCallback(response); } }, onLongPressEnd: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } - final ScatterTouchResponse response = - _touchHandler?.handleTouch(FlLongPressEnd(d.localPosition), chartSize); + final response = _touchHandler?.handleTouch(FlLongPressEnd(d.localPosition), chartSize); if (_canHandleTouch(response, touchData)) { touchData.touchCallback(response); } }, onLongPressMoveUpdate: (d) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } - final ScatterTouchResponse response = + final response = _touchHandler?.handleTouch(FlLongPressMoveUpdate(d.localPosition), chartSize); if (_canHandleTouch(response, touchData)) { touchData.touchCallback(response); } }, onPanCancel: () { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } - final ScatterTouchResponse response = _touchHandler?.handleTouch( + final response = _touchHandler?.handleTouch( FlPanEnd(Offset.zero, const Velocity(pixelsPerSecond: Offset.zero)), chartSize); if (_canHandleTouch(response, touchData)) { touchData.touchCallback(response); } }, onPanEnd: (DragEndDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } - final ScatterTouchResponse response = + final response = _touchHandler?.handleTouch(FlPanEnd(Offset.zero, details.velocity), chartSize); if (_canHandleTouch(response, touchData)) { touchData.touchCallback(response); } }, onPanDown: (DragDownDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } - final ScatterTouchResponse response = - _touchHandler?.handleTouch(FlPanStart(details.localPosition), chartSize); + final response = _touchHandler?.handleTouch(FlPanStart(details.localPosition), chartSize); if (_canHandleTouch(response, touchData)) { touchData.touchCallback(response); } }, onPanUpdate: (DragUpdateDetails details) { - final Size chartSize = _getChartSize(); + final chartSize = _getChartSize(); if (chartSize == null) { return; } - final ScatterTouchResponse response = + final response = _touchHandler?.handleTouch(FlPanMoveUpdate(details.localPosition), chartSize); if (_canHandleTouch(response, touchData)) { touchData.touchCallback(response); diff --git a/lib/src/chart/scatter_chart/scatter_chart_data.dart b/lib/src/chart/scatter_chart/scatter_chart_data.dart index 2c805aebd..55f0f4c10 100644 --- a/lib/src/chart/scatter_chart/scatter_chart_data.dart +++ b/lib/src/chart/scatter_chart/scatter_chart_data.dart @@ -94,8 +94,8 @@ class ScatterChartData extends AxisChartData with EquatableMixin { maxY = scatterSpots[0].y; } - for (int j = 0; j < scatterSpots.length; j++) { - final ScatterSpot spot = scatterSpots[j]; + for (var j = 0; j < scatterSpots.length; j++) { + final spot = scatterSpots[j]; if (canModifyMaxX && spot.x > maxX) { maxX = spot.x; } @@ -443,7 +443,7 @@ ScatterTooltipItem defaultScatterTooltipItem(ScatterSpot touchedSpot) { if (touchedSpot == null) { return null; } - final TextStyle textStyle = TextStyle( + final textStyle = TextStyle( color: touchedSpot.color, fontWeight: FontWeight.bold, fontSize: 14, diff --git a/lib/src/chart/scatter_chart/scatter_chart_painter.dart b/lib/src/chart/scatter_chart/scatter_chart_painter.dart index ef85d4ab9..354efd5fb 100644 --- a/lib/src/chart/scatter_chart/scatter_chart_painter.dart +++ b/lib/src/chart/scatter_chart/scatter_chart_painter.dart @@ -50,12 +50,12 @@ class ScatterChartPainter extends AxisChartPainter _drawTitles(canvasWrapper); _drawSpots(canvasWrapper); - for (int i = 0; i < targetData.scatterSpots.length; i++) { + for (var i = 0; i < targetData.scatterSpots.length; i++) { if (!targetData.showingTooltipIndicators.contains(i)) { continue; } - final ScatterSpot scatterSpot = targetData.scatterSpots[i]; + final scatterSpot = targetData.scatterSpots[i]; _drawTouchTooltip(canvasWrapper, targetData.scatterTouchData.touchTooltipData, scatterSpot); } } @@ -71,17 +71,17 @@ class ScatterChartPainter extends AxisChartPainter final leftInterval = leftTitles.interval ?? getEfficientInterval(viewSize.height, data.verticalDiff); if (leftTitles.showTitles) { - double verticalSeek = data.minY; + var verticalSeek = data.minY; while (verticalSeek <= data.maxY) { if (leftTitles.checkToShowTitle( data.minY, data.maxY, leftTitles, leftInterval, verticalSeek)) { - double x = 0 + getLeftOffsetDrawSize(); - double y = getPixelY(verticalSeek, viewSize); + var x = 0 + getLeftOffsetDrawSize(); + var y = getPixelY(verticalSeek, viewSize); - final String text = leftTitles.getTitles(verticalSeek); + final text = leftTitles.getTitles(verticalSeek); - final TextSpan span = TextSpan(style: leftTitles.getTextStyles(verticalSeek), text: text); - final TextPainter tp = TextPainter( + final span = TextSpan(style: leftTitles.getTextStyles(verticalSeek), text: text); + final tp = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -110,18 +110,17 @@ class ScatterChartPainter extends AxisChartPainter final topInterval = topTitles.interval ?? getEfficientInterval(viewSize.width, data.horizontalDiff); if (topTitles.showTitles) { - double horizontalSeek = data.minX; + var horizontalSeek = data.minX; while (horizontalSeek <= data.maxX) { if (topTitles.checkToShowTitle( data.minX, data.maxX, topTitles, topInterval, horizontalSeek)) { - double x = getPixelX(horizontalSeek, viewSize); - double y = getTopOffsetDrawSize(); + var x = getPixelX(horizontalSeek, viewSize); + var y = getTopOffsetDrawSize(); - final String text = topTitles.getTitles(horizontalSeek); + final text = topTitles.getTitles(horizontalSeek); - final TextSpan span = - TextSpan(style: topTitles.getTextStyles(horizontalSeek), text: text); - final TextPainter tp = TextPainter( + final span = TextSpan(style: topTitles.getTextStyles(horizontalSeek), text: text); + final tp = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -151,18 +150,17 @@ class ScatterChartPainter extends AxisChartPainter final rightInterval = rightTitles.interval ?? getEfficientInterval(viewSize.height, data.verticalDiff); if (rightTitles.showTitles) { - double verticalSeek = data.minY; + var verticalSeek = data.minY; while (verticalSeek <= data.maxY) { if (rightTitles.checkToShowTitle( data.minY, data.maxY, rightTitles, rightInterval, verticalSeek)) { - double x = viewSize.width + getLeftOffsetDrawSize(); - double y = getPixelY(verticalSeek, viewSize); + var x = viewSize.width + getLeftOffsetDrawSize(); + var y = getPixelY(verticalSeek, viewSize); - final String text = rightTitles.getTitles(verticalSeek); + final text = rightTitles.getTitles(verticalSeek); - final TextSpan span = - TextSpan(style: rightTitles.getTextStyles(verticalSeek), text: text); - final TextPainter tp = TextPainter( + final span = TextSpan(style: rightTitles.getTextStyles(verticalSeek), text: text); + final tp = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -192,18 +190,17 @@ class ScatterChartPainter extends AxisChartPainter final bottomInterval = bottomTitles.interval ?? getEfficientInterval(viewSize.width, data.horizontalDiff); if (bottomTitles.showTitles) { - double horizontalSeek = data.minX; + var horizontalSeek = data.minX; while (horizontalSeek <= data.maxX) { if (bottomTitles.checkToShowTitle( data.minX, data.maxX, bottomTitles, bottomInterval, horizontalSeek)) { - double x = getPixelX(horizontalSeek, viewSize); - double y = viewSize.height + getTopOffsetDrawSize(); + var x = getPixelX(horizontalSeek, viewSize); + var y = viewSize.height + getTopOffsetDrawSize(); - final String text = bottomTitles.getTitles(horizontalSeek); + final text = bottomTitles.getTitles(horizontalSeek); - final TextSpan span = - TextSpan(style: bottomTitles.getTextStyles(horizontalSeek), text: text); - final TextPainter tp = TextPainter( + final span = TextSpan(style: bottomTitles.getTextStyles(horizontalSeek), text: text); + final tp = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -235,12 +232,12 @@ class ScatterChartPainter extends AxisChartPainter } final viewSize = canvasWrapper.size; final chartUsableSize = getChartUsableDrawSize(viewSize); - for (final ScatterSpot scatterSpot in data.scatterSpots) { + for (final scatterSpot in data.scatterSpots) { if (!scatterSpot.show) { continue; } - final double pixelX = getPixelX(scatterSpot.x, chartUsableSize); - final double pixelY = getPixelY(scatterSpot.y, chartUsableSize); + final pixelX = getPixelX(scatterSpot.x, chartUsableSize); + final pixelY = getPixelY(scatterSpot.y, chartUsableSize); _spotsPaint.color = scatterSpot.color; @@ -257,14 +254,14 @@ class ScatterChartPainter extends AxisChartPainter final viewSize = canvasWrapper.size; final chartUsableSize = getChartUsableDrawSize(viewSize); - final ScatterTooltipItem tooltipItem = tooltipData.getTooltipItems(showOnSpot); + final tooltipItem = tooltipData.getTooltipItems(showOnSpot); if (tooltipItem == null) { return; } - final TextSpan span = TextSpan(style: tooltipItem.textStyle, text: tooltipItem.text); - final TextPainter drawingTextPainter = TextPainter( + final span = TextSpan(style: tooltipItem.textStyle, text: tooltipItem.text); + final drawingTextPainter = TextPainter( text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr, @@ -277,16 +274,16 @@ class ScatterChartPainter extends AxisChartPainter /// if we have multiple bar lines, /// there are more than one FlCandidate on touch area, /// we should get the most top FlSpot Offset to draw the tooltip on top of it - final Offset mostTopOffset = Offset( + final mostTopOffset = Offset( getPixelX(showOnSpot.x, chartUsableSize), getPixelY(showOnSpot.y, chartUsableSize), ); - final double tooltipWidth = width + tooltipData.tooltipPadding.horizontal; - final double tooltipHeight = height + tooltipData.tooltipPadding.vertical; + final tooltipWidth = width + tooltipData.tooltipPadding.horizontal; + final tooltipHeight = height + tooltipData.tooltipPadding.vertical; /// draw the background rect with rounded radius - Rect rect = Rect.fromLTWH(mostTopOffset.dx - (tooltipWidth / 2), + var rect = Rect.fromLTWH(mostTopOffset.dx - (tooltipWidth / 2), mostTopOffset.dy - tooltipHeight - tooltipItem.bottomMargin, tooltipWidth, tooltipHeight); if (tooltipData.fitInsideHorizontally) { @@ -333,8 +330,8 @@ class ScatterChartPainter extends AxisChartPainter } } - final Radius radius = Radius.circular(tooltipData.tooltipRoundedRadius); - final RRect roundedRect = RRect.fromRectAndCorners(rect, + final radius = Radius.circular(tooltipData.tooltipRoundedRadius); + final roundedRect = RRect.fromRectAndCorners(rect, topLeft: radius, topRight: radius, bottomLeft: radius, bottomRight: radius); _bgTouchTooltipPaint.color = tooltipData.tooltipBgColor; canvasWrapper.drawRRect(roundedRect, _bgTouchTooltipPaint); @@ -354,7 +351,7 @@ class ScatterChartPainter extends AxisChartPainter /// and the whole space is [getExtraNeededHorizontalSpace] @override double getExtraNeededHorizontalSpace() { - double sum = super.getExtraNeededHorizontalSpace(); + var sum = super.getExtraNeededHorizontalSpace(); if (data.titlesData.show) { final leftSide = data.titlesData.leftTitles; if (leftSide.showTitles) { @@ -376,7 +373,7 @@ class ScatterChartPainter extends AxisChartPainter /// and the whole space is [getExtraNeededVerticalSpace] @override double getExtraNeededVerticalSpace() { - double sum = super.getExtraNeededVerticalSpace(); + var sum = super.getExtraNeededVerticalSpace(); if (data.titlesData.show) { final topSide = data.titlesData.topTitles; if (topSide.showTitles) { @@ -427,9 +424,9 @@ class ScatterChartPainter extends AxisChartPainter /// then makes a [ScatterTouchResponse] from the elements that has been touched. @override ScatterTouchResponse handleTouch(FlTouchInput touchInput, Size size) { - final Size chartViewSize = getChartUsableDrawSize(size); + final chartViewSize = getChartUsableDrawSize(size); - for (int i = 0; i < data.scatterSpots.length; i++) { + for (var i = 0; i < data.scatterSpots.length; i++) { final spot = data.scatterSpots[i]; final spotPixelX = getPixelX(spot.x, chartViewSize); diff --git a/lib/src/extensions/canvas_extension.dart b/lib/src/extensions/canvas_extension.dart index 441f9a6fd..b09697f4e 100644 --- a/lib/src/extensions/canvas_extension.dart +++ b/lib/src/extensions/canvas_extension.dart @@ -7,7 +7,7 @@ import 'package:fl_chart/src/utils/canvas_wrapper.dart'; extension DashedLine on CanvasWrapper { /// Draws a dashed line from passed in offsets void drawDashedLine(Offset from, Offset to, Paint painter, List dashArray) { - Path path = Path(); + var path = Path(); path.moveTo(from.dx, from.dy); path.lineTo(to.dx, to.dy); path = path.toDashedPath(dashArray); diff --git a/lib/src/utils/utils.dart b/lib/src/utils/utils.dart index 78930423f..8c998122a 100644 --- a/lib/src/utils/utils.dart +++ b/lib/src/utils/utils.dart @@ -108,13 +108,13 @@ Color lerpGradient(List colors, List stops, double t) { /// 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 5000, 10000,... double getEfficientInterval(double axisViewSize, double diffInYAxis, {double pixelPerInterval = 10}) { - final int allowedCount = axisViewSize ~/ pixelPerInterval; - final double accurateInterval = diffInYAxis / allowedCount; + final allowedCount = axisViewSize ~/ pixelPerInterval; + final accurateInterval = diffInYAxis / allowedCount; return _roundInterval(accurateInterval).toDouble(); } int _roundInterval(double input) { - int count = 0; + var count = 0; if (input >= 10) { count++; @@ -125,7 +125,7 @@ int _roundInterval(double input) { count++; } - final double scaled = input >= 10 ? input.round() / 10 : input; + final scaled = input >= 10 ? input.round() / 10 : input; if (scaled >= 2.6) { return 5 * pow(10, count); diff --git a/pubspec.yaml b/pubspec.yaml index 691c5dbfa..86856b7e6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,10 @@ dependencies: path_drawing: ^0.4.1 equatable: ^1.1.1 + pedantic: ^1.9.0 dev_dependencies: flutter_test: sdk: flutter + +