font_metadata 0.0.5 copy "font_metadata: ^0.0.5" to clipboard
font_metadata: ^0.0.5 copied to clipboard

Flutter plugin to get font files metadata and attributes

example/lib/main.dart

import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:font_metadata/font_metadata.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _fontName = 'Unknown';

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              OutlinedButton(
                onPressed: () async {
                  FilePickerResult? result =
                      await FilePicker.platform.pickFiles(type: FileType.any);
                  if (result != null) {
                    File file = File(result.files.single.path!);
                    String extension =
                        (file.path.split('.').last).toLowerCase();
                    if (extension == 'ttf' || extension == 'otf') {
                      if (mounted) {
                        FontMetadata fontMetadata =
                            FontMetadata(FontFileSource(path: Platform.isIOS ? result.files.single.identifier! : file.path));


                        _fontName = await fontMetadata.getFontName() ?? "";
                        setState(() {});
                      }
                    }
                  }
                },
                child: const Text("Select font file"),
              ),
              Text("Font name: $_fontName")
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
130
pub points
0%
popularity

Publisher

unverified uploader

Flutter plugin to get font files metadata and attributes

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface

More

Packages that depend on font_metadata