[Flutter] 第一个flutter程序

Flutter是什么?

Flutter 官方网站 的描述如下:
Flutter is a new project to help developers build high-performance, high-fidelity, mobile apps for iOS and Android from a single codebase.
Flutter是一个新的项目,旨在帮助开发者构建高效、高保真的移动应用。 它是一个跨平台的解决方案,开发人员写一份代码,可以分别针对ios和android编译app。
目前该项目还处于早期开发阶段,有很多不完善的地方。

安装SDK

目前Flutter只支持ios和linux,我使用的ubuntu。按照官网的方法通过git安装。

$ git clone https://github.com/flutter/flutter.git


之后设置环境变量,可以在命令行上输入下面的语句,最好在配置文件中添加下面的shell脚本,这样就不必每次都输入。

$ export PATH=path_to_flutter/bin:$PATH


以上完成后使用下面的命令检查Flutter开发环境。

$ flutter doctor

这个命令检查需要的依赖,如果需要,会自动下载并编译依赖。


创建项目

使用flutter create命令就可以创建一个项目,下面例子创建一个名为firstapp的项目。


xxx@xxx-ubuntu:~/flib$ flutter create firstapp

Creating project firstapp...

Wrote 51 files.


Running 'pub get' in firstapp...                     7.1s


[✓] Flutter is fully installed. (on Linux, channel master)

[✓] Android toolchain - develop for Android devices is fully installed. (Android SDK 23.0.2)

[✓] Atom - a lightweight development environment for Flutter is fully installed.

[✓] Connected devices is fully installed.


All done! In order to run your application, type:


  $ cd firstapp

  $ flutter run


Your main program file is lib/main.dart in the firstapp directory.

xxx@xxx-ubuntu:


然后我们查看这个项目的文件目录,如下:

xxx@xxx-ubuntu:~/flib/firstapp$ ls -lR

.:

total 28

drwxrwxr-x 3 joe joe 4096 10月 19 17:58 android

-rw-rw-r-- 1 joe joe   42 10月 19 17:58 flutter.yaml

drwxrwxr-x 7 joe joe 4096 10月 19 17:58 ios

drwxrwxr-x 2 joe joe 4096 10月 19 17:58 lib

-rw-rw-r-- 1 joe joe 2314 10月 19 17:58 pubspec.lock

-rw-rw-r-- 1 joe joe   93 10月 19 17:58 pubspec.yaml

-rw-rw-r-- 1 joe joe  148 10月 19 17:58 README.md

编译和执行

可以使用下面的命令直接编译运行app:

  $ cd firstapp

  $ flutter run

也可以使用 flutter build命令编译app:

$ flutter help build
Flutter build commands.

Usage: flutter build  [arguments]
-h, --help    Print this usage information.

Available subcommands:
  aot     Build an ahead-of-time compiled snapshot of your app's Dart code.
  apk     Build an Android APK file from your app.
  clean   Delete the build/ directory.
  flx     Build a Flutter FLX file from your app.
  ios     Build an iOS application bundle (Mac OS X host only).

Run "flutter help" to see global options.

这是真机上运行app的截图

[Flutter] 第一个flutter程序_第1张图片


------ 结束 ------





你可能感兴趣的:(Flutter)