fix(treewide): migrate to sound null safety
Signed-off-by: Sphericalkat <me@kat.bio>
This commit is contained in:
12 files changed
+86
-86
No files matched your search
@@ -25,9 +25,9 @@ enum SegmentEdgeStyle {
|
||||
|
||||
class AnimatedCircularChart extends StatefulWidget {
|
||||
AnimatedCircularChart({
|
||||
Key key,
|
||||
@required this.size,
|
||||
@required this.initialChartData,
|
||||
Key? key,
|
||||
required this.size,
|
||||
required this.initialChartData,
|
||||
this.chartType = CircularChartType.Radial,
|
||||
this.duration = _kDuration,
|
||||
this.percentageValues = false,
|
||||
@@ -51,7 +51,7 @@ class AnimatedCircularChart extends StatefulWidget {
|
||||
/// will be grouped together as concentric circles.
|
||||
///
|
||||
/// If [chartType] is [CircularChartType.Pie] then length cannot be > 1.
|
||||
final List<CircularStackEntry> initialChartData;
|
||||
final List<CircularStackEntry>? initialChartData;
|
||||
|
||||
/// The type of chart to be rendered.
|
||||
/// Use [CircularChartType.Pie] for a circle divided into slices for each entry.
|
||||
@@ -76,7 +76,7 @@ class AnimatedCircularChart extends StatefulWidget {
|
||||
/// be automatically calculated to accommodate all the data.
|
||||
///
|
||||
/// Has no effect in [CircularChartType.Pie] charts.
|
||||
final double holeRadius;
|
||||
final double? holeRadius;
|
||||
|
||||
/// The chart gets drawn and animates clockwise from [startAngle], defaulting to the
|
||||
/// top/center point or -90.0. In terms of a clock face these would be:
|
||||
@@ -92,13 +92,13 @@ class AnimatedCircularChart extends StatefulWidget {
|
||||
/// in the center of the chart's hole.
|
||||
///
|
||||
/// See also [labelStyle] which is used to render the label.
|
||||
final String holeLabel;
|
||||
final String? holeLabel;
|
||||
|
||||
/// The style used when rendering the [holeLabel].
|
||||
///
|
||||
/// Defaults to the active [ThemeData]'s
|
||||
/// [ThemeData.textTheme.body2] text style.
|
||||
final TextStyle labelStyle;
|
||||
final TextStyle? labelStyle;
|
||||
|
||||
/// The type of segment edges to be drawn.
|
||||
///
|
||||
@@ -113,11 +113,11 @@ class AnimatedCircularChart extends StatefulWidget {
|
||||
/// ```dart
|
||||
/// AnimatedCircularChartState animatedCircularChart = AnimatedCircularChart.of(context);
|
||||
/// ```
|
||||
static AnimatedCircularChartState of(BuildContext context, {bool nullOk: false}) {
|
||||
static AnimatedCircularChartState? of(BuildContext context, {bool nullOk: false}) {
|
||||
assert(context != null);
|
||||
assert(nullOk != null);
|
||||
|
||||
final AnimatedCircularChartState result =
|
||||
final AnimatedCircularChartState? result =
|
||||
context.findAncestorStateOfType<AnimatedCircularChartState>();
|
||||
|
||||
if (nullOk || result != null) return result;
|
||||
@@ -151,10 +151,10 @@ class AnimatedCircularChart extends StatefulWidget {
|
||||
/// ```
|
||||
class AnimatedCircularChartState extends State<AnimatedCircularChart>
|
||||
with TickerProviderStateMixin {
|
||||
CircularChartTween _tween;
|
||||
AnimationController _animation;
|
||||
final Map<String, int> _stackRanks = <String, int>{};
|
||||
final Map<String, int> _entryRanks = <String, int>{};
|
||||
late CircularChartTween _tween;
|
||||
late AnimationController _animation;
|
||||
final Map<String?, int> _stackRanks = <String?, int>{};
|
||||
final Map<String?, int> _entryRanks = <String?, int>{};
|
||||
final TextPainter _labelPainter = TextPainter();
|
||||
|
||||
@override
|
||||
@@ -165,13 +165,13 @@ class AnimatedCircularChartState extends State<AnimatedCircularChart>
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_assignRanks(widget.initialChartData);
|
||||
_assignRanks(widget.initialChartData!);
|
||||
|
||||
_tween = CircularChartTween(
|
||||
CircularChart.empty(chartType: widget.chartType),
|
||||
CircularChart.fromData(
|
||||
size: widget.size,
|
||||
data: widget.initialChartData,
|
||||
data: widget.initialChartData!,
|
||||
chartType: widget.chartType,
|
||||
stackRanks: _stackRanks,
|
||||
entryRanks: _entryRanks,
|
||||
@@ -215,7 +215,7 @@ class AnimatedCircularChartState extends State<AnimatedCircularChart>
|
||||
|
||||
void _updateLabelPainter() {
|
||||
if (widget.holeLabel != null) {
|
||||
TextStyle _labelStyle = widget.labelStyle ?? Theme.of(context).textTheme.bodyText1;
|
||||
TextStyle? _labelStyle = widget.labelStyle ?? Theme.of(context).textTheme.bodyText1;
|
||||
_labelPainter
|
||||
..text = TextSpan(style: _labelStyle, text: widget.holeLabel)
|
||||
..textDirection = Directionality.of(context)
|
||||
|
||||
+14
-14
@@ -17,22 +17,22 @@ class CircularChart {
|
||||
|
||||
final List<CircularChartStack> stacks;
|
||||
final CircularChartType chartType;
|
||||
final SegmentEdgeStyle edgeStyle;
|
||||
final SegmentEdgeStyle? edgeStyle;
|
||||
|
||||
factory CircularChart.empty({@required CircularChartType chartType}) {
|
||||
factory CircularChart.empty({required CircularChartType chartType}) {
|
||||
return CircularChart(<CircularChartStack>[], chartType);
|
||||
}
|
||||
|
||||
factory CircularChart.fromData({
|
||||
@required Size size,
|
||||
@required List<CircularStackEntry> data,
|
||||
@required CircularChartType chartType,
|
||||
@required bool percentageValues,
|
||||
@required double startAngle,
|
||||
Map<String, int> stackRanks,
|
||||
Map<String, int> entryRanks,
|
||||
double holeRadius,
|
||||
SegmentEdgeStyle edgeStyle,
|
||||
required Size size,
|
||||
required List<CircularStackEntry> data,
|
||||
required CircularChartType chartType,
|
||||
required bool percentageValues,
|
||||
required double startAngle,
|
||||
Map<String?, int>? stackRanks,
|
||||
Map<String?, int>? entryRanks,
|
||||
double? holeRadius,
|
||||
SegmentEdgeStyle? edgeStyle,
|
||||
}) {
|
||||
final double _holeRadius = holeRadius ?? size.width / (2 + data.length);
|
||||
final double stackDistance = (size.width / 2 - _holeRadius) / (2 + data.length);
|
||||
@@ -42,7 +42,7 @@ class CircularChart {
|
||||
List<CircularChartStack> stacks = List<CircularChartStack>.generate(
|
||||
data.length,
|
||||
(i) => CircularChartStack.fromData(
|
||||
stackRanks[data[i].rankKey] ?? i,
|
||||
stackRanks![data[i].rankKey] ?? i,
|
||||
data[i].entries,
|
||||
entryRanks,
|
||||
percentageValues,
|
||||
@@ -66,7 +66,7 @@ class CircularChartTween extends Tween<CircularChart> {
|
||||
@override
|
||||
CircularChart lerp(double t) => CircularChart(
|
||||
_stacksTween.lerp(t),
|
||||
begin.chartType,
|
||||
edgeStyle: end.edgeStyle,
|
||||
begin!.chartType,
|
||||
edgeStyle: end!.edgeStyle,
|
||||
);
|
||||
}
|
||||
+3
-3
@@ -19,11 +19,11 @@ class CircularSegmentEntry {
|
||||
final double value;
|
||||
|
||||
/// The color drawn in the stack for this segment.
|
||||
final Color color;
|
||||
final Color? color;
|
||||
|
||||
/// An optional String key, used when animating charts to preserve semantics when
|
||||
/// transitioning between data points.
|
||||
final String rankKey;
|
||||
final String? rankKey;
|
||||
|
||||
String toString() {
|
||||
return '$rankKey: $value $color';
|
||||
@@ -45,5 +45,5 @@ class CircularStackEntry {
|
||||
|
||||
/// An optional String key, used when animating charts to preserve semantics when
|
||||
/// transitioning between data points.
|
||||
final String rankKey;
|
||||
final String? rankKey;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ class AnimatedCircularChartPainter extends CustomPainter {
|
||||
AnimatedCircularChartPainter(this.animation, this.labelPainter) : super(repaint: animation);
|
||||
|
||||
final Animation<CircularChart> animation;
|
||||
final TextPainter labelPainter;
|
||||
final TextPainter? labelPainter;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
@@ -39,7 +39,7 @@ class CircularChartPainter extends CustomPainter {
|
||||
|
||||
const double _kRadiansPerDegree = Math.pi / 180;
|
||||
|
||||
void _paintLabel(Canvas canvas, Size size, TextPainter labelPainter) {
|
||||
void _paintLabel(Canvas canvas, Size size, TextPainter? labelPainter) {
|
||||
if (labelPainter != null) {
|
||||
labelPainter.paint(
|
||||
canvas,
|
||||
@@ -59,16 +59,16 @@ void _paintChart(Canvas canvas, Size size, CircularChart chart) {
|
||||
|
||||
for (final CircularChartStack stack in chart.stacks) {
|
||||
for (final segment in stack.segments) {
|
||||
segmentPaint.color = segment.color;
|
||||
segmentPaint.strokeWidth = stack.width;
|
||||
segmentPaint.color = segment.color!;
|
||||
segmentPaint.strokeWidth = stack.width!;
|
||||
|
||||
canvas.drawArc(
|
||||
Rect.fromCircle(
|
||||
center: Offset(size.width / 2, size.height / 2),
|
||||
radius: stack.radius,
|
||||
radius: stack.radius!,
|
||||
),
|
||||
stack.startAngle * _kRadiansPerDegree,
|
||||
segment.sweepAngle * _kRadiansPerDegree,
|
||||
stack.startAngle! * _kRadiansPerDegree,
|
||||
segment.sweepAngle! * _kRadiansPerDegree,
|
||||
chart.chartType == CircularChartType.Pie,
|
||||
segmentPaint,
|
||||
);
|
||||
|
||||
@@ -7,8 +7,8 @@ class CircularChartSegment extends MergeTweenable<CircularChartSegment> {
|
||||
CircularChartSegment(this.rank, this.sweepAngle, this.color);
|
||||
|
||||
final int rank;
|
||||
final double sweepAngle;
|
||||
final Color color;
|
||||
final double? sweepAngle;
|
||||
final Color? color;
|
||||
|
||||
@override
|
||||
CircularChartSegment get empty => CircularChartSegment(rank, 0.0, color);
|
||||
@@ -38,5 +38,5 @@ class CircularChartSegmentTween extends Tween<CircularChartSegment> {
|
||||
}
|
||||
|
||||
@override
|
||||
CircularChartSegment lerp(double t) => CircularChartSegment.lerp(begin, end, t);
|
||||
CircularChartSegment lerp(double t) => CircularChartSegment.lerp(begin!, end!, t);
|
||||
}
|
||||
+9
-9
@@ -17,15 +17,15 @@ class CircularChartStack implements MergeTweenable<CircularChartStack> {
|
||||
);
|
||||
|
||||
final int rank;
|
||||
final double radius;
|
||||
final double width;
|
||||
final double startAngle;
|
||||
final double? radius;
|
||||
final double? width;
|
||||
final double? startAngle;
|
||||
final List<CircularChartSegment> segments;
|
||||
|
||||
factory CircularChartStack.fromData(
|
||||
int stackRank,
|
||||
List<CircularSegmentEntry> entries,
|
||||
Map<String, int> entryRanks,
|
||||
Map<String?, int>? entryRanks,
|
||||
bool percentageValues,
|
||||
double startRadius,
|
||||
double stackWidth,
|
||||
@@ -42,7 +42,7 @@ class CircularChartStack implements MergeTweenable<CircularChartStack> {
|
||||
List<CircularChartSegment> segments = List<CircularChartSegment>.generate(entries.length, (i) {
|
||||
double sweepAngle = (entries[i].value / valueSum * _kMaxAngle) + previousSweepAngle;
|
||||
previousSweepAngle = sweepAngle;
|
||||
int rank = entryRanks[entries[i].rankKey] ?? i;
|
||||
int rank = entryRanks![entries[i].rankKey] ?? i;
|
||||
return CircularChartSegment(rank, sweepAngle, entries[i].color);
|
||||
});
|
||||
|
||||
@@ -78,10 +78,10 @@ class CircularChartStackTween extends Tween<CircularChartStack> {
|
||||
|
||||
@override
|
||||
CircularChartStack lerp(double t) => CircularChartStack(
|
||||
begin.rank,
|
||||
lerpDouble(begin.radius, end.radius, t),
|
||||
lerpDouble(begin.width, end.width, t),
|
||||
lerpDouble(begin.startAngle, end.startAngle, t),
|
||||
begin!.rank,
|
||||
lerpDouble(begin!.radius, end!.radius, t),
|
||||
lerpDouble(begin!.width, end!.width, t),
|
||||
lerpDouble(begin!.startAngle, end!.startAngle, t),
|
||||
_circularSegmentsTween.lerp(t),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user