首页 > 解决方案 > 循环进度不断旋转

问题描述

我试图实现 CircularProgressBar 以实现颤振,但不知何故,它一直在旋转,加载数据后不会关闭。

从 NetworkFile 调用数据

 final getCategory = NetworkFile().getCategories(elem);
  bool isLoading = true;
  List posts = [];

  void getPostsList() async {
    var res = await getCategory;

    if (this.mounted) {
      setState(() {
        posts = res;

      });
    }
  }

退回容器

return isLoading ? CircularProgressIndicator() : Container(
      child: ListView.builder(
        itemCount: posts == null ? 0 : posts.length,
        itemBuilder: (BuildContext context, int index) {
          return Column(), }
         ), 
     );

标签: flutter

解决方案


  setState(() {
        posts = res;
        isLoading = false;
      });

改为使用FutureBuilder


推荐阅读