Created
April 8, 2020 22:11
-
-
Save knezzz/07340a21f0d1a831ba1c8ee430270650 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() { | |
| GradientController controller = GradientController(<Color>[ | |
| Color(0xffff0000), | |
| Color(0xff0000ff), | |
| Color(0xff00ff00), | |
| ]); | |
| print(controller.getColorAt(0.0) == Color(0xffff0000)); | |
| print(controller.getColorAt(0.5) == Color(0xff0000ff)); | |
| print(controller.getColorAt(1.0) == Color(0xff00ff00)); | |
| } | |
| class GradientController{ | |
| GradientController(this.colors); | |
| final List<Color> colors; | |
| Color getColorAt(double value){ | |
| value = value * (colors.length - 1); | |
| return Color.lerp(colors[value.floor()], colors[value.ceil()], value - value.floor()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment