From d601842da09d9ebf339bd5c1eeb12f48ed57b0b3 Mon Sep 17 00:00:00 2001 From: Sphericalkat Date: Tue, 2 Jul 2024 11:43:07 +0530 Subject: [PATCH] fix(treewide): migrate to sound null safety Signed-off-by: Sphericalkat --- example/animated_pie_chart_example.dart | 2 +- example/animated_radial_chart_example.dart | 10 ++--- .../animated_random_radial_chart_example.dart | 6 +-- example/color_palette.dart | 10 ++--- lib/src/animated_circular_chart.dart | 32 ++++++++-------- lib/src/circular_chart.dart | 28 +++++++------- lib/src/entry.dart | 6 +-- lib/src/painter.dart | 14 +++---- lib/src/segment.dart | 6 +-- lib/src/stack.dart | 18 ++++----- pubspec.lock | 38 +++++++++---------- pubspec.yaml | 2 +- 12 files changed, 86 insertions(+), 86 deletions(-) diff --git a/example/animated_pie_chart_example.dart b/example/animated_pie_chart_example.dart index 00e50cc..39afe01 100644 --- a/example/animated_pie_chart_example.dart +++ b/example/animated_pie_chart_example.dart @@ -57,7 +57,7 @@ class _AnimatedPieChartExampleState extends State { setState(() { sampleIndex++; List data = _quarterlyProfitPieData[sampleIndex % 3]; - _chartKey.currentState.updateData(data); + _chartKey.currentState!.updateData(data); }); } diff --git a/example/animated_radial_chart_example.dart b/example/animated_radial_chart_example.dart index 19876f4..5650e44 100644 --- a/example/animated_radial_chart_example.dart +++ b/example/animated_radial_chart_example.dart @@ -17,13 +17,13 @@ class _AnimatedRadialChartExampleState extends State final _chartSize = const Size(200.0, 200.0); double value = 50.0; - Color labelColor = Colors.blue[200]; + Color? labelColor = Colors.blue[200]; void _increment() { setState(() { value += 10; List data = _generateChartData(value); - _chartKey.currentState.updateData(data); + _chartKey.currentState!.updateData(data); }); } @@ -31,12 +31,12 @@ class _AnimatedRadialChartExampleState extends State setState(() { value -= 10; List data = _generateChartData(value); - _chartKey.currentState.updateData(data); + _chartKey.currentState!.updateData(data); }); } List _generateChartData(double value) { - Color dialColor = Colors.blue[200]; + Color? dialColor = Colors.blue[200]; if (value < 0) { dialColor = Colors.red[200]; } else if (value < 50) { @@ -78,7 +78,7 @@ class _AnimatedRadialChartExampleState extends State @override Widget build(BuildContext context) { TextStyle _labelStyle = - Theme.of(context).textTheme.headline6.merge(TextStyle(color: labelColor)); + Theme.of(context).textTheme.headline6!.merge(TextStyle(color: labelColor)); return Scaffold( appBar: AppBar( diff --git a/example/animated_random_radial_chart_example.dart b/example/animated_random_radial_chart_example.dart index ce97cc6..b7d9ce0 100644 --- a/example/animated_random_radial_chart_example.dart +++ b/example/animated_random_radial_chart_example.dart @@ -19,7 +19,7 @@ class _RandomizedRadialChartExampleState extends State _chartKey = GlobalKey(); final _chartSize = const Size(300.0, 300.0); final Math.Random random = Math.Random(); - List data; + List? data; @override void initState() { @@ -32,7 +32,7 @@ class _RandomizedRadialChartExampleState extends State data = List.generate(stackCount, (i) { int segCount = random.nextInt(10); List segments = List.generate(segCount, (j) { - Color randomColor = ColorPalette.primary.random(random); + Color? randomColor = ColorPalette.primary.random(random); return CircularSegmentEntry(random.nextDouble(), randomColor); }); return CircularStackEntry(segments); diff --git a/example/color_palette.dart b/example/color_palette.dart index cd6884c..0ed00c1 100644 --- a/example/color_palette.dart +++ b/example/color_palette.dart @@ -3,7 +3,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; class ColorPalette { - static final ColorPalette primary = ColorPalette([ + static final ColorPalette primary = ColorPalette([ Colors.blue[400], Colors.blue[200], Colors.red[400], @@ -21,15 +21,15 @@ class ColorPalette { Colors.black, ]); - ColorPalette(List colors) : _colors = colors { + ColorPalette(List colors) : _colors = colors { assert(colors.isNotEmpty); } - final List _colors; + final List _colors; - Color operator [](int index) => _colors[index % length]; + Color? operator [](int index) => _colors[index % length]; int get length => _colors.length; - Color random(Random random) => this[random.nextInt(length)]; + Color? random(Random random) => this[random.nextInt(length)]; } diff --git a/lib/src/animated_circular_chart.dart b/lib/src/animated_circular_chart.dart index 16475f7..f46a348 100644 --- a/lib/src/animated_circular_chart.dart +++ b/lib/src/animated_circular_chart.dart @@ -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 initialChartData; + final List? 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(); if (nullOk || result != null) return result; @@ -151,10 +151,10 @@ class AnimatedCircularChart extends StatefulWidget { /// ``` class AnimatedCircularChartState extends State with TickerProviderStateMixin { - CircularChartTween _tween; - AnimationController _animation; - final Map _stackRanks = {}; - final Map _entryRanks = {}; + late CircularChartTween _tween; + late AnimationController _animation; + final Map _stackRanks = {}; + final Map _entryRanks = {}; final TextPainter _labelPainter = TextPainter(); @override @@ -165,13 +165,13 @@ class AnimatedCircularChartState extends State 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 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) diff --git a/lib/src/circular_chart.dart b/lib/src/circular_chart.dart index 5383a37..ae5913f 100644 --- a/lib/src/circular_chart.dart +++ b/lib/src/circular_chart.dart @@ -17,22 +17,22 @@ class CircularChart { final List stacks; final CircularChartType chartType; - final SegmentEdgeStyle edgeStyle; + final SegmentEdgeStyle? edgeStyle; - factory CircularChart.empty({@required CircularChartType chartType}) { + factory CircularChart.empty({required CircularChartType chartType}) { return CircularChart([], chartType); } factory CircularChart.fromData({ - @required Size size, - @required List data, - @required CircularChartType chartType, - @required bool percentageValues, - @required double startAngle, - Map stackRanks, - Map entryRanks, - double holeRadius, - SegmentEdgeStyle edgeStyle, + required Size size, + required List data, + required CircularChartType chartType, + required bool percentageValues, + required double startAngle, + Map? stackRanks, + Map? 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 stacks = List.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 { @override CircularChart lerp(double t) => CircularChart( _stacksTween.lerp(t), - begin.chartType, - edgeStyle: end.edgeStyle, + begin!.chartType, + edgeStyle: end!.edgeStyle, ); } diff --git a/lib/src/entry.dart b/lib/src/entry.dart index 04ab966..6eb1a66 100644 --- a/lib/src/entry.dart +++ b/lib/src/entry.dart @@ -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; } diff --git a/lib/src/painter.dart b/lib/src/painter.dart index b4ee61a..60b174a 100644 --- a/lib/src/painter.dart +++ b/lib/src/painter.dart @@ -9,7 +9,7 @@ class AnimatedCircularChartPainter extends CustomPainter { AnimatedCircularChartPainter(this.animation, this.labelPainter) : super(repaint: animation); final Animation 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, ); diff --git a/lib/src/segment.dart b/lib/src/segment.dart index 24ff8cc..5522f24 100644 --- a/lib/src/segment.dart +++ b/lib/src/segment.dart @@ -7,8 +7,8 @@ class CircularChartSegment extends MergeTweenable { 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 { } @override - CircularChartSegment lerp(double t) => CircularChartSegment.lerp(begin, end, t); + CircularChartSegment lerp(double t) => CircularChartSegment.lerp(begin!, end!, t); } diff --git a/lib/src/stack.dart b/lib/src/stack.dart index bfdcd07..91cbb73 100644 --- a/lib/src/stack.dart +++ b/lib/src/stack.dart @@ -17,15 +17,15 @@ class CircularChartStack implements MergeTweenable { ); final int rank; - final double radius; - final double width; - final double startAngle; + final double? radius; + final double? width; + final double? startAngle; final List segments; factory CircularChartStack.fromData( int stackRank, List entries, - Map entryRanks, + Map? entryRanks, bool percentageValues, double startRadius, double stackWidth, @@ -42,7 +42,7 @@ class CircularChartStack implements MergeTweenable { List segments = List.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 { @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), ); } diff --git a/pubspec.lock b/pubspec.lock index b308ac3..03307d6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.8.2" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.3.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -66,21 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.11" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.7.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -92,55 +92,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.4.3" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.1" sdks: - dart: ">=2.10.0-110 <2.11.0" + dart: ">=2.14.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 0c4f40f..715f7a4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,4 +12,4 @@ dev_dependencies: sdk: flutter environment: - sdk: ">=2.0.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0'