【问题标题】:How can i check if the UI is refreshing?如何检查 UI 是否正在刷新?
【发布时间】:2020-03-08 10:39:27
【问题描述】:

当我使用小部件显示未来构建者的项目列表时遇到问题,我有一个过滤器对象,当我在过滤器屏幕中更改某些内容时,会自动获取列表屏幕中的更改,但总是向我显示相同的数据,但项目列表具有 UI 显示的不同项目。

这是我的容器:

body: Container(
        color: Colors.white,
        child: FutureBuilder<ResponseHome>(
          future: Connection(context: context).filterPlaces(filter: _filter),
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return _formatCategories(context, snapshot.data.news, snapshot.data.places);
            } else if (snapshot.hasError) {
              var message = Utils.parseError(context, snapshot.error);
              return Center(
                child: Text("$message"),
              );
            }
            return Center(
              child: CircularProgressIndicator(),
            );
          },
        ),
      )

这是我用来制作小部件的功能:

Widget _formatCategories(BuildContext context, List<Publication> publications, ResponsePlaces response) {
    List<Category> categories = <Category>[];

    if (response.hotels.isNotEmpty) {
      categories.add(Category(title: "Hoteles", places: response.hotels));
    }

    if (response.restaurants.isNotEmpty) {
      categories.add(Category(title: "Restaurantes", places: response.restaurants));
    }

    if (response.touristic.isNotEmpty) {
      categories.add(Category(title: "Actividades", places: response.touristic));
    }

    for (var category in categories) {
      print("Category ${category.title}  ${category.places.length}");
    }

    return _containerLists(context, publications, categories);
  }


  Widget _containerLists(BuildContext context, List<Publication> publications, List<Category> categories) {

    List<Widget> items = <Widget>[];

    items.clear();

    items.add(
        Routes.newsSlider(publications)
    );

    for (var index in categories) {
      items.add(
          Routes.placeList(index)
      );
    }

    return SingleChildScrollView(
      scrollDirection: Axis.vertical,
      child: Container(
        child: Column(
          children: items,
        ),
      ),
    );
  }

如果你看到我选择了另一种类型的地方,但总是向我展示酒店,这就是证据。

这就是我得到一个包含不同数据的列表的证据。

https://i.stack.imgur.com/lIwoN.png

【问题讨论】:

  • 您忘记添加其中一个网址
  • @PhaniRithvij 哪个网址?

标签: android ios flutter mobile flutter-layout


【解决方案1】:

如果您的items 列表大小相同,则可能会发生这种情况。如果这是真的,那么您的元素树无法识别列中的小部件已更改,您必须为它们使用 UniqueKey。您可以阅读更多关于它的信息here,尝试应用它并提供反馈

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 1970-01-01
    • 2018-10-27
    • 2013-06-17
    相关资源
    最近更新 更多