如何在浮动的可重新排序列表视图中实现拉动刷新

问题描述 投票:0回答:1

我尝试了一些方法,但没有得到确切的结果。

在列表功能中的某些记录停止工作后,如何在可重排的列表视图中实现拉动刷新以刷新。而且,可重新排序的列表在没有列表项的列表末尾占用更多空间。

产生拉动刷新的代码

Widget todoList() {
    return StreamBuilder<dynamic>(
        stream: toDoBloc.getTodos,
        builder: (BuildContext context, AsyncSnapshot<dynamic> snap) {
          if (!snap.hasData) {
            return Center(
              child: SizedBox(
                height: 30.0,
                width: 30.0,
                child: CircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
                ),
              ),
            );
          } else {
            _refreshController.refreshCompleted();
            return SmartRefresher(
              enablePullDown: true,
              controller: _refreshController,
              onRefresh: () async {
                await Future<dynamic>.delayed(
                  const Duration(milliseconds: 1000),
                );
                toDoBloc.toDoList(
                  prefsObject.getString('circleId'),
                );
              },
              header: ClassicHeader(
                key: centerKey,
                completeIcon: null,
              ),
              child: listView(snap.data),
            );
          }
        });
  }

使列表可重新排序的代码

Widget listview(list) {
    final List child = map<Widget>(list, (index, i) {
      return _singleToDoWidget(list[index], index);
    });
    void _onReorder(int oldIndex, int newIndex) {
      setState(() {
        if (newIndex > oldIndex) {
          newIndex -= 1;
        }
        final List oldIndexIds = map<String>(list, (index, i) {
          return list[index].id;
        });
        final dynamic selectedListItem = list[oldIndex];
        list.removeAt(oldIndex);
        list.insert(newIndex, selectedListItem);
        final List newIndexIds = map<String>(list, (index, i) {
          return list[index].id;
        });
        toDoBloc.toDoOrderList(oldIndexIds, newIndexIds);
      });
    }

    return ReorderableListView(
        header: null, onReorder: _onReorder, children: child);
  }
flutter dart flutter-layout
1个回答
1
投票

我实现拉动以使用RefreshIndicator class在可重新排序的列表视图中刷新

Future<dynamic> refreshList() async {
    await Future.delayed(const Duration(seconds: 1));
    return null; //do some here.
  }

Widget todoList() {
    return StreamBuilder<dynamic>(
        stream: toDoBloc.getTodos,
        builder: (BuildContext context, AsyncSnapshot<dynamic> snap) {
          if (!snap.hasData) {
            return Center(
              child: SizedBox(
                height: 30.0,
                width: 30.0,
                child: CircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
                ),
              ),
            );
          } else {
            _refreshController.refreshCompleted();
            return RefreshIndicator(
            key: refreshKey,
            color: pinkColor,
            onRefresh: () async {
              await refreshList();
            },
            child: _listView(snap.data),
          );
          }
        });
  }
© www.soinside.com 2019 - 2024. All rights reserved.