GithubHelp home page GithubHelp logo

Can't use fonts about nativeshell HOT 20 CLOSED

nativeshell avatar nativeshell commented on July 24, 2024
Can't use fonts

from nativeshell.

Comments (20)

knopp avatar knopp commented on July 24, 2024

This could definitely be issue with nativeshell build. Given that some flutter targets litter the root project structure with ephemeral files as a workaround nativeshell runs the actual flutter build in a subfolder inside build folder. It does create symlinks for assets, but there might be cases where it doesn't work correctly. Is there a repository I can reproduce this with?

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

Not that I have publicly available, but I think trying to add a custom font to the nativeshell examples might produce the same error. I'll try and see immediately

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

Trying to add a custom font to the example project produces this error:

  Stderr:
  [        ] Unexpected child "example" found under "flutter".
  [   +8 ms] Please correct the pubspec.yaml file at /Users/wilson/Developer/Experimenting/examples/target/x86_64-apple-darwin/debug/build/nativeshell_examples-c92add7ebd1546ee/out/flutter/pubspec.yaml

from nativeshell.

knopp avatar knopp commented on July 24, 2024

That seems like a flutter tool error. Are you sure the pubspec.yaml is correct? Can you post it here?

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

My bad, the pubspec.yaml file was not correctly formatted. Trying again on the app template yielded the same error:

  Stderr:
  [  +50 ms] Error: unable to locate asset entry in pubspec.yaml: "fonts/Inter/Inter-Regular.ttf".
  [   +5 ms] Target debug_macos_bundle_flutter_assets failed: Exception: Failed to bundle asset files.
             #0      copyAssets (package:flutter_tools/src/build_system/targets/assets.dart:61:5)

from nativeshell.

knopp avatar knopp commented on July 24, 2024

Can you post the whole pubspec.yaml? Just in case. I'll try to reproduce this tomorrow.

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

Sure!

name: app_template
description: NativeShell application template
publish_to: 'none'
version: 1.0.0+1
environment:
  sdk: ">=2.12.0-214.0.dev <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  pedantic: ^1.9.2
  path: ^1.7.0

  cupertino_icons: ^1.0.0
  nativeshell:
    version: ^0.1.9

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  fonts:
    - family: Inter
      fonts:
        - asset: fonts/Inter/Inter-Regular.ttf
        - asset: fonts/Inter/Inter-Bold.ttf
          weight: 700
        - asset: fonts/Inter/Inter-Black.ttf
          weight: 900    

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

I can upload the project to a temporary repository if that helps

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

Here's the app template with fonts included: https://github.com/wilsonowilson/app_template

from nativeshell.

knopp avatar knopp commented on July 24, 2024

Sure, it won't harm :) Or at least the fonts folder. But I think the problem is that nativeshell only recognizes flutter/assets, it ignores flutter/fonts at this point. The functionality will need to be added in flutter_build.rs (copy_pubspec_yaml)

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

I initially tried with an assets folder. Let me update the example and see if that works.

from nativeshell.

knopp avatar knopp commented on July 24, 2024

I think for now you can manually add the fonts in flutter/assets so that they get copied.

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

In the flutter sdk?

from nativeshell.

knopp avatar knopp commented on July 24, 2024

No, I meant specifying the font files as flutter assets in pubspec.yaml (https://flutter.dev/docs/development/ui/assets-and-images)

from nativeshell.

knopp avatar knopp commented on July 24, 2024

Something like this should work:

flutter:
  assets:
    - fonts/

It should force nativeshell build to link the fonts folder.

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

Ah, gotcha. I guess if I wanted to use fonts that way, I'd have to use the FontLoader, correct?

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

Oh I think I misunderstood. It just helps nativeshell create a link, right?

from nativeshell.

knopp avatar knopp commented on July 24, 2024

No, you should be able to have both in pubspec.yaml

flutter:
  uses-material-design: true
  assets:
    - fonts/
  fonts:
    - family: Inter
      fonts:
        - asset: fonts/Inter/Inter-Regular.ttf
        - asset: fonts/Inter/Inter-Bold.ttf
          weight: 700
        - asset: fonts/Inter/Inter-Black.ttf
          weight: 900    

I haven't test this but it should work. The assets/fonts part is there just so that nativeshell makes the proper symlink before running the build.

In any case, this is a bug and it should be fixed properly.

from nativeshell.

knopp avatar knopp commented on July 24, 2024

Oh I think I misunderstood. It just helps nativeshell create a link, right?

Right.

from nativeshell.

wilsonowilson avatar wilsonowilson commented on July 24, 2024

Works like a charm! Thanks for the help!

from nativeshell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.