Unexpected key assets ((String)) under font - Mobile app error in flutter and dart

flutter custom font not working
flutter otf font
flutter fonts
dart fonts
flutter monospace font
flutter web font
unable to locate asset entry in pubspec yaml fonts raleway regular ttf
flutter io custom fonts

I'm new to Mobile development and I'm using Dart and Flutter to build mobile applications, both android and ios apps. The problem is I can't start my application and I keep getting an error related to the pubspec.yaml file.

When I comment the fonts: section, The app runs properly. But I need to load the fonts, so that is not solving my problem.

This is my pubspec.yaml

name: simple_app
description: A new Flutter project.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  fonts:
    - family: Oxygen
      fonts:
        - assets: assets/fonts/Oxygen-Regular.ttf
        - assets: assets/fonts/Oxygen-Light.ttf
        - assets: assets/fonts/Oxygen-Bold.ttf

  assets:
    - assets/images/

Bellow is the error I keep getting in the console.

Error detected in pubspec.yaml:
Unexpected key assets ((String)) under font.
Unexpected key assets ((String)) under font.
Unexpected key assets ((String)) under font.
C:\Users\user\Documents\mobile_app\flutter\simple_app\pubspec.yaml
exit code 1

please see my working example

  fonts:
    - family: icomoon
      fonts:
        - asset: assets/fonts/IcoMoon.ttf

    - family: Qwigley
      fonts:
        - asset: assets/fonts/Qwigley-Regular.ttf

    - family: Dosis
      fonts:
        - asset: assets/fonts/dosis/Dosis-Regular.otf
          weight: 400
        - asset: assets/fonts/dosis/Dosis-Medium.otf
          weight: 500
        - asset: assets/fonts/dosis/Dosis-SemiBold.otf
          weight: 600
        - asset: assets/fonts/dosis/Dosis-Bold.otf
          weight: 800
        - asset: assets/fonts/dosis/Dosis-ExtraBold.otf
          weight: 900

Typo in pubspec.yaml fonts leads to TypeError instead of helpful , I can't run my app on my device,when i click the run button, there was no gradle build info tips. and no error on my terminal,but only some info in  name: AppName description: My App rocks. # 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 +.


fonts: - family: Poppins fonts: - asset: assets/fonts/Poppins-Black.ttf

Check there is a difference between asset and assets. kindly check and update it.

Use a custom font, dependencies: flutter: sdk: flutter builders: r_flutter: <version> generate localization keys. arb files are essentialy json files with some special, Compiler must run at least once to generate the file. assets.dart will be Other locales will be searched under the same folder as the default Add it to your app. 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.


try this pubspec.yaml:

name: custom_fonts
description: An example of how to use custom fonts with Flutter

dependencies:
  flutter:
    sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  fonts:
    - family: DUBAI
      fonts:
        - asset: assets/fonts/DUBAI-BOLD.TTF
        - asset: assets/fonts/DUBAI-LIGHT.TTF
        - asset: assets/fonts/DUBAI-MEDIUM.TTF
        - asset: assets/fonts/DUBAI-REGULAR.TTF
    - family: Dima
      fonts:
        - asset: assets/fonts/DimaPlatinum.ttf

  uses-material-design: true

  assets:
    - assets/azmoon.db
    - assets/qi1.png

and maybe you like to have a look on main.dart:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Custom Fonts',
      // Set Raleway as the default app font.
      theme: ThemeData(fontFamily: 'Raleway'),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // The AppBar uses the app-default Raleway font.
      appBar: AppBar(title: Text('Custom Fonts')),
      body: Center(
        // This Text widget uses the RobotoMono font.
        child: Text(
          'Roboto Mono sample',
          style: TextStyle(fontFamily: 'RobotoMono'),
        ),
      ),
    );
  }
}

see the full tutorial on https://flutter.dev/docs/cookbook/design/fonts.

and in case you faced the "Error: unable to locate asset entry in pubspec.yaml" issue see Error: unable to locate asset entry in pubspec.yaml: "assets/fonts/Lato-Regular.ttf". :)

Export fonts from a package, Development with. Flutter. Create Cross-Platform. Mobile Apps. Rap Payne We​'ve found that Dart has got its by a more in-depth explanation of the features that will be unexpected by widget types, keys, and stateless vs. stateful widgets​. If you want to display a string to the screen, the Text widget is what you'll need​. Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.


r_flutter, “How to use a custom font in a Flutter app” is published by Suragch. Copy and paste your font into the new assets directory. I'm just using a Add the fonts info under the flutter section. Indentation is mandatory. flutter: fonts: A Flutter and Dart developer with a background in Android and iOS. Follow me  Add an assets subsection to the flutter section like this: flutter: assets: - assets/my_file.txt If you have multiple files that you want to include, then you can leave off the file name and just use the directory name (include the final /): flutter: assets: - assets/ Get the text in code


Beginning App Development with Flutter, framework and developing all type of mobile applications using Flutter Programming and basic knowledge on Android framework and Dart The core concept of the Flutter framework is In Flutter, Everything is a widget. String values are specified in either Specify the assets in the pubspec.yaml as shown below: flutter  Note: Check out the google_fonts package for direct access to almost 1000 open-sourced font families. Flutter works with custom fonts and you can apply a custom font across an entire app or to individual widgets. This recipe creates an app that uses custom fonts with the following steps: Import the font files. Declare the font in the pubspec.


How to use a custom font in a Flutter app - Suragch, In this tutorial we are going to start with an overview of Dart strings and Unicode. styling text for your app, first for entire strings and then for spans within a string. Flutter'; print(myString); return Text( myString, style: TextStyle(fontSize: 30.0), ); } We want to make our messages easy to decode, so we agree on a code key,​  dev_dependencies: flutter_test: sdk: flutter test: ^0.12.0 http: ^0.11.3+16 image: ^1.1.30 Then click on Package get (shown in Android Studio) option to add above dependency for the project. You can also do the same using command(in project stucture): flutter packages get