Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter searchDelegate未响应项目列表_Flutter_Flutter Layout_Flutter Dependencies_Flutter Test - Fatal编程技术网

Flutter searchDelegate未响应项目列表

Flutter searchDelegate未响应项目列表,flutter,flutter-layout,flutter-dependencies,flutter-test,Flutter,Flutter Layout,Flutter Dependencies,Flutter Test,我在Flatter中实现了searchDelegate。我不明白为什么searchDelegate不返回我从答案中选择的元素。 仅当我选择了建议的一个元素而不是结果的一个元素时,检查它才会返回我。 谢谢 这是我的密码。 这里我调用方法来显示SearchDelegate final result = await showSearch<String>( context: context, delegate: NameSearch(listN

我在Flatter中实现了searchDelegate。我不明白为什么searchDelegate不返回我从答案中选择的元素。 仅当我选择了建议的一个元素而不是结果的一个元素时,检查它才会返回我。 谢谢 这是我的密码。 这里我调用方法来显示SearchDelegate

final result = await showSearch<String>(
            context: context,
            delegate: NameSearch(listNamesProducts),
          );
          print(result);
import 'package:flutter/material.dart';

class NameSearch extends SearchDelegate<String> {
  final List<String> names;
  String result;

  NameSearch(this.names);

  @override
  List<Widget> buildActions(BuildContext context) {
    return [
      IconButton(
        icon: Icon(Icons.clear),
        onPressed: () {
          query = '';
        },
      )
    ];
  }

  @override
  Widget buildLeading(BuildContext context) {
    return IconButton(
      icon: Icon(Icons.arrow_back),
      onPressed: () {
        close(context, result);
      },
    );
  }

  @override
  Widget buildResults(BuildContext context) {
    final suggestions = names.where((name) {
      return name.toLowerCase().contains(query.toLowerCase());
    });

    return ListView.builder(
      itemCount: suggestions.length,
      itemBuilder: (BuildContext context, int index) {
        return ListTile(
          title: Text(
            suggestions.elementAt(index),
          ),
          onTap: () {
            result = suggestions.elementAt(index);
            close(context, result);
          },
        );
      },
    );
  }

  @override
  Widget buildSuggestions(BuildContext context) {
    final suggestions = names.where((name) {
      return name.toLowerCase().contains(query.toLowerCase());
    });

    return ListView.builder(
      itemCount: suggestions.length,
      itemBuilder: (BuildContext context, int index) {
        return ListTile(
          title: Text(
            suggestions.elementAt(index),
          ),
          onTap: () {
            query = suggestions.elementAt(index);
          },
        );
      },
    );
  }
}

```

I am new to flutter.
final result=wait showSearch(
上下文:上下文,
代表:名称搜索(listNamesProducts),
);
打印(结果);
这是搜索代理

final result = await showSearch<String>(
            context: context,
            delegate: NameSearch(listNamesProducts),
          );
          print(result);
import 'package:flutter/material.dart';

class NameSearch extends SearchDelegate<String> {
  final List<String> names;
  String result;

  NameSearch(this.names);

  @override
  List<Widget> buildActions(BuildContext context) {
    return [
      IconButton(
        icon: Icon(Icons.clear),
        onPressed: () {
          query = '';
        },
      )
    ];
  }

  @override
  Widget buildLeading(BuildContext context) {
    return IconButton(
      icon: Icon(Icons.arrow_back),
      onPressed: () {
        close(context, result);
      },
    );
  }

  @override
  Widget buildResults(BuildContext context) {
    final suggestions = names.where((name) {
      return name.toLowerCase().contains(query.toLowerCase());
    });

    return ListView.builder(
      itemCount: suggestions.length,
      itemBuilder: (BuildContext context, int index) {
        return ListTile(
          title: Text(
            suggestions.elementAt(index),
          ),
          onTap: () {
            result = suggestions.elementAt(index);
            close(context, result);
          },
        );
      },
    );
  }

  @override
  Widget buildSuggestions(BuildContext context) {
    final suggestions = names.where((name) {
      return name.toLowerCase().contains(query.toLowerCase());
    });

    return ListView.builder(
      itemCount: suggestions.length,
      itemBuilder: (BuildContext context, int index) {
        return ListTile(
          title: Text(
            suggestions.elementAt(index),
          ),
          onTap: () {
            query = suggestions.elementAt(index);
          },
        );
      },
    );
  }
}

```

I am new to flutter.
导入“包装:颤振/材料.省道”;
类名称搜索扩展了SearchDelegate{
最后名单名称;
字符串结果;
名称搜索(this.names);
@凌驾
列出buildActions(BuildContext上下文){
返回[
图标按钮(
图标:图标(图标。清除),
已按下:(){
查询=“”;
},
)
];
}
@凌驾
小部件buildLeading(BuildContext上下文){
返回图标按钮(
图标:图标(图标。箭头返回),
已按下:(){
关闭(上下文、结果);
},
);
}
@凌驾
小部件构建结果(构建上下文){
最终建议=名称。其中((名称){
返回name.toLowerCase().contains(query.toLowerCase());
});
返回ListView.builder(
itemCount:suggestions.length,
itemBuilder:(构建上下文,int索引){
返回列表块(
标题:正文(
建议。元素(索引),
),
onTap:(){
结果=建议。元素AT(索引);
关闭(上下文、结果);
},
);
},
);
}
@凌驾
小部件构建建议(构建上下文){
最终建议=名称。其中((名称){
返回name.toLowerCase().contains(query.toLowerCase());
});
返回ListView.builder(
itemCount:suggestions.length,
itemBuilder:(构建上下文,int索引){
返回列表块(
标题:正文(
建议。元素(索引),
),
onTap:(){
查询=建议.elementAt(索引);
},
);
},
);
}
}
```
我是个新手。