Skip to content

Improve Gradient Model Identity Check #81

Description

@victoreronmosele

Improvements

The logic for determining an AbstractGradient's identity has some improvements that can be made:

1. Add Gradient Direction To AbstractGradient's Identity Check

The GradientDirection is not considered part of the AbstractGradient's identity check.

The only properties checked are:

  1. the widget string,
  2. the gradient style and
  3. the flutter gradient object.

This leads to specifying the gradient direction separately from the gradient object when selecting rebuild triggers for the PreviewSection. See #80 (comment).

LinearStyleGradient

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is LinearStyleGradient &&
runtimeType == other.runtimeType &&
toWidgetString() == other.toWidgetString() &&
getGradientStyle() == other.getGradientStyle() &&
toFlutterGradient() == other.toFlutterGradient();
@override
int get hashCode => hash3(toWidgetString().hashCode,
getGradientStyle().hashCode, toFlutterGradient().hashCode);

2. Reuse Identity Check Logic

The logic for the identity check is duplicated across LinearStyleGradient, RadialStyleGradient, and SweepStyleGradient.

The logic can be centralized in the AbstractGradient class.

This will improve maintainability, especially as other gradient styles will be introduced.

LinearStyleGradient:

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is LinearStyleGradient &&
runtimeType == other.runtimeType &&
toWidgetString() == other.toWidgetString() &&
getGradientStyle() == other.getGradientStyle() &&
toFlutterGradient() == other.toFlutterGradient();
@override
int get hashCode => hash3(toWidgetString().hashCode,
getGradientStyle().hashCode, toFlutterGradient().hashCode);

RadialStyleGradient:

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is RadialStyleGradient &&
runtimeType == other.runtimeType &&
toWidgetString() == other.toWidgetString() &&
getGradientStyle() == other.getGradientStyle() &&
toFlutterGradient() == other.toFlutterGradient();
@override
int get hashCode => hash3(toWidgetString().hashCode,
getGradientStyle().hashCode, toFlutterGradient().hashCode);

SweepStyleGradient:

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is SweepStyleGradient &&
runtimeType == other.runtimeType &&
toWidgetString() == other.toWidgetString() &&
getGradientStyle() == other.getGradientStyle() &&
toFlutterGradient() == other.toFlutterGradient();
@override
int get hashCode => hash3(toWidgetString().hashCode,
getGradientStyle().hashCode, toFlutterGradient().hashCode);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions