【Flutter 实战】pubspec.yaml 配置文件详解

移动开发 作者: 2024-08-24 20:30:01
老孟导读:pubspec.yaml 文件是 Flutter 中非常重要的配置文件,下面就让我们看看里面各个配置的含义。 pubspec.yaml 是 Flutter 项目的配置文件,类似于 Andro
name: flutter_app
description: A new Flutter application.

publish_to: 'none' 

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

name

import 'package:flutter_app/home_page.dart';
import 'package:flutter_app_demo/home_page.dart';

description

version

path_provider: ^1.6.22

不指定或者 any

path_provider:

path_provider: any

x.y.z

path_provider: 1.6.22

<=x.y.z 或者<x.y.z

path_provider: <=1.6.22

path_provider: <1.6.22

>=a.b.c <x.y.z

path_provider: '>=1.0.0 <1.6.22'

^x.y.z

path_provider: ^1.6.22

author homepage issue_tracker repository

  • author:作者,填写自己的署名
  • homepage:主页。
  • issue_tracker:issue,一般写当前插件源代码的Github issue 地址。
  • repository:一般写当前插件源代码的Github地址。

Environment

environment:
  sdk: ">=2.7.0 <3.0.0"
environment:
  sdk: ">=2.7.0 <3.0.0"
  flutter: "1.22.0"
environment:
  sdk: ">=2.11.0-213.0.dev <2.12.0"

dependencies 和 dev_dependencies

  • 依赖 pub.dev 上的第三方库
  • 依赖本地库
  • 依赖 git repository
  • 依赖我们自己的 pub仓库

依赖 pub.dev 上的第三方库

dependencies:
  path_provider: ^1.6.22

依赖本地库

dependencies:
  flutter_package:
    path: ../flutter_package

依赖 git repository

dependencies:
  bloc:
    git:
      url: https://github.com/felangel/bloc.git
      ref: bloc_fixes_issue_110
      path: packages/bloc
  • url:github 地址
  • ref:表示git引用,可以是 commit hash,tag 或者 branch
  • path:如果 git 仓库中有多个软件包,则可以使用此属性指定软件包

依赖我们自己的 pub 仓库。

dependencies:
  bloc: 
    hosted:
      name: bloc
      url: http://your-package-server.com
    version: ^6.0.0

依赖覆盖

Running "flutter pub get" in flutter_app...                     

Because every version of flutter_plugin from path depends on path_provider ^0.5.0 and flutter_app depends on path_provider ^1.6.22,flutter_plugin from path is forbidden.
So,because flutter_app depends on flutter_plugin from path,version solving failed.
pub get failed (1; So,version solving failed.)
Process finished with exit code 1
dependency_overrides:
  path_provider: ^1.6.22
/Users/mengqingdong/project/flutter/bin/flutter --no-color pub get
Running "flutter pub get" in flutter_app...                     

Warning: You are using these overridden dependencies:
! path_provider 1.6.22
Running "flutter pub get" in flutter_app...                         0.5s
Process finished with exit code 0

Flutter

uses-material-design

flutter:
  uses-material-design: true

assets

assets:
  - images/a_dot_burr.jpeg
  - images/a_dot_ham.jpeg
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

plugin

flutter:
  plugin:
    platforms:
      android:
        package: com.flutter.app_market
        pluginClass: AppMarketPlugin
      ios:
        pluginClass: AppMarketPlugin
flutter:
  plugin:
    platforms:
      android:
        package: com.flutter.app_market
        pluginClass: AppMarketPlugin
      ios:
        pluginClass: AppMarketPlugin
      macos:
        default_package: app_market_macos
      web:
        default_package: app_market_web
        
原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
本文链接:http://www.jiecseo.com/news/show_68009.html