一、flutter项目的配置文件说明
- flutter配置文件是pubspec.yaml
- 一些常用组件介绍
name: offlinetestroom_flutter #项目名
description: "A new Flutter project." #项目描述
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1 #版本号和构建号,打包时默认是从pubspec.yaml中version读取的。标准格式:version:A.B.C+X
environment:
sdk: '>=3.3.0 <4.0.0' #Dart sdk版本号,多人开发中建议写死
#以下是依赖的三方库
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.6 #自带的图标库,iOS风格
shared_preferences: ^2.2.2 #用于在设备上存储简单的持久化数据
dio: ^5.2.0 # HTTP 客户端库,适用于处理复杂网络请求
get: ^4.0.0 #状态管理库,比如导航、状态管理、依赖注入等
collection: ^1.18.0 #用于对数据进行集合操作和处理
json_annotation: ^4.8.1 #生成 JSON 序列化代码的库,配合 json_serializable 库一起,自动将json生成dart模型对象。
freezed_annotation: ^2.4.1 # 数据类生成库,用于简化不可变数据类的定义。它与 freezed 库一起使用,可以生成不可变对象、实现模式匹配,并自动生成 copyWith、toString、hashCode、== 操作符等方法。
fluttertoast: ^8.0.7 # 提示消息的插件库
dio_cookie_manager : ^3.1.1 #配合Dio网络请求库中管理HTTP cookie的Flutter插件
dio_http2_adapter: ^2.5.2 # Dio网络请求库中添加对HTTP/2协议的支持的Flutter插件。
logger: ^2.2.0 #日志记录库
# path_provider: ^2.1.3 # 用于获取设备上常见文件和目录的路径的插件库
intl: ^0.19.0 #国际化和本地化任务,处理字符
marquee: ^2.2.3 # 显示滚动文本的小部件,适配文字超出
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practi ces. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^3.0.0
build_runner: ^2.4.9
json_serializable: ^6.7.1
freezed: ^2.5.0
# 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 packages.
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
# 在你的应用里添加assets,需要按在这里添加路径,否则无法识别文件,例如添加image或json
assets:
- assets/
- assets/images/
- assets/images/login/
- assets/images/exam/
- assets/images/home/
- assets/images/home/newslist/
- assets/images/icon/
- assets/images/icon/tabbarIcon/
- assets/images/usercenter/
- assets/data/
- assets/data/call/
- assets/data/home/
- assets/data/exam/
- assets/data/appointment/
# 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
# 如果要在应用中添加字体,需要在这里进行配置
# 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
二、如何使用第三方插件
1. 可以去flutter插件库搜索你想要安装的插件
网址:Dart packages
2. 添加到pubspec的插件配置中dependencies:下面
dependencies:
cupertino_icons: ^1.0.6 #自带的图标库,iOS风格
3.切换到vscode中的终端窗口,输入安装命令进行安装
flutter packages get // 获取pubspec.yaml中所有的依赖关系
flutter packages upgrade //获取pubspec.yaml中所有列表中的依赖项的最新版
三、如何安装扩展
1、打开vscode,找到左侧菜单栏小方块图案,安装扩展插件, Flutter项目需要安装的插件列表如下:
- Build Runner
- Chinese(Simplified)(简体中文)
- Dart
- Dart build_runner
- Flutter
- Flutter Intl
- ESLint
补充说明
- ESLint 主要用于代码的格式化和代码质量检查。ESLint 可以通过配置规则实现代码自动格式化,同时发现和修复代码中的潜在问题。只需要cmd+s/ctrl+s保存代码,就会自动规范格式化代码。
参考文章
flutter 中的版本管理
网友评论