bluemix / Gradient-Widgets

Flutter widgets wrapped with gradients
Apache License 2.0
348 stars 48 forks source link

Make shaderRect optional on Text widgets #3

Closed simolus3 closed 5 years ago

simolus3 commented 5 years ago

Problem

Thanks for this great and useful library. I wanted to point out a potential problem with the GradientText widget: It requires users to set a fixed Rect which is then going to be used to determine the size of the shader. However, especially with dynamic texts, we often don't know what size to use here. It would be great if we had the option to instead use a rect that is as big as the text to draw.

Solution

The built-in widget ShaderMask can solve this for us: It will dynamically give us a rect obtained by measuring the child widget during layout. We can make advantage of this by just using that rectangle to create the shader. In this PR, I thus make the shaderRect optional for GradientText. If a shaderRect is provided, that size will always be used. Otherwise, the dynamic size of the text will be used instead.

Backwards-compatibility

These changes should be backwards compatible because the look doesn't change provided a non-null shaderRect was given. This does change the appearance when that parameter was force-set to null before, as the previous behavior was to use a fixed rect in that case. The design of the example page has also changed because I removed the shaderRect parameter, which was different from the actual text size. If this is not desirable, changing it back to Rect.fromLTWH(0.0, 0.0, 50.0, 50.0) will make the text appear like it did before.

bluemix commented 5 years ago

thanks dear 👍 :)