Icon not displaying in flutter - flutter

Ok, so I'm trying to implement a custom icon in flutter but it's not rendering the image.
enter image description here
Font code:
fonts:
family: icon
fonts:
asset: assets/fonts/MyFlutterApp.ttf
Icon code:
icon: new Icon(const IconData(0xe800, fontFamily: 'icon'))

Related

Im not able to get my custom font working

Im trying to setup my font here: https://github.com/kaspernordkvist/uncut_sans/tree/main/Static
this is my pubspec.yaml
fonts:
- family: UncutSans
fonts:
- asset: lib/theme/fonts/UncutSans-Bold.ttf
weight: 700
- asset: lib/theme/fonts/UncutSans-Semibold.ttf
weight: 600
- asset: lib/theme/fonts/UncutSans-Light.ttf
weight: 300
- asset: lib/theme/fonts/UncutSans-Regular.ttf
weight: 400
- asset: lib/theme/fonts/UncutSans-Medium.ttf
weight: 500
In my ios emulator everything just looks fine, but on my real device it completely ignores my font weights I just set up. For example:
...
TextStyle(
fontWeight: FontWeight.w300,
fontSize: 18.0,
fontFamily: 'UncutSans',
color: Theme.colorDarkBodyText,)
...
This Text is thin and looks fine on simulator. On my real device it more looks like a font weight of Semibold 600.
Whats missing here?
EDIT: Folder Structure (Screenshot I made when I tried to add the variable type of the font. It doesnt make any difference using the variable font and update pubspec.yaml or choose the single ttfs.)

I placed icons created with the "Flutter custom icons generator". But something is wrong.I would like to set up icons with a SVG-like design

issue
I want to put icons like SVG.
But I can't put it.
The dart file generated by the Flutter custom icons generator.
class WDLogo {
WDLogo._();
static const _kFontFam = 'WDLogo';
static const String? _kFontPkg = null;
static const IconData arrow_back = IconData(0xe801, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData arrow_forward = IconData(0xe802, fontFamily: _kFontFam, fontPackage: _kFontPkg);
static const IconData menu = IconData(0xe803, fontFamily: _kFontFam, fontPackage: _kFontPkg);
}
pubspec.yaml
fonts:
- family: WDLogo
fonts:
- asset: assets/fonts/WDLogo.ttf
icon widget
"Icon(WDLogo.arrow_back))"
https://www.fluttericon.com/
SVG (Correct icon)
Mac folder
Flutter custom icons generator
Mac font preview
You need to add your fonts to asset folder and defined it on pubspec.yaml file like this
flutter:
fonts:
- family: MyFlutterApp
fonts:
- asset: fonts/MyFlutterApp.ttf
first add plugin ,link : https://pub.dev/packages/fluttericon/install
to your pubsepec.yaml file. after that import file.
then
Call Your icons like this
final myIcons = const <Widget>[
const Icon(Typicons.attention),
const Icon(Fontelico.emo_wink),
const Icon(Linecons.globe),
];
DONT USE LIKE THIS "Icon(WDLogo.arrow_back))",
if You need to use SVG , you can use this Flutter svg plugin for that ,
link for plugin https://pub.dev/packages/flutter_svg
final String assetName = 'assets/image.svg';
final Widget svg = SvgPicture.asset(
assetName,
semanticsLabel: 'Acme Logo'
);

Change custom color font in flutter not working for spec font

I'm using this font https://www.dafont.com/pixeloid-sans.font in flutter, but can't accept custom colors, like this:
pubspec.yaml :
fonts:
- family: Pixeloid Sans
fonts:
- asset: fonts/PixeloidSans-Bold.ttf
- asset: fonts/PixeloidSans.ttf
now, code:
Text(
'You have pushed the button this many times:',
style: Theme.of(context).textTheme.headline5!.apply(color: Colors.amberAccent, fontFamily: "Pixeloid Sans"),
)
The font changes, but color not.

Does Flutter/Dart know what glyphs are available in loaded font files?

I am trying to put a specified unicode character into a Text widget, but only if there is a glyph available in the fontFamily font specified in the TextStyle.
What currently happens by design is the fontFamilyFallback font is checked for a glyph, and if not found then the system font is checked, then if still no glyph found a 'not found' style glyph is rendered instead - usually a box with an X inside (depends on system I think).
I wonder if there is a way to disable that fall-back or even better have a list of available glyphs before building the text widget?
Attached some example code, and the results of the code in a screenshot. The code uses two fonts available via google fonts, and attempts to output the euro unicode character \u20ac. You can see from the screenshot that Syne has a glyph at u20ac, but Arvo does not. This could also be validated in for example Windows Character map.
Flutter Code (nothing in texttheme other than fontsize):
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'No fontfamily, no fontfamilyfallback \u20AC',
),
Text(
'fontfamily Syne Tactile: \u20AC',
style: TextStyle(fontFamily: 'Syne'),
),
Text(
'fontfamily Arvo, no fontfamilyfallback \u20AC',
style: TextStyle(fontFamily: 'Arvo'),
),
Text(
'fontfamily Arvo, fontfamilyfallback: Syne Tactile \u20AC',
style:
TextStyle(fontFamily: 'Arvo', fontFamilyFallback: ['Syne']),
),
],
),
),
); }
pubspec.yaml:
fonts:
- family: Arvo
fonts:
- asset: assets/Arvo-Regular.ttf
- family: Syne
fonts:
- asset: assets/SyneTactile-Regular.ttf
Flutter Web Output
Found a bit of a hack/workaround. If I load the AdobeBlank font into the package, and use that as fontFamilyFallback, then a glyph with zero width is displayed. Not ideal (better to know before building), but sort of does the job.
Can also then try and determine width before building using something like this.
Hopefully there is a better answer out there still, as I'd much rather be able to load a font and know what glyphs are available somehow.

Flutter custom font weights not getting picked up

Using google fonts I have no issues with getting font weights to display correctly. But as soon as I use a custom font I have trouble. I'm using the sofia pro font and I've put the fonts into my assets folder and set up by pubspc.yaml as following:
fonts:
- family: SofiaPro
fonts:
- asset: assets/fonts/SofiaProUltraLight.ttf
weight: 200
- asset: assets/fonts/SofiaProLight.ttf
weight: 300
- asset: assets/fonts/SofiaProRegular.ttf
weight: 400
- asset: assets/fonts/SofiaProMedium.ttf
weight: 500
- asset: assets/fonts/SofiaProSemiBold.ttf
weight: 600
- asset: assets/fonts/SofiaProBold.ttf
weight: 700
- asset: assets/fonts/SofiaProBlack.ttf
weight: 900
- family: SofiaProRegular
fonts:
- asset: assets/fonts/SofiaProRegular.ttf
weight: 400
I'm then referencing the font in two ways - once where it's in its own font family with no other weights and once where it's in with a list of other weights.
Container(
height: height,
child: Center(
child: Text(
"This text has weight w400",
style: TextStyle(fontFamily: 'SofiaPro', fontSize: size, fontWeight: FontWeight.w400),
)),
),
Container(
height: height,
child: Center(
child: Text(
"This text has weight w400",
style: TextStyle(fontFamily: 'SofiaProRegular', fontSize: size, fontWeight: FontWeight.w400),
)),
),
So, the only difference is the font family I'm referring to, but the text displayed is only shown correctly for the one where it's in a family by itself. For the other one I get the weight of the first font in the list. Not sure what I'm missing here.
Probably there's no font family SofiaProRegular at all in the fonts that you provide.
Please note that you're adding assets/fonts/SofiaProRegular.ttf twice both for SofiaPro and SofiaProRegular family.
If you want to use the same font in two font families try to copy the font file under a different name.