首页 > 解决方案 > 如何使用 FutureBuilder 使用 List 数据构建 ListTile

问题描述

列表>_userAccounts;

结果:

_CurrentUserAccounts: [
    [Current Account, 10.06, United States Dollar USD], 
    [Demand Deposit, 55.22, British Pound GBP], 
    [Current Account, 250, Euro EUR], 
    [Deposit Account, 0, Euro EUR]
]

格式: [AccountName, CurrentBalance, CurrencyName],

我需要使用此信息 (List>) 来构建 ListTile。这仅适用于一位用户。一些用户可能有 1 个帐户,其中一些可能有超过 10 个帐户。

显示这些数据的最佳做法是什么?我打算使用 ListTile,所以,如果用户选择 ListTile,他们可以获取特定帐户的详细信息。

那么,如何使用 FutureBuilder 使用 List 数据构建 ListTile?

标签: listbuilddartflutter

解决方案


您必须为 home 或 root 小部件提供FutureBuilder的实例。正如你在下面看到的。

body: new FutureBuilder<List<Country>>(
        future: fetchCountry(new http.Client()),
        builder: (context, snapshot) {
          if (snapshot.hasError) print(snapshot.error);

          return snapshot.hasData
              ? new CountyList(country: snapshot.data)
              : new Center(child: new CircularProgressIndicator());
        },

我在这里找到了一个简单的例子。


推荐阅读