Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple null exceptions when tapping on bar graph rapidly #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions community_charts_common/lib/src/chart/bar/bar_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ class BarRenderer<D>
final domainAxis = series.getAttr(domainAxisKey) as ImmutableAxis<D>;
final measureAxis = series.getAttr(measureAxisKey) as ImmutableAxis<num>;

final barGroupIndex = series.getAttr(barGroupIndexKey)!;
final barGroupIndex = series.getAttr(barGroupIndexKey) ?? 0;
final previousBarGroupWeight = series.getAttr(previousBarGroupWeightKey);
final barGroupWeight = series.getAttr(barGroupWeightKey);
final allBarGroupWeights = series.getAttr(allBarGroupWeightsKey);
final numBarGroups = series.getAttr(barGroupCountKey)!;
final numBarGroups = series.getAttr(barGroupCountKey) ?? 0;

final bounds = _getBarBounds(
details.domain,
Expand Down Expand Up @@ -409,6 +409,7 @@ class BarRenderer<D>
// TODO: Investigate why this is negative for a DateTime domain
// in RTL mode.
domainWidth = domainWidth.abs();
if (numBarGroups == 0) numBarGroups = 1;

// If no weights were passed in, default to equal weight per bar.
if (barGroupWeight == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class LayoutManagerImpl implements LayoutManager {

@override
Rectangle<int> get drawableLayoutAreaBounds {
assert(_drawAreaBoundsOutdated == false);
if (_drawAreaBoundsOutdated != false) return Rectangle(0, 0, 0, 0);

final drawableViews =
_views.where((LayoutView view) => view.isSeriesRenderer);
Expand Down
8 changes: 4 additions & 4 deletions community_charts_flutter/lib/src/widget_layout_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ class WidgetLayoutDelegate extends MultiChildLayoutDelegate {
switch (horizontalJustification) {
case _HorizontalJustification.leftDrawArea:
behaviorOffset = new Offset(
behavior.drawAreaBounds!.left.toDouble(), heightOffset);
behavior.drawAreaBounds?.left.toDouble() ?? 0.0, heightOffset);
break;
case _HorizontalJustification.left:
behaviorOffset = new Offset(0.0, heightOffset);
break;
case _HorizontalJustification.rightDrawArea:
behaviorOffset = new Offset(
behavior.drawAreaBounds!.right - behaviorSize.width,
(behavior.drawAreaBounds?.right ?? behaviorSize.width) - behaviorSize.width,
heightOffset);
break;
case _HorizontalJustification.right:
Expand All @@ -149,15 +149,15 @@ class WidgetLayoutDelegate extends MultiChildLayoutDelegate {
case common.OutsideJustification.startDrawArea:
case common.OutsideJustification.middleDrawArea:
behaviorOffset =
new Offset(widthOffset, behavior.drawAreaBounds!.top.toDouble());
new Offset(widthOffset, behavior.drawAreaBounds?.top.toDouble() ?? 0.0);
break;
case common.OutsideJustification.start:
case common.OutsideJustification.middle:
behaviorOffset = new Offset(widthOffset, 0.0);
break;
case common.OutsideJustification.endDrawArea:
behaviorOffset = new Offset(widthOffset,
behavior.drawAreaBounds!.bottom - behaviorSize.height);
(behavior.drawAreaBounds?.bottom ?? behaviorSize.height) - behaviorSize.height);
break;
case common.OutsideJustification.end:
behaviorOffset =
Expand Down