FontFeature.alternativeFractions constructor

const FontFeature.alternativeFractions()

Use alternative ligatures to represent fractions. (afrc)

When this feature is enabled (and the font supports it), sequences of digits separated by U+002F SOLIDUS character (/) or U+2044 FRACTION SLASH (⁄) are replaced by ligatures that represent the corresponding fraction. These ligatures may differ from those used by the FontFeature.fractions feature.

This feature overrides all other features.

The Ubuntu Mono font supports the afrc feature. It causes digits before slashes to become superscripted and digits after slashes to become subscripted. This contrasts to the effect seen with FontFeature.fractions.

link

To create a local project with this code sample, run:
flutter create --sample=dart.dart_ui.FontFeature.alternativeFractions.1 mysample

import 'package:flutter/widgets.dart';

/// Flutter code sample for [FontFeature.FontFeature.alternativeFractions].

void main() => runApp(const ExampleApp());

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return WidgetsApp(
      builder: (BuildContext context, Widget? navigator) =>
          const ExampleWidget(),
      color: const Color(0xffffffff),
    );
  }
}

class ExampleWidget extends StatelessWidget {
  const ExampleWidget({super.key});

  @override
  Widget build(BuildContext context) {
    // The Ubuntu Mono font can be downloaded from Google Fonts
    // (https://www.google.com/fonts).
    return const Text(
      'Fractions: 1/2 2/3 3/4 4/5',
      style: TextStyle(
        fontFamily: 'Ubuntu Mono',
        fontFeatures: <FontFeature>[
          FontFeature.alternativeFractions(),
        ],
      ),
    );
  }
}

See also:

Implementation

const FontFeature.alternativeFractions() : feature = 'afrc', value = 1;