Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.6, on macOS 11.2.1 20D74 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.52.0)
[✓] Connected device (1 available)
• No issues found!
All done!
[✓] Flutter: is fully installed. (Channel stable, 1.22.6, on macOS 11.2.1 20D74 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices: is fully installed. (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS: is fully installed. (Xcode 12.4)
[✓] Android Studio: is fully installed. (version 4.1)
[✓] VS Code: is fully installed. (version 1.52.0)
[✓] Connected device: is fully installed. (1 available)
In order to run your application, type:
$ cd app
$ flutter run
Your application code is in app/lib/main.dart.
运行flutter项目
cd app
flutter run
会自动打开模拟器,并出现下面的提示信息
Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...
└─Compiling, linking and signing... 87.2s
Xcode build done. 114.1s
Waiting for iPhone 12 Pro Max to report its views... 4ms
Syncing files to device iPhone 12 Pro Max... 353ms
Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
An Observatory debugger and profiler on iPhone 12 Pro Max is available at: http://127.0.0.1:55603/9Dz6pZ8WEDY=/
通过vscode flutter插件创建项目
打开vscode,点击扩展,输入flutter,点击install安装flutter依赖
点击管理->命令面板,输入flutter,选择Flutter: New Application Project
Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
有状态的widget
页面路由(router)
通过Navigator.of来实现路由的具体实现
Navigator.of(context).push(
new MaterialPageRoute<void>(
builder: (BuildContext context) {
},
),
);
编写第一个flutter应用
你可以学到的:
启动项目的前提是对应的xcode Android Studio环境安装完全
初始化一个flutter项目
通过flutter 命令创建
安装正确会出现下面这样的提示👇:
如果安装错误,按照环境搭建中的安装flutter
创建项目名为app的flutter项目
初始化创建成功会出现下面提示
会自动打开模拟器,并出现下面的提示信息
通过vscode flutter插件创建项目
使用外部package
pubspec.yaml
文件中管理依赖,比如新增包english_words
查找更多flutter相关依赖
热重载
在通过
flutter run
运行的命令下,输入r
即可完成热重载几个常见的命令:
有状态的widget
页面路由(router)
通过Navigator.of来实现路由的具体实现
页面交互
通过
onTap
来实现页面交互,使用setState改变对应状态主题
通过
new ThemeData()
来实现主题的切换