Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MichaelFenwick opened this issue Jun 9, 2024 · 0 comments
Open

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

MichaelFenwick opened this issue Jun 9, 2024 · 0 comments

Comments

@MichaelFenwick
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant