0%

Flutter Hello World

Flutter是什么

Flutter is Google’s SDK for crafting beautiful, fast user experiences for mobile, web and desktop from a single codebase.
Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.
Flutter是基于Dart语言的.

Dart Hello World

Dart是什么
A client-optimized language for fast apps on any platform.
打开在线DartPad,简单hello world如下

1
2
3
void main() {
print('Hello World');
}

Flutter Hello World

打开Android Studio,安装Dart和Flutter插件;选择Flutter Examples目录下的Hello World.

项目结构如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
├── hello_world
│ ├── android
│ │ └── ...
│ ├── fuchsia
│ │ └── meta
│ │ ├── hello_world.cmx
│ ├── ios
│ │ ├── ...
│ ├── lib
│ │ └── arabic.dart
│ │ └── main.dart
│ ├── test
│ │ ├── hell_test.dart
│ ├── web
│ │ ├── index.html
├── pubspec.lock
└── pubspec.yaml
├── README.md

正如Flutter的定义一样,Flutter代码能生成移动端android ios fuchsia发布包, 并且能运行在web端.

代码启动入口main.dart

1
2
3
4
5
6
7
// Copyright 2015 The Chromium Authors. All rights reserved.  
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';

void main() => runApp(const Center(child: Text('Hello, world!', textDirection: TextDirection.ltr)));