ShannonChenCHN / FlutterPlayground

5 stars 3 forks source link

Keynote #3

Open ShannonChenCHN opened 4 years ago

ShannonChenCHN commented 4 years ago

初识 Flutter

带一点自己的思考;聊一两个深入的点

ShannonChenCHN commented 4 years ago

Technical overview/Core principles

image

ShannonChenCHN commented 4 years ago

Introduction to widgets

Overview

Basic widgets

Lifecycle events

Why StatefulWidget and State are separate objects?

In Flutter, these two types of objects have different life cycles. Widgets are temporary objects, used to construct a presentation of the application in its current state. State objects, on the other hand, are persistent between calls to build(), allowing them to remember information.

In Flutter, change notifications flow “up” the widget hierarchy by way of callbacks, while current state flows “down” to the stateless widgets that do presentation. The common parent that redirects this flow is the State.

Handling gestures

Many widgets use a GestureDetector to provide optional callbacks for other widgets.

Key, GlobalKey

A Key is an identifier for Widgets, Elements and SemanticsNodes.

A new widget will only be used to update an existing element if its key is the same as the key of the current widget associated with the element.

A `GlobalKey is a key that is unique across the entire app.

参考

ShannonChenCHN commented 4 years ago

Layout

Key points

Tip: To minimize the visual confusion that can result from heavily nested layout code, implement pieces of the UI in variables and functions.

image

Lay out a widget

Lay out multiple widgets vertically and horizontally

Common layout widgets

Any app can use the widgets library but only Material apps can use the Material Components library.

Constraints

Creating responsive apps

参考

ShannonChenCHN commented 4 years ago

DevTools

Overview

Flutter inspector

Timeline view

Memory view

Performance view

Network view

Debugger

Logging view

参考

ShannonChenCHN commented 4 years ago

State management

Flutter is declarative. This means that Flutter builds its user interface to reflect the current state of your app: image

Benefit: Remarkably, there is only one code path for any state of the UI. You describe what the UI should look like for any given state, once—and that is it.(所见即所得)

Key points

Differentiate between ephemeral state and app state

When asked about React’s setState versus Redux’s store, the author of Redux, Dan Abramov, replied:

“The rule of thumb is: Do whatever is less awkward.”

image

List of state management approaches

参考