Skip to content

How to extend existing utility? #321

Answered by leoafarias
Maksimka101 asked this question in Q&A
Discussion options

You must be logged in to vote

@Maksimka101, you bring up a valid point. Right now, we wanted to keep the builder method protected because we want to avoid the generation of custom build methods outside of the main signatures.

Here is an example:

extension LinearGradientUtilityX<T extends Attribute> on LinearGradientUtility<T> {
  LinearGradientUtility<T> get vertical {
    return LinearGradientUtility(
        (v) => only(begin: Alignment.topCenter, end: Alignment.bottomCenter));
  }
}

With this, you can have the vertical whenever the LinearGradientUtility is used. That would be $box.linearGradient.vertical or $box.decoration.gradient.linear.vertical.

When doing linearGradient.vertical.colors(), the begin and end will…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Maksimka101
Comment options

@leoafarias
Comment options

Answer selected by Maksimka101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants