Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Fix warnings for Flutter 3.0 - Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which excludes null. #765

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion charts_flutter/example/lib/behaviors/slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class _SliderCallbackState extends State<SliderLine> {
});
}

SchedulerBinding.instance!.addPostFrameCallback(rebuild);
_ambiguate(SchedulerBinding.instance)!.addPostFrameCallback(rebuild);
}

fzyzcjy marked this conversation as resolved.
Show resolved Hide resolved
@override
Expand Down Expand Up @@ -194,3 +194,11 @@ class LinearSales {

LinearSales(this.year, this.sales);
}

/// This allows a value of type T or T?
/// to be treated as a value of type T?.
///
/// We use this so that APIs that have become
/// non-nullable can still be used with `!` and `?`
/// to support older versions of the API as well.
T? _ambiguate<T>(T? value) => value;
16 changes: 12 additions & 4 deletions charts_flutter/lib/src/chart_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ class ChartContainerRenderObject<D> extends RenderCustomPaint

// Sometimes chart behaviors try to draw the chart outside of a Flutter draw
// cycle. Schedule a frame manually to handle these cases.
if (!SchedulerBinding.instance!.hasScheduledFrame) {
SchedulerBinding.instance!.scheduleFrame();
if (!_ambiguate(SchedulerBinding.instance)!.hasScheduledFrame) {
_ambiguate(SchedulerBinding.instance)!.scheduleFrame();
}

SchedulerBinding.instance!.addPostFrameCallback(startAnimationController);
_ambiguate(SchedulerBinding.instance)!.addPostFrameCallback(startAnimationController);
}

/// Request Flutter to rebuild the widget/container of chart.
Expand All @@ -229,7 +229,7 @@ class ChartContainerRenderObject<D> extends RenderCustomPaint
// This is needed to request rebuild after the legend has been added in the
// post process phase of the chart, which happens during the chart widget's
// build cycle.
SchedulerBinding.instance!.addPostFrameCallback(doRebuild);
_ambiguate(SchedulerBinding.instance)!.addPostFrameCallback(doRebuild);
}

fzyzcjy marked this conversation as resolved.
Show resolved Hide resolved
/// When Flutter's markNeedsLayout is called, layout and paint are both
Expand Down Expand Up @@ -377,3 +377,11 @@ class ChartContainerCustomPaint extends CustomPainter {
return nodes;
}
}

/// This allows a value of type T or T?
/// to be treated as a value of type T?.
///
/// We use this so that APIs that have become
/// non-nullable can still be used with `!` and `?`
/// to support older versions of the API as well.
T? _ambiguate<T>(T? value) => value;