flutter / flutter/flutter

Add ability to switch color palettes for Coloured Fonts

Open
#161,804 0 comments 1 reaction 0 assignees View on GitHub
a: typography c: proposal framework P3 team-engine triaged-engine
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.

![Image](https://github.com/user-attachments/assets/7aeedfca-5869-4730-aaea-2a7e3d46904d)

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,
),
),
),
),
);
}
}
```

![Image](https://github.com/user-attachments/assets/4bbb03b3-7db3-48d9-80cb-6ed4d0208250)

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.