前言
環境搭建完成之後,我們來看看Flutter:New Project後生成的項目結。
具體環境搭建可以參考:w7上使用VSCode配置Flutter開發環境
項目結構
pubspec.yaml配置文件說明
- 作用
每個發佈包都需要一些元數據,以便能夠指定它的依賴項。與他人共享的發佈包還需要提供一些其他信息,以便用戶能夠發現它們。所有這些元數據都放在一個名爲pubspec.yaml的yamll(YAML 是專門用來寫配置文件的語言,非常簡潔和強大,遠比 JSON 格式方便)文件中。 - 支持的字段
name,version,description,author/authors,homepage,repository,issue_tracker,documentation,dependencies,dev_dependcencies,dependency_overrides,environment,excutables,publish_to -
與Node.js的package.json文件的類比
(因爲我在web開發裏是使用Node.js來做包管理的,所以類比nonde.js的package.json對於由web入門學習flutter的同學會比較容易理解。)簡單而言,pubspec.yaml文件的作用就相當於Node.js的package.json文件,是用來進行包管理的;
兩者都分離了兩個環境,dependencies和dev_dependencies;
前者使用yaml語法來定義,後者使用json語法;
pubspec.yaml對版本的約束規則與package.json規則類似;Node.js Flutter 安裝依賴 npm install flutter package get 升級依賴包版本 npm update flutter packages upgrade 協同開發保證包版本一致 package-lock.json pubspec.lock 關於此後續可以再豐富~~
- 默認的配置如下,有備註解釋:
#包名
name: todo_app
#描述信息
description: A new Flutter project.
#版本號
version: 1.0.0+1
#指定環境
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
#指定包依賴
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
english_words: ^3.1.0
#指定開發環境下的包依賴
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/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