Chapter 1: Getting Started with Flutter

Getting Started with Flutterarrow-up-right

大綱

  • Introduction to Flutter

  • Getting Started

  • Setting up your development environment

  • Creating a new project

  • Hot Reload

  • Importing a File

  • Widgets

  • Making Network Calls

  • Using a ListView

  • Adding dividers

  • Parsing to Custom Types

  • Downloading Images with NetworkImage

  • Cleaning the Code

  • Adding a Theme

Introduction to Flutter

  • Flutter apps are written using the Dartarrow-up-right programming language, also originally from Google and now an ECMA standard

  • Flutter allows for a reactive and declarative style of programming

  • Dart achieves improve app startup times and overall performance by using Ahead-Of-Time or AOT compilation.

  • use Just-In-Time or JIT compilation. JIT compilation with Flutter improves the development workflow by allowing a hot reload capability.

  • Flutter will also give you a head start on developing for the Fuchsiaarrow-up-right platform, which is currently an experimental operating system in development at Google.

Getting Started

  • In this tutorial, you’ll build a Flutter app that queries the GitHub APIarrow-up-right for team members in a GitHub organization and displays the team member information in a scrollable list.

Setting up your development environment

Creating a new project

  • 預設的範例專案 - 是一個計數app。

  • 先把這些範例專案,做基本調整,只需要在頁面中間秀一段文字。

Hot Reload

One of the best aspects of Flutter development is being able to hot reload your app as you make changes. This is similar to something like Android Studio’s Instant Run/Apply Changes.

Widgets

There are two fundamental types of widgets you will use:

  • Stateless: widgets that depend only upon their own configuration info, such as a static image in an image view.

  • Stateful: widgets that need to maintain dynamic information and do so by interacting with a State object.

將GHFlutterApp改寫成Stateful widget

Making Network Calls

  • Navigate to the pubspec.yaml file and right under dependencies and cupertino_icons: ^0.1.2 add the below:

  • make an HTTP network call and also parse the resulting response JSON into Dart objects

Using a ListView

  • Add a _buildRow() method to GHFlutterState

  • Update the build method of GHFlutterState to have it’s body be a ListView.builder

Adding dividers

  • 加入分隔線的做法,不像iOS的tableView是自動有分隔線,這裡要自己手動產生。

To add dividers into the list, you’re going to double the item count, and then return a Divider widget when the position in the list is odd

Parsing to Custom Types

  • the _members list as a Dart Map type, the equivalent of a Map in Kotlin or a Dictionary in Swift.

  • Add a new Member type to the Member.dart file:

  • Update the _members declaration in GHFlutterState so that it is a list of Member objects

  • Now update the callback sent to setState() in _loadData() to turn the decoded map into a Member object and add it to the list of members

Downloading Images with NetworkImage

  • Update the Member class to add an avatarUrl property that cannot be null:

  • Update _buildRow() to show the avatar using a NetworkImage and the CircleAvatar widget:

Cleaning the Code

  • Create files named member.dart and ghflutter.dart in the lib folder.

  • Move the Member class into member.dart and both the GHFlutterState and GHFlutter classes into ghflutter.dart.

Adding a Theme

Last updated