Flutter开发 初识目录结构
初识目录结构
.dart_tool:记录dart工具库所在位置及信息的json文件和一些dart编译文件。
.idea:存放IDE生成的一些临时文件
android:存放flutter与android原生交互的一些代码
build:存放运行时生成的编译文件
ios:存放flutter与ios原生交互的一些代码
lib:存放的dart语言编写的代码
test:存放项目测试代码文件
pubspec.yaml:用于管理第三方依赖库及资源的配置文件
主要文件介绍
main.dart 入口文件
import 'package:flutter/material.dart'; //导入包void main() {//入口函数runApp(const MyApp());
}class MyApp extends StatelessWidget { //无状态的const MyApp({super.key});// This widget is the root of your application. Widget build(BuildContext context) {return MaterialApp(title: 'Flutter Demo', //任务管理窗口中显示的应用程序标题theme: ThemeData(//主题colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),),home: const MyHomePage(title: 'Flutter Demo Home Page222'), //应用程序默认显示的控件);}
}
pubspec.yaml
name: first_flutter
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.devversion: 1.0.0+1 #应用程序版本号environment:sdk: ^3.8.1 #适配的版本号
#依赖管理,第三方插件
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: ^1.0.8 #ios样式的图标库#dependency_overrides:
# path_provider:
# hosted:
# url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"#开发时需要的依赖包,不会包含在发布的包中
dev_dependencies:flutter_test:sdk: flutter# The "flutter_lints" package below contains a set of recommended lints to# encourage good coding practices. 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: ^5.0.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:uses-material-design: true #是否使用material design# To add assets to your application, add an assets section, like this:
#项目使用的资源文件(图片、字体、JSON等)
# 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## For details regarding fonts from package dependencies,# see https://flutter.dev/to/font-from-package