flutter_freetype

Cross-platform FreeType bindings for Flutter using FFI on native platforms and WebAssembly on the web.

Features

  • Bindings generated automatically with ffigen
  • Native FreeType is built automatically by the Flutter plugin_ffi build (Android/iOS/macOS/Linux/Windows)
  • Web/Wasm uses the bundled wasm/dist/freetype.{js,wasm}
  • A declared Flutter Web plugin entry point allows pub.flutter-io.cn and Flutter tooling to detect Web support

Installation

dependencies:
  flutter_freetype: ^1.0.0

Binding generation

dart run ffigen

Native builds (Android/iOS/macOS/Linux/Windows)

No manual steps required. The consuming Flutter app builds and bundles the native library automatically (Flutter plugin_ffi).

On Windows, FreeType is linked into flutter_freetype.dll; applications do not ship a second standalone FreeType DLL. Warnings from vendored FreeType C sources are suppressed only for that third-party target, while warnings in the plugin bridge remain visible.

Usage

Prefer the async constructor so the same code works on Web/Wasm and native:

import 'package:flutter_freetype/flutter_freetype.dart';

final ft = await Freetype.create();

On Web/Wasm, load fonts from bytes (paths are not supported):

final face = ft.newFaceFromBytes(fontBytes);

The JavaScript loader and WASM module are Flutter package assets. Consumers do not add <script> tags or copy artifacts into their application web/ directory.

If you need the raw ffigen bindings on native platforms, import:

import 'package:flutter_freetype/flutter_freetype_ffi.dart';

Tests

  • VM (default): flutter test test/vm
  • Web/Wasm (optional): RUN_WEB_TESTS=1 ./scripts/test_all.sh
  • All (VM only): ./scripts/test_all.sh

License

Original package code is available under the MIT License. The bundled FreeType source and binary are distributed under the FreeType License. Other bundled components and the example font retain their respective open-source licenses. See THIRD_PARTY_NOTICES.md for attribution and full license references.

Libraries

flutter_freetype
flutter_freetype_ffi
Native (Dart VM / Flutter native) FFI exports.
flutter_freetype_web