Skip to content

Capability to package and depend on non-code assets #1815

Open
@MichaelFenwick

Description

@MichaelFenwick

I have a few Dart (but not Flutter) applications which use the same non-code asset - in this case a font. This font, while not code itself, nonetheless runs through much of the some lifecycle as code would; it can be committed to a git repository and has semantic version numbers which are incremented as the font is developed.

I'd like to be able to create a package for this font, and then depend upon that package in other packages. For example:

MyFont package

Package Structure

src/
  myfont.sfd
fonts/
  myfont.otf
  myfont.woff
  myfont.woff2
pubspec.yaml

pubspec.yaml

name: myfont
version: 1.1.5
description: A really awesome font.

EpubBuilder package

pubspec.yaml

name: epubbuilder
version: 1.0.0
description: A application that creates epubs with an awesome font!

dependencies:
  myfont: ^1.1.0
  epubx: ^4.0.0

main.dart

import 'package:epubx/epubx.dart';
import 'package:myfont/fonts/myfont.otf' as myfontotf;

void main() {
  final EpubBook book = EpubBook();
  // do some stuff to build a great ebook
  embedFont(book, myfontotf);
  EpubWriter.writeBook(book);
}

void embedFont(EpubBook book, File fontFile) {
    final Uint8List fontData = fontFile.readAsBytesSync();
    final EpubByteContentFile myfontContentFile = EpubByteContentFile()
      ..Content = fontData
      ..ContentMimeType = 'application/vnd.ms-opentype'
      ..ContentType = EpubContentType.FONT_OPENTYPE
      ..FileName = myfont.otf;
    book.Content!.AllFiles![myfontContentFile.FileName!] = myfontContentFile;
}

That's just a guess at what the syntax might look like, but hopefully it gets the idea across well enough.

Note: I wouldn't expect non-code packages like this to be publishable to pub.dev, but rather just to be something which could be depended upon via path or hosted.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions