Add ability to switch color palettes for Coloured Fonts
- Dominant language
- Dart
- Stars
- 179k
- Forks
- 31.1k
- PR merge metrics
- PR metrics pending
Description
### Use case
It seems like Flutter already has support for [colored fonts](https://css-tricks.com/colrv1-and-css-font-palette-web-typography/), but it lacks a feature to switch the color palettes.
A font file can have more than 1 color palettes that user can chooses. In HTML, we can choose the palettes using `font-palette-values`, for example:
```html
Demo
body {
font-size: 7rem;
display: flex;
justify-content: space-around;
}
@font-face {
font-family: MyTestFont;
src: url('MyTestFont-Regular.ttf');
}
@font-palette-values --Dark {
font-family: MyTestFont;
base-palette: 1;
}
@font-palette-values --Light {
font-family: MyTestFont;
base-palette: 0;
}
.my-text-light {
font-family: "MyTestFont";
font-palette: --Light;
}
.my-text-dark {
font-family: "MyTestFont";
font-palette: --Dark;
}
F
F
```
The results show two different colors but the same fonts.

However, in Flutter, the first palettes are choosen by default, but there is no way to choose other palettes or even customize one.
```dart
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text(
'F',
style: TextStyle(
fontFamily: 'MyTestFont',
fontSize: 144,
),
),
),
),
);
}
}
```

The font file: https://github.com/iqfareez/demo_color_fonts_for_flutter_feature_report/blob/main/MyTestFont-Regular.ttf
Current workaround is maybe (not tested) is two have two different font file with different palettes. But that's far from ideal.
### Proposal
Add the ability to switch the font's color palettes.
Contributor guide
Assessment
This issue has not been assessed yet.