Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: unable to locate asset entry in pubspec.yaml: "assets/fonts/Lato-Regular.ttf"

Before I wrote this, I searched everywhere for my mistake, but I didn't find anything.

although I have everything correctly and written down in the pubspec.yaml file, I get this error in the debug console:

Launching lib/main.dart on Android SDK built for x86 in debug mode...
Error: unable to locate asset entry in pubspec.yaml: "assets/fonts/Lato-Regular.ttf".
✓ Built build/app/outputs/apk/debug/app-debug.apk.
Error: unable to locate asset entry in pubspec.yaml: "assets/fonts/Lato-Regular.ttf".
Exited (sigterm)

my pubspec.yaml file looks like this:

name: shopping_app
description: A new Flutter project.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  fonts:
    - family: Lato
      fonts:
        - asset: assets/fonts/Lato-Regular.ttf
        - asset: assets/fonts/Lato-Bold.ttf
          weight: 700
    - family: Anton
      fonts:
        - asset: assets/fonts/Anton-Regular.ttf
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

here is the path where the fonts are inside:

path screenshot

Can you help me maybe? I just can't find a solution

best regards

like image 459
Tolga Avatar asked Dec 20 '19 23:12

Tolga


3 Answers

The assets folder should be in the root path (/). If you want to keep it in the lib folder, put lib in front of assets like this:

//new path
lib/assets/fonts/Lato-Regular.ttf

Sidenote: To avoid having to import fonts manually, I recommend the google_fonts package. It has hundreds of fonts including Lato and you can access it with GoogleFonts.lato() to get a default TextStyle with the Lato font without having to import it via the pubspec.yml file.

like image 109
Benjamin Avatar answered Nov 16 '22 03:11

Benjamin


If there is no font-family for your font, then try using this:

  1. Create an assets folder
  2. Move your font file under the assets folder.
  3. Give a simple name to your font file. Like without special characters or caps.
  4. Add this code in pubspec.yaml
fonts:
    - family: CustomFamilyName
      fonts:
        - asset: assets/fontfile.ttf
  1. run pub get

  2. stop your app and restart it.

like image 37
NullByte08 Avatar answered Nov 16 '22 03:11

NullByte08


Just check the indentation on more time, like tabs and spaces and all I would recommended copying the code from flutter-font-declaration and then making changes to it. And one more thing is, if your fonts are in lib/assets/fonts folder you should mention the total path from root directory in your yaml file. Happy debugging :)

like image 1
Umar Farooq Avatar answered Nov 16 '22 04:11

Umar Farooq