Skip to content

Commit 4a32161

Browse files
committed
Simplify the codebase by using the single line functions style or new switch statement
1 parent d1e7e66 commit 4a32161

18 files changed

+751
-887
lines changed

lib/src/chart/bar_chart/bar_chart_data.dart

Lines changed: 106 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,22 @@ class BarChartData extends AxisChartData with EquatableMixin {
9494
double? baselineY,
9595
Color? backgroundColor,
9696
ExtraLinesData? extraLinesData,
97-
}) {
98-
return BarChartData(
99-
barGroups: barGroups ?? this.barGroups,
100-
groupsSpace: groupsSpace ?? this.groupsSpace,
101-
alignment: alignment ?? this.alignment,
102-
titlesData: titlesData ?? this.titlesData,
103-
rangeAnnotations: rangeAnnotations ?? this.rangeAnnotations,
104-
barTouchData: barTouchData ?? this.barTouchData,
105-
gridData: gridData ?? this.gridData,
106-
borderData: borderData ?? this.borderData,
107-
maxY: maxY ?? this.maxY,
108-
minY: minY ?? this.minY,
109-
baselineY: baselineY ?? this.baselineY,
110-
backgroundColor: backgroundColor ?? this.backgroundColor,
111-
extraLinesData: extraLinesData ?? this.extraLinesData,
112-
);
113-
}
97+
}) =>
98+
BarChartData(
99+
barGroups: barGroups ?? this.barGroups,
100+
groupsSpace: groupsSpace ?? this.groupsSpace,
101+
alignment: alignment ?? this.alignment,
102+
titlesData: titlesData ?? this.titlesData,
103+
rangeAnnotations: rangeAnnotations ?? this.rangeAnnotations,
104+
barTouchData: barTouchData ?? this.barTouchData,
105+
gridData: gridData ?? this.gridData,
106+
borderData: borderData ?? this.borderData,
107+
maxY: maxY ?? this.maxY,
108+
minY: minY ?? this.minY,
109+
baselineY: baselineY ?? this.baselineY,
110+
backgroundColor: backgroundColor ?? this.backgroundColor,
111+
extraLinesData: extraLinesData ?? this.extraLinesData,
112+
);
114113

115114
/// Lerps a [BaseChartData] based on [t] value, check [Tween.lerp].
116115
@override
@@ -243,35 +242,32 @@ class BarChartGroupData with EquatableMixin {
243242
List<BarChartRodData>? barRods,
244243
double? barsSpace,
245244
List<int>? showingTooltipIndicators,
246-
}) {
247-
return BarChartGroupData(
248-
x: x ?? this.x,
249-
groupVertically: groupVertically ?? this.groupVertically,
250-
barRods: barRods ?? this.barRods,
251-
barsSpace: barsSpace ?? this.barsSpace,
252-
showingTooltipIndicators:
253-
showingTooltipIndicators ?? this.showingTooltipIndicators,
254-
);
255-
}
245+
}) => BarChartGroupData(
246+
x: x ?? this.x,
247+
groupVertically: groupVertically ?? this.groupVertically,
248+
barRods: barRods ?? this.barRods,
249+
barsSpace: barsSpace ?? this.barsSpace,
250+
showingTooltipIndicators:
251+
showingTooltipIndicators ?? this.showingTooltipIndicators,
252+
);
256253

257254
/// Lerps a [BarChartGroupData] based on [t] value, check [Tween.lerp].
258255
static BarChartGroupData lerp(
259256
BarChartGroupData a,
260257
BarChartGroupData b,
261258
double t,
262-
) {
263-
return BarChartGroupData(
264-
x: (a.x + (b.x - a.x) * t).round(),
265-
groupVertically: b.groupVertically,
266-
barRods: lerpBarChartRodDataList(a.barRods, b.barRods, t),
267-
barsSpace: lerpDouble(a.barsSpace, b.barsSpace, t),
268-
showingTooltipIndicators: lerpIntList(
269-
a.showingTooltipIndicators,
270-
b.showingTooltipIndicators,
271-
t,
272-
),
273-
);
274-
}
259+
) =>
260+
BarChartGroupData(
261+
x: (a.x + (b.x - a.x) * t).round(),
262+
groupVertically: b.groupVertically,
263+
barRods: lerpBarChartRodDataList(a.barRods, b.barRods, t),
264+
barsSpace: lerpDouble(a.barsSpace, b.barsSpace, t),
265+
showingTooltipIndicators: lerpIntList(
266+
a.showingTooltipIndicators,
267+
b.showingTooltipIndicators,
268+
t,
269+
),
270+
);
275271

276272
/// Used for equality check, see [EquatableMixin].
277273
@override
@@ -386,42 +382,40 @@ class BarChartRodData with EquatableMixin {
386382
BorderSide? borderSide,
387383
BackgroundBarChartRodData? backDrawRodData,
388384
List<BarChartRodStackItem>? rodStackItems,
389-
}) {
390-
return BarChartRodData(
391-
fromY: fromY ?? this.fromY,
392-
toY: toY ?? this.toY,
393-
color: color ?? this.color,
394-
gradient: gradient ?? this.gradient,
395-
width: width ?? this.width,
396-
borderRadius: borderRadius ?? this.borderRadius,
397-
borderDashArray: borderDashArray,
398-
borderSide: borderSide ?? this.borderSide,
399-
backDrawRodData: backDrawRodData ?? this.backDrawRodData,
400-
rodStackItems: rodStackItems ?? this.rodStackItems,
401-
);
402-
}
385+
}) =>
386+
BarChartRodData(
387+
fromY: fromY ?? this.fromY,
388+
toY: toY ?? this.toY,
389+
color: color ?? this.color,
390+
gradient: gradient ?? this.gradient,
391+
width: width ?? this.width,
392+
borderRadius: borderRadius ?? this.borderRadius,
393+
borderDashArray: borderDashArray,
394+
borderSide: borderSide ?? this.borderSide,
395+
backDrawRodData: backDrawRodData ?? this.backDrawRodData,
396+
rodStackItems: rodStackItems ?? this.rodStackItems,
397+
);
403398

404399
/// Lerps a [BarChartRodData] based on [t] value, check [Tween.lerp].
405-
static BarChartRodData lerp(BarChartRodData a, BarChartRodData b, double t) {
406-
return BarChartRodData(
407-
// ignore: invalid_use_of_protected_member
408-
gradient: a.gradient?.lerpTo(b.gradient, t),
409-
color: Color.lerp(a.color, b.color, t),
410-
width: lerpDouble(a.width, b.width, t),
411-
borderRadius: BorderRadius.lerp(a.borderRadius, b.borderRadius, t),
412-
borderDashArray: lerpIntList(a.borderDashArray, b.borderDashArray, t),
413-
borderSide: BorderSide.lerp(a.borderSide, b.borderSide, t),
414-
fromY: lerpDouble(a.fromY, b.fromY, t),
415-
toY: lerpDouble(a.toY, b.toY, t)!,
416-
backDrawRodData: BackgroundBarChartRodData.lerp(
417-
a.backDrawRodData,
418-
b.backDrawRodData,
419-
t,
420-
),
421-
rodStackItems:
422-
lerpBarChartRodStackList(a.rodStackItems, b.rodStackItems, t),
423-
);
424-
}
400+
static BarChartRodData lerp(BarChartRodData a, BarChartRodData b, double t) =>
401+
BarChartRodData(
402+
// ignore: invalid_use_of_protected_member
403+
gradient: a.gradient?.lerpTo(b.gradient, t),
404+
color: Color.lerp(a.color, b.color, t),
405+
width: lerpDouble(a.width, b.width, t),
406+
borderRadius: BorderRadius.lerp(a.borderRadius, b.borderRadius, t),
407+
borderDashArray: lerpIntList(a.borderDashArray, b.borderDashArray, t),
408+
borderSide: BorderSide.lerp(a.borderSide, b.borderSide, t),
409+
fromY: lerpDouble(a.fromY, b.fromY, t),
410+
toY: lerpDouble(a.toY, b.toY, t)!,
411+
backDrawRodData: BackgroundBarChartRodData.lerp(
412+
a.backDrawRodData,
413+
b.backDrawRodData,
414+
t,
415+
),
416+
rodStackItems:
417+
lerpBarChartRodStackList(a.rodStackItems, b.rodStackItems, t),
418+
);
425419

426420
/// Used for equality check, see [EquatableMixin].
427421
@override
@@ -483,28 +477,26 @@ class BarChartRodStackItem with EquatableMixin {
483477
double? toY,
484478
Color? color,
485479
BorderSide? borderSide,
486-
}) {
487-
return BarChartRodStackItem(
488-
fromY ?? this.fromY,
489-
toY ?? this.toY,
490-
color ?? this.color,
491-
borderSide ?? this.borderSide,
492-
);
493-
}
480+
}) =>
481+
BarChartRodStackItem(
482+
fromY ?? this.fromY,
483+
toY ?? this.toY,
484+
color ?? this.color,
485+
borderSide ?? this.borderSide,
486+
);
494487

495488
/// Lerps a [BarChartRodStackItem] based on [t] value, check [Tween.lerp].
496489
static BarChartRodStackItem lerp(
497490
BarChartRodStackItem a,
498491
BarChartRodStackItem b,
499492
double t,
500-
) {
501-
return BarChartRodStackItem(
502-
lerpDouble(a.fromY, b.fromY, t)!,
503-
lerpDouble(a.toY, b.toY, t)!,
504-
Color.lerp(a.color, b.color, t)!,
505-
BorderSide.lerp(a.borderSide, b.borderSide, t),
506-
);
507-
}
493+
) =>
494+
BarChartRodStackItem(
495+
lerpDouble(a.fromY, b.fromY, t)!,
496+
lerpDouble(a.toY, b.toY, t)!,
497+
Color.lerp(a.color, b.color, t)!,
498+
BorderSide.lerp(a.borderSide, b.borderSide, t),
499+
);
508500

509501
/// Used for equality check, see [EquatableMixin].
510502
@override
@@ -557,16 +549,14 @@ class BackgroundBarChartRodData with EquatableMixin {
557549
BackgroundBarChartRodData a,
558550
BackgroundBarChartRodData b,
559551
double t,
560-
) {
561-
return BackgroundBarChartRodData(
562-
fromY: lerpDouble(a.fromY, b.fromY, t),
563-
toY: lerpDouble(a.toY, b.toY, t),
564-
color: Color.lerp(a.color, b.color, t),
565-
// ignore: invalid_use_of_protected_member
566-
gradient: a.gradient?.lerpTo(b.gradient, t),
567-
show: b.show,
568-
);
569-
}
552+
) => BackgroundBarChartRodData(
553+
fromY: lerpDouble(a.fromY, b.fromY, t),
554+
toY: lerpDouble(a.toY, b.toY, t),
555+
color: Color.lerp(a.color, b.color, t),
556+
// ignore: invalid_use_of_protected_member
557+
gradient: a.gradient?.lerpTo(b.gradient, t),
558+
show: b.show,
559+
);
570560

571561
/// Used for equality check, see [EquatableMixin].
572562
@override
@@ -645,19 +635,17 @@ class BarTouchData extends FlTouchData<BarTouchResponse> with EquatableMixin {
645635
EdgeInsets? touchExtraThreshold,
646636
bool? allowTouchBarBackDraw,
647637
bool? handleBuiltInTouches,
648-
}) {
649-
return BarTouchData(
650-
enabled: enabled ?? this.enabled,
651-
touchCallback: touchCallback ?? this.touchCallback,
652-
mouseCursorResolver: mouseCursorResolver ?? this.mouseCursorResolver,
653-
longPressDuration: longPressDuration ?? this.longPressDuration,
654-
touchTooltipData: touchTooltipData ?? this.touchTooltipData,
655-
touchExtraThreshold: touchExtraThreshold ?? this.touchExtraThreshold,
656-
allowTouchBarBackDraw:
657-
allowTouchBarBackDraw ?? this.allowTouchBarBackDraw,
658-
handleBuiltInTouches: handleBuiltInTouches ?? this.handleBuiltInTouches,
659-
);
660-
}
638+
}) => BarTouchData(
639+
enabled: enabled ?? this.enabled,
640+
touchCallback: touchCallback ?? this.touchCallback,
641+
mouseCursorResolver: mouseCursorResolver ?? this.mouseCursorResolver,
642+
longPressDuration: longPressDuration ?? this.longPressDuration,
643+
touchTooltipData: touchTooltipData ?? this.touchTooltipData,
644+
touchExtraThreshold: touchExtraThreshold ?? this.touchExtraThreshold,
645+
allowTouchBarBackDraw:
646+
allowTouchBarBackDraw ?? this.allowTouchBarBackDraw,
647+
handleBuiltInTouches: handleBuiltInTouches ?? this.handleBuiltInTouches,
648+
);
661649

662650
/// Used for equality check, see [EquatableMixin].
663651
@override
@@ -864,9 +852,8 @@ typedef GetBarTooltipColor = Color Function(
864852
);
865853

866854
/// Default implementation for [BarTouchTooltipData.getTooltipColor].
867-
Color defaultBarTooltipColor(BarChartGroupData group) {
868-
return Colors.blueGrey.darken(15);
869-
}
855+
Color defaultBarTooltipColor(BarChartGroupData group) =>
856+
Colors.blueGrey.darken(15);
870857

871858
/// Holds information about touch response in the [BarChart].
872859
///
@@ -884,11 +871,9 @@ class BarTouchResponse extends BaseTouchResponse {
884871
/// and replaces provided values.
885872
BarTouchResponse copyWith({
886873
BarTouchedSpot? spot,
887-
}) {
888-
return BarTouchResponse(
889-
spot ?? this.spot,
890-
);
891-
}
874+
}) => BarTouchResponse(
875+
spot ?? this.spot,
876+
);
892877
}
893878

894879
/// It gives you information about the touched spot.

0 commit comments

Comments
 (0)