Last active
December 16, 2021 11:03
-
-
Save jagomf/9ddbad3f41f19701f946b54495ad27bd to your computer and use it in GitHub Desktop.
Getting a color in between a scale in Dart/Flutter
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() => runApp(MyApp()); | |
const totalColorsToShow = 50; | |
const startColor = Colors.red; | |
const finalColor = Colors.green; | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar(title: const Text('Lerping colors')), | |
body: ListView( | |
children: List<double>.generate(totalColorsToShow, (i) => i / totalColorsToShow).map((e) { | |
final color = HSVColor.lerp(HSVColor.fromColor(startColor), HSVColor.fromColor(finalColor), e)?.toColor(); | |
return ListTile( | |
title: Text('scale $e/1, ${color.toString()}'), | |
tileColor: color, | |
); | |
}).toList() | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment