Page URL: [https://flutter.dev/docs/cookbook/design/package-fonts.html][1]
Page source: [https://github.com/flutter/website/tree/master/src/docs/cookbook/design/package-fonts.md][1]
Description of issue:
I've been trying to replicate the project Export fonts from a package from the Flutter.dev cookbook page. But I'm getting lost in the instructions. The instructions indicate that :
To export a font from a package, you need to import the font files into the lib folder of the package project.
The instructions also say that (I quote)
assume you’ve got a Flutter library called awesome_package with fonts living in a lib/fonts folder.
And the awesome_package package/library folder structure is defined as follow
awesome_package/
lib/
awesome_package.dart
fonts/
Raleway-Regular.ttf
Raleway-Italic.ttf
My question is : How do I create the awesome_package. Do I necessarily need to publish the package on the pub.dev ?
Please help me out
How do I create the awesome_package.
See more about Flutter packages and plugins
Do I necessarily need to publish the package on the pub.dev ?
No, you can use the package locally.
If you just want to use differents fonts, don't create a package for this, use this package google_fonts
Or you can use your own font
Docs
flutter:
fonts:
- family: font_name
fonts:
- asset: fonts/font_name1.ttf
- asset: fonts/font_name1.ttf
Related
When creating a custom package that contains font as a .ttf file. I try to download the font file also in the example app that is contained in the package.
The font is downloaded successfully on iOS and macOS apps but not on Linux or Web.
The web console is giving me an error
Failed to load font My-Custom-Icons at assets/../lib/assets/fonts/My-Custom-Icons.ttf
...
my_package:
# When depending on this package from a real application you should use:
# custom_package: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
...
flutter:
uses-material-design: true
fonts:
- family: My-Custom-Icons
fonts:
- asset: ../lib/assets/fonts/My-Custom-Icons.ttf
I would expect that font would be downloaded the same way on all different platforms. What I'm missing here?
Hi just replace this and try.
- asset: assets/fonts/My-Custom-Icons.ttf
Ah, it seems that you can use the packages path when importing the font even inside the example. So the following did the work.
...
my_package:
# When depending on this package from a real application you should use:
# custom_package: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
...
flutter:
uses-material-design: true
fonts:
- family: My-Custom-Icons
fonts:
- asset: packages/my_package/assets/fonts/My-Custom-Icons.ttf
I am working in a Flutter project and I want to use the following Adobe fonts, how can I do that?
https://fonts.adobe.com/fonts/myriad
https://fonts.adobe.com/fonts/myriad-arabic
You need to download this fonts and place it to assets/fonts folder at the root of your project. Next, add fonts to your pubspec.yaml file. For example:
flutter:
fonts:
- family: FontFamily
fonts:
- asset: fonts/FontFamily-Regular.ttf
style: regular
You can find more information in Official Documentation.
for context I am currently following this exercise provided by flutter dev: https://codelabs.developers.google.com/codelabs/first-flutter-app-pt1/#3
I use android studio on a Windows 10 profesional.
I have seen this issue across many different areas and I am continually unable to get the English_Words package to upload. I had even uploaded the file directly the .packages and had the import work, however, the functions and classes do not validate
This is the import from main.dart
This is the pubspec.yaml, with the dependency properly spelled out
I had navigated and manually put in the english_words dependency. However, then the methods would not engage, even when the import worked. Furthermore, when I did ''' -flutter packages get ''', the file was removed, even with the .yaml dependency spelled out.
I have done lots of the recommended things:
-flutter doctor
-deleting the pubspec.lock and upgrading/getting packages
-shutting down the virtualization and android studio
cupertino icon and english words must have have a spacing of 2 just like flutter
ex:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words:^3.1.5
this is a YAML file so spacing have a special meaning. just correct it as i did in example enjoy.
I'm using flutter gallery sample code, and found following in pubspec.yaml file.
flutter:
assets:
- packages/shrine_images/0-0.jpg
I tried to find out packages and 0-0.jpg file in the project but couldn't find. Can anyone tell me what this package is all about and from where I am seeing images when running the app?
Actually they have added a package
flutter_gallery_assets: 0.1.9+2
Check it in pubspec.yaml dependencies, its a package so that you can use images from this package. So the pictures are from that package and they are just mentioning the image path from that package. Here is the package link they are using click here
I've created a Flutter standalone app and it's all working fine.
But now I want to integrate some of the screens of that Flutter app in an existing Android/iOS app.
Is it possible?
Yes.
I could make it work by adding this at the end of the pubspec.yaml:
module:
androidPackage: com.teste.embeded
iosBundleIdentifier: com.teste.embeded
Add this and then call a packages get. This will create 2 hidden folders in your project structure: .android and .ios.
Becareful with the identation! This settings must be inside the flutter: tag, like this:
flutter:
uses-material-design: true
assets:
- images/a_dot_burr.jpeg
- images/a_dot_ham.jpeg
module:
androidPackage: com.test.embeded
iosBundleIdentifier: com.test.embeded
After doing this, follow the documentation for the Android/iOS sides (skip the module creating parts).
https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps
You can do that in tow ways:
1- Convert your project to Flutter module and then put that along side the native project and call your FlutterActivity from native
2- Convert your project to Flutter module and make an AAR from it ant import in the native project
Read this Flutter documentation:
https://flutter.dev/docs/development/add-to-app/android/project-setup