Chapter 1: Getting Started with Flutter
大綱
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 Dart 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 Fuchsia 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 API 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
dependenciesandcupertino_icons: ^0.1.2add the below:
make an HTTP network call and also parse the resulting response JSON into Dart objects
Using a ListView
Add a
_buildRow()method toGHFlutterState
Update the build method of
GHFlutterStateto 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
_memberslist as a Dart Map type, the equivalent of a Map in Kotlin or a Dictionary in Swift.Add a new
Membertype to the Member.dart file:
Update the
_membersdeclaration inGHFlutterStateso that it is a list ofMemberobjects
Now update the callback sent to
setState()in_loadData()to turn the decoded map into aMemberobject and add it to the list of members
Downloading Images with NetworkImage
Update the
Memberclass to add anavatarUrlproperty 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
Memberclass into member.dart and both theGHFlutterStateandGHFlutterclasses into ghflutter.dart.
Adding a Theme
Last updated