Listview无法使用TextField动态更新

时间:2019-11-02 12:03:03

标签: flutter mobile dart

当前,我正在尝试使用TextField更新ListView,但是遇到了问题。初始化后,ListView最初可以正确更新,但是当我键入内容时,它变为空白。

这是我的代码:

Nov 02 11:19:10 server systemd[1]: Starting Docker Application Container Engine...
Nov 02 11:19:10 server dockerd[1059]: time="2019-11-02T11:19:10.878296526Z" level=info msg="Starting up"
Nov 02 11:19:10 server dockerd[1059]: time="2019-11-02T11:19:10.930469940Z" level=info msg="parsed scheme: \"unix\"" module=grpc
Nov 02 11:19:10 server dockerd[1059]: time="2019-11-02T11:19:10.930539797Z" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
Nov 02 11:19:10 server dockerd[1059]: time="2019-11-02T11:19:10.930596542Z" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0  <nil>}] <nil>}" module=grpc
Nov 02 11:19:10 server dockerd[1059]: time="2019-11-02T11:19:10.930621923Z" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Nov 02 11:19:10 server dockerd[1059]: time="2019-11-02T11:19:10.981128356Z" level=info msg="parsed scheme: \"unix\"" module=grpc
Nov 02 11:19:10 server dockerd[1059]: time="2019-11-02T11:19:10.981167718Z" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
Nov 02 11:19:10 server dockerd[1059]: time="2019-11-02T11:19:10.981190341Z" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0  <nil>}] <nil>}" module=grpc
Nov 02 11:19:10 server dockerd[1059]: time="2019-11-02T11:19:10.981202686Z" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Nov 02 11:19:11 server dockerd[1059]: time="2019-11-02T11:19:11.074191900Z" level=info msg="[graphdriver] using prior storage driver: overlay2"
Nov 02 11:19:11 server dockerd[1059]: time="2019-11-02T11:19:11.157844953Z" level=info msg="Loading containers: start."
Nov 02 11:19:12 server dockerd[1059]: time="2019-11-02T11:19:12.159329593Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred
Nov 02 11:19:12 server dockerd[1059]: time="2019-11-02T11:19:12.297096462Z" level=info msg="Loading containers: done."
Nov 02 11:19:12 server dockerd[1059]: time="2019-11-02T11:19:12.646584626Z" level=info msg="Docker daemon" commit=9013bf583a graphdriver(s)=overlay2 version=19.03.4
Nov 02 11:19:12 server dockerd[1059]: time="2019-11-02T11:19:12.646760510Z" level=info msg="Daemon has completed initialization"
Nov 02 11:19:12 server dockerd[1059]: time="2019-11-02T11:19:12.848425893Z" level=info msg="API listen on /var/run/docker.sock"
Nov 02 11:19:12 server configure-snat[1517]: mount: /dev/sr0 is write-protected, mounting read-only
Nov 02 11:19:13 server configure-snat[1517]: + iptables -t nat -D POSTROUTING -s 172.17.0.1/16 '!' -o docker0 -j SNAT --to
Nov 02 11:19:13 server configure-snat[1517]: iptables v1.4.21: option "--to" requires an argument
Nov 02 11:19:13 server configure-snat[1517]: Try `iptables -h' or 'iptables --help' for more information.
Nov 02 11:19:13 server configure-snat[1517]: + iptables -t nat -I POSTROUTING -s 172.17.0.1/16 '!' -o docker0 -j SNAT --to
Nov 02 11:19:13 server configure-snat[1517]: iptables v1.4.21: option "--to" requires an argument
Nov 02 11:19:13 server configure-snat[1517]: Try `iptables -h' or 'iptables --help' for more information.
Nov 02 11:19:13 server systemd[1]: docker.service: control process exited, code=exited status=2
Nov 02 11:19:13 server dockerd[1059]: time="2019-11-02T11:19:13.296514020Z" level=info msg="Processing signal 'terminated'"
Nov 02 11:19:13 server dockerd[1059]: time="2019-11-02T11:19:13.297279527Z" level=info msg="Daemon shutdown complete"
Nov 02 11:19:13 server systemd[1]: Failed to start Docker Application Container Engine.
Nov 02 11:19:13 server systemd[1]: Unit docker.service entered failed state.
Nov 02 11:19:13 server systemd[1]: docker.service failed.
Nov 02 11:19:15 server systemd[1]: docker.service holdoff time over, scheduling restart.
Nov 02 11:19:15 server systemd[1]: Stopped Docker Application Container Engine.

需要很多帮助!我是一个自学的Flutter爱好者,所以我可能不了解很多东西。请忍受我!

1 个答案:

答案 0 :(得分:2)

以某种方式(我不明白为什么)在方法filteredSearch中清除了widget.selectedList中的列表。

我对您的代码进行了一些更改,它可以正常工作:

List items = List<String>();

  void filteredSearch(String query) {
    items = widget.selectedList.where((txt) => query.isEmpty || txt.contains(query)).toList();
    setState(() {
    });
  }

  @override
  void initState() {
    items = widget.selectedList;
    super.initState();
  }