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

Improve Gradient Model Identity Check #81

Open
victoreronmosele opened this issue Apr 7, 2024 · 0 comments
Open

Improve Gradient Model Identity Check #81

victoreronmosele opened this issue Apr 7, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@victoreronmosele
Copy link
Owner

victoreronmosele commented Apr 7, 2024

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);

@victoreronmosele victoreronmosele added the enhancement New feature or request label Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant