Skip to content

Commit

Permalink
[内容修订] src/cookbook/networking/fetch-data (#1396)
Browse files Browse the repository at this point in the history
Co-authored-by: Luke Cheng <[email protected]>
  • Loading branch information
mobeicanyue and chenglu authored Dec 14, 2023
1 parent a13c5b9 commit 4f8bb63
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/cookbook/networking/fetch-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,17 @@ and this happens surprisingly often.
The `fetchAlbum()` method, if placed inside `build()`, is repeatedly
called on each rebuild causing the app to slow down.

每当 Flutter 需要更改视图中的任何内容时(并且这种更改出现的频率非常高),
就会调用 `build()` 方法。因此,如果你将 `fetchAlbum()` 方法放在 `build()` 内,
该方法会在每次重建应用时重复调用,同时还会拖慢应用程序的速度。

Storing the `fetchAlbum()` result in a state variable ensures that
the `Future` is executed only once and then cached for subsequent
rebuilds.

每当 Flutter 需要改变视图中的一些内容时(这个发生的频率非常高)
就会调用 `build()` 方法。因此,如果你将数据请求置于 `build()` 内部
就会造成大量的无效调用,同时还会拖慢应用程序的速度
`fetchAlbum()` 的结果存储在状态变量中
可确保 `Future` 只执行一次
然后缓存(得到的数据)以备后续重新构建应用

## Testing

Expand Down

0 comments on commit 4f8bb63

Please sign in to comment.