Skip to content

Instantly share code, notes, and snippets.

@Levi-Lesches
Created January 12, 2023 05:12
Show Gist options
  • Save Levi-Lesches/58395f9075cd96de07796db3de5f81c2 to your computer and use it in GitHub Desktop.
Save Levi-Lesches/58395f9075cd96de07796db3de5f81c2 to your computer and use it in GitHub Desktop.
quiet-gust-6827
import "package:flutter/material.dart";
void main() => runApp(MaterialApp(home: Home()));
class Home extends StatefulWidget {
@override
HomeState createState() => HomeState();
}
final red = HSVColor.fromColor(Colors.red);
final purple = HSVColor.fromColor(Colors.purple);
const double size = 200;
class HomeState extends State<Home> {
double color = 0;
double color2 = 0;
Color getColor(double val) =>
HSVColor.lerp(red, purple, val)!.toColor();
Color getColor2(double val) =>
Color.lerp(Colors.red, Colors.purple, val)!;
@override
Widget build(BuildContext context) => Scaffold(
body: Column(
children: [
Slider(
value: color,
min: 0,
max: 1,
onChanged: (double val) => setState(() => color = val),
),
Container(
height: size,
width: size,
color: getColor(color),
child: Text("HSV: $color"),
),
Slider(
value: color2,
min: 0,
max: 1,
onChanged: (double val) => setState(() => color2 = val),
),
Container(
height: size,
width: size,
color: getColor2(color2),
child: Text("RGB: $color2"),
),
]
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment