Fluent and pubspec files

Keywords: Flutter

summary

Each fluent project contains a pubspec.yaml file, commonly known as pubspec. When creating a new fluent project, this file will be generated in the project root directory to specify the dependencies required by the project, such as a specific package (and its version), font or image file. It also specifies other requirements, such as dependencies on developer packages (such as test or simulation packages), or specific restrictions on the version of the fluent SDK; Pubspec is written in YAML. You also need to pay attention to the writing of spaces (tabs and spaces).

pubspec.yaml file example

name: flutter_study_app
description: A new Flutter project.

# Downstream is to prevent packages from being accidentally published to
# pub.dev uses' pub publish '. This is the first choice for private bags.
publish_to: 'none' # If you want to publish to pub.dev, delete this line

# The version and build number of the application
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # Add the plug-in library dependency. The following is the added icon library for creating the fluent project
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.0

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

  # Add the assets file to the application, such as IC needed locally_ Launcher.png, add and import as follows:
  assets:
    - assets/images/ic_launcher.png

  # 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: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - 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

Package name and description

Name is the name of the current project package (not the program name). Each package needs a name. As for the naming rules, the names should be all lowercase and separated by underscores; Also make sure that the name is a valid Dart identifier and does not start with a number.

Description is the description of the project package, which is optional. However, if you intend to publish your package, you must provide a description, which should be in English. The description should be relatively short (60 to 180 characters), such as:

name: flutter_study_app
description: A new Flutter project.

Publish package to site

publish_to is used to specify the location of the publishing package. By default, the pub.dev site is used. If the package is not published, specify none to prevent the package from being published.

publish_to: 'none'

edition

The version and build number of the application are defined by version. For example, define the version name as 1.0.0 and the version number as 1:

version: 1.0.0+1

Version is three numbers separated by dots, such as 1.0.0; Followed by optional version numbers separated by +. Both version number and builder number may be overwritten in fluent; Build by specifying -- build name and -- build number, respectively.

In Android, build name is used as versionName and build number as versionCode. In iOS, build name is used as CFBundleShortVersionString and build number is used as CFBundleVersion.

SDK constraints

A package can indicate which versions of dependencies it supports, but the package has another implicit dependency: the Dart platform itself. The Dart platform develops over time. A package may only be applicable to some versions of the platform, so you can use environment to restrict the version range of the SDK, such as:

environment:
  sdk: ">=2.7.0 <3.0.0"

My current project is not compatible with flutter2.0, but it is still a project created with flutter1.22.6. Therefore, the minimum SDK constraint here is 2.7.0. After upgrading to flutter2.0, the SDK constraint here should be after 2.10.0.

Plug in Library dependency

General dependencies are listed in dependencies: These are packages that anyone who uses your package also needs. Dependencies that are required only during the development phase of the package itself are listed in dev_dependencies.

For example, the icon library added in the example depends on:

dependencies:
  cupertino_icons: ^1.0.0

During the development process, errors are reported due to different versions. For example, many modules use different versions of plug-in libraries, which may need to cover dependencies, etc,
You can then use override dependency_overrides, for example, the latest version of the icon library is used uniformly:

dependency_overrides:
  cupertino_icons: ^1.0.4

Assets asset file

A resource file is a file that is packaged into an application installation package and can be accessed at run time. Common asset types include static data (such as JSON files), configuration files, icons, and images (JPEG, WebP, GIF, animated WebP/GIF, PNG, BMP, and WBMP). Use example:

# Add the assets file to the application, such as IC needed locally_ Launcher.png, add and import as follows:
  assets:
    - assets/images/ic_launcher.png
 or
assets:
    - assets/images/

In addition to listing the images contained in the application package, image assets can also refer to one or more resolution specific "variants". For the understanding of "variants" and more resource files, please go to the official website:
https://flutter.cn/docs/devel...

Fonts font

The user-defined font is mainly used to meet the design needs of designers, so this configuration is also necessary; Currently, the font formats supported by fluent are as follows:

  • .ttf
  • .otf
    Examples of using custom fonts:

    flutter:
    fonts:
      - family: Raleway
        fonts:
          - asset: fonts/Raleway-Regular.ttf
          - asset: fonts/Raleway-Italic.ttf
            style: italic
      - family: RobotoMono
        fonts:
          - asset: fonts/RobotoMono-Regular.ttf
          - asset: fonts/RobotoMono-Bold.ttf
            weight: 700

    For more font related understanding, please attach the corresponding address of the official website:
    https://flutter.cn/docs/cookb...

Finally, there are many knowledge points waiting for me to practice and summarize. This article will be recorded here for the time being. See you another day!

Posted by MortimerJazz on Sun, 28 Nov 2021 14:50:48 -0800